]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Hibernate config changed to generate db in release mode also. User creation is fixed...
authorrkv <rkv@opencascade.com>
Fri, 30 Nov 2012 13:22:42 +0000 (13:22 +0000)
committerrkv <rkv@opencascade.com>
Fri, 30 Nov 2012 13:22:42 +0000 (13:22 +0000)
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java
Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java
Workspace/Siman-Common/testng_study.xml [new file with mode: 0644]
Workspace/Siman/conf/release.properties

index ffa5d73850b512423198492e3cf94c439b005db3..3273b27fc7994c52683d6fa81b51252cde066bd7 100644 (file)
@@ -19,7 +19,7 @@
                <!--     <natural-id>-->
                <property name="username" column="username" access="field" />
                <many-to-one name="role" column="username" insert="false"
-                       update="false" unique="true" cascade="save-update" access="field" />
+                       update="false" unique="true" cascade="merge,save-update" access="field" />
                <property name="email" column="email" access="field" />
                <!--     </natural-id>-->
                
index 70714a69bd74607bf2a3065f7f3761a877e35f2c..0303a5f4efa5ee2399c161f2374290d5d49c73f6 100644 (file)
@@ -19,8 +19,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
 import org.splat.common.properties.MessageKeyEnum;
 import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.kernel.Role;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
@@ -35,6 +38,7 @@ import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.UsedByRelation;
 import org.splat.dal.bo.som.UsesRelation;
+import org.splat.dal.dao.kernel.RoleDAO;
 import org.splat.dal.dao.kernel.UserDAO;
 import org.splat.dal.dao.som.KnowledgeElementDAO;
 import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
@@ -117,6 +121,11 @@ public class ScenarioServiceImpl implements ScenarioService {
         */
        private UserDAO _userDAO;
 
+       /**
+        * Injected role DAO.
+        */
+       private RoleDAO _roleDAO;
+
        /**
         * Injected knowledge element type DAO.
         */
@@ -784,7 +793,13 @@ public class ScenarioServiceImpl implements ScenarioService {
                KnowledgeElementType ucase = getKnowledgeElementTypeService()
                                .selectType("usecase");
                KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
-               User admin = getUserService().selectUser(1); // First user created when creating the database
+               // TODO: Get appropriate user by its role: UserService.getAdmin();
+               // User admin = getUserService().selectUser(1); // First user created when creating the database
+               Role adminRole = getRoleDAO().getFilteredList(
+                               Restrictions.like("role", "%sysadmin%")).get(0);
+               User admin = getUserDAO().getFilteredList(
+                               Restrictions.eq("role", adminRole), Order.asc("rid")).get(0); // First sysadmin in the database
+               
                kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
                                scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
                // knowledges
@@ -1059,4 +1074,23 @@ public class ScenarioServiceImpl implements ScenarioService {
                _documentTypeService = documentTypeService;
        }
 
+       /**
+        * Get the roleDAO.
+        * 
+        * @return the roleDAO
+        */
+       public RoleDAO getRoleDAO() {
+               return _roleDAO;
+       }
+
+       /**
+        * Set the roleDAO.
+        * 
+        * @param roleDAO
+        *            the roleDAO to set
+        */
+       public void setRoleDAO(final RoleDAO roleDAO) {
+               _roleDAO = roleDAO;
+       }
+
 }
index 94ba43aeb1a30d0e4bbd326620b3b098de30a4c4..9541c3db20f04963710670cd09b05e6abaf7ec39 100644 (file)
@@ -72,7 +72,7 @@ public class UserServiceImpl implements UserService {
                // and to avoid the exception:
                // org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the
                // session: [org.splat.dal.bo.kernel.Role#simer]
-               getUserDAO().merge(nuser);
+               nuser = getUserDAO().merge(nuser);
                getUserDAO().saveOrUpdate(nuser);
                
                //getUserDAO().create(nuser);
index adc8a361f74f9e2369270ff6291bcd26354c9cd9..08feeae8374fa27a8a524ce55efe817358a6e02f 100644 (file)
@@ -336,7 +336,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
        }
 
        /**
-        * Check if a file of the given format should be imported during check-in of a document of the given type.
+        * Check if a file of the given format should be imported during check-out of a document of the given type.
         * 
         * @param type
         *            document type
@@ -345,6 +345,15 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @return true if file should be imported
         */
        public boolean doImport(final String type, final String format) {
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("Do import for ("
+                                       + type
+                                       + ", "
+                                       + format
+                                       + "): "
+                                       + (_mapimport.containsKey(type) && _mapimport.get(type)
+                                                       .contains(format)));
+               }
                return (_mapimport.containsKey(type) && _mapimport.get(type).contains(
                                format));
        }
index 13293474b28c32c51103cc784cb133fd3d511370..9ac10075bdf69755bd5eedda59a212c540fe6b04 100644 (file)
@@ -87,7 +87,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="knowledgeElementTypeService"
                        ref="knowledgeElementTypeService" />
                <property name="userService" ref="userService" />
-               <property name="userDAO" ref="userDAO" />
+        <property name="userDAO" ref="userDAO" />
+        <property name="roleDAO" ref="roleDAO" />
                <property name="knowledgeElementTypeDAO"
                        ref="knowledgeElementTypeDAO" />
                <property name="simulationContextService"
index d0807aec0d71d92d288c3b94f5ff7f24df82dd4a..c1fc9a59d4151e19584dd8195e85d5b813e0c97e 100644 (file)
@@ -13,10 +13,14 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.List;
 
+import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.dao.som.Database;
 import org.splat.log.AppLogger;
 import org.splat.service.DocumentTypeService;
+import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.SimulationContextService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.technical.ProjectSettingsService.Step;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -55,6 +59,20 @@ public class TestProjectSettingsService extends BaseTest {
        @Qualifier("documentTypeService")
        private transient DocumentTypeService _documentTypeService;
 
+       /**
+        * The KnowledgeElementTypeService. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("knowledgeElementTypeService")
+       private transient KnowledgeElementTypeService _knowledgeElementTypeService;
+
+       /**
+        * The DocumentTypeService. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("simulationContextService")
+       private transient SimulationContextService _simulationContextService;
+       
        /**
         * Test of loading document mappings to file formats from customization XML file.<BR>
         * <B>Description :</B> <BR>
@@ -454,6 +472,7 @@ public class TestProjectSettingsService extends BaseTest {
                startNestedTransaction();
                // ///////////////////////////////////////////////////
                // ////// Load good workflow customization
+               getHibernateTemplate().clear();
                _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                try {
                        _projectSettings.configure(ClassLoader.getSystemResource(
@@ -464,6 +483,10 @@ public class TestProjectSettingsService extends BaseTest {
 
                List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
                Assert.assertTrue(steps.size() > 0, "No steps are created.");
+               KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
+               Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+               SimulationContextType prodtype = _simulationContextService.selectType("product");
+               Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
 
                // /////////////////////////////////////////////////////////
                // ////// Test reconfiguration attempt
@@ -477,6 +500,10 @@ public class TestProjectSettingsService extends BaseTest {
                }
                steps = _projectSettings.getStepsOf(Scenario.class);
                Assert.assertTrue(steps.size() > 0, "No steps are created.");
+               ucase = _knowledgeElementTypeService.selectType("usecase");
+               Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+               prodtype = _simulationContextService.selectType("product");
+               Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
 
                try {
                        /*
@@ -500,4 +527,71 @@ public class TestProjectSettingsService extends BaseTest {
                rollbackNestedTransaction();
                LOG.debug(">>>>> END testConfigure()");
        }
+
+       /**
+        * Test of repeated database configuration method (dynamic reconfiguration).<BR>
+        * The problem - duplication of the simer user admin role. <B>Description :</B> <BR>
+        * <i>Load customization twice and check the result.</i><BR>
+        * <B>Action : </B><BR>
+        * <i>1. call the method twice for som.xml</i><BR>
+        * <B>Test data : </B><BR>
+        * <i>test/som.xml</i><BR>
+        * 
+        * <B>Outcome results:</B><BR>
+        * <i>
+        * <ul>
+        * <li>step must be configured<BR>
+        * </li>
+        * </ul>
+        * </i>
+        * 
+        * @throws IOException
+        *             if configuration loading is failed
+        * @throws SQLException
+        *             if configuration loading is failed
+        */
+       @Test
+       public void testDatabaseInitialize() throws IOException, SQLException {
+               LOG.debug(">>>>> BEGIN testDatabaseInitialize()");
+               startNestedTransaction();
+               // ///////////////////////////////////////////////////
+               // ////// Load good workflow customization
+               getHibernateTemplate().bulkUpdate("delete from Role");
+               getHibernateTemplate().flush();
+               Database.getInstance().reset();
+               _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+               try {
+                       _projectSettings.configure(ClassLoader.getSystemResource(
+                                       "test/som.xml").getPath());
+               } catch (FileNotFoundException e) {
+                       Assert.fail("Can't find configuration file: ", e);
+               }
+               try {
+                       /*
+                        * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different
+                        * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested
+                        * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated
+                        * with the session: [org.splat.dal.bo.kernel.Role#simer] at
+                        * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at
+                        * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at
+                        * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at
+                        * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at
+                        * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
+                        */
+                       Database.getInstance().initialize();
+                       getHibernateTemplate().flush();
+               } catch (DuplicateKeyException dke) {
+                       Assert.fail(
+                                       "User creation failed during the database reconfiguration: "
+                                                       + dke.getMessage(), dke);
+               }
+
+               KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
+               Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+               SimulationContextType prodtype = _simulationContextService.selectType("product");
+               Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
+               
+               rollbackNestedTransaction();
+               LOG.debug(">>>>> END testDatabaseInitialize()");
+       }
 }
index d064e2fd3c00cb497ff4bdd0622cb685f7817ada..b858a2905160e0176cc51f163e902b97110015d3 100644 (file)
@@ -24,8 +24,11 @@ import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.UsedByRelation;
 import org.splat.dal.bo.som.UsesRelation;
@@ -39,8 +42,10 @@ import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.NotApplicableException;
 import org.splat.log.AppLogger;
 import org.splat.service.DocumentTypeService;
+import org.splat.service.KnowledgeElementTypeService;
 import org.splat.service.PublicationService;
 import org.splat.service.ScenarioService;
+import org.splat.service.SimulationContextService;
 import org.splat.service.StepService;
 import org.splat.service.dto.DocumentDTO;
 import org.splat.service.dto.FileDTO;
@@ -105,6 +110,13 @@ public class TestScenarioService extends BaseTest {
        @Qualifier("stepService")
        private transient StepService _stepService;
 
+       /**
+        * The SimulationContextService. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("simulationContextService")
+       private transient SimulationContextService _simulationContextService;
+       
        /**
         * The ProjectSettingsService. Later injected by Spring.
         */
@@ -119,6 +131,13 @@ public class TestScenarioService extends BaseTest {
        @Qualifier("documentTypeService")
        private transient DocumentTypeService _documentTypeService;
 
+       /**
+        * The KnowledgeElementTypeService. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("knowledgeElementTypeService")
+       private transient KnowledgeElementTypeService _knowledgeElementTypeService;
+
        /**
         * Test of getting a scenario content for building siman-salome.conf.<BR>
         * <B>Description :</B> <BR>
@@ -835,4 +854,108 @@ public class TestScenarioService extends BaseTest {
 
                return pub;
        }
+
+
+       /**
+        * Test check-in scenario operation to be performed after SALOME session.<BR>
+        * <B>Description :</B> <BR>
+        * <i>Create a scenario and try to check-in it with some simulated SALOME results data.<BR>
+        * After check-in verify following points:
+        * <ul>
+        * <li>scenario is no more marked as checked out</li>
+        * <li>new document versions are created for checked in documents</li>
+        * <li>presentation of the previous version is removed</li>
+        * <li>uses relations are copied correctly</li>
+        * <li>files are moved correctly</li>
+        * <li>new documents are created for new data</li>
+        * <li>uses relations are created correctly</li>
+        * <li>files are moved correctly</li>
+        * </ul>
+        * </i><BR>
+        * <B>Action : </B><BR>
+        * <i>1. call the method for an existing scenario id.</i><BR>
+        * <i>2. call the method for a not existing scenario id.</i><BR>
+        * <B>Test data : </B><BR>
+        * <i>no input parameters</i><BR>
+        * <i>no input parameters</i><BR>
+        * 
+        * <B>Outcome results:</B><BR>
+        * <i>
+        * <ul>
+        * <li>New version of existing documents must be created and new documents must be imported for documents with zero id. Correct
+        * relations must be created.<BR>
+        * </li>
+        * <li>Exception is thrown<BR>
+        * </li>
+        * </ul>
+        * </i>
+        * 
+        * @throws InvalidPropertyException
+        *             if an invalid property is used when creating objects
+        * @throws MultiplyDefinedException
+        *             when trying to create an object with already existing id
+        * @throws MissedPropertyException
+        *             if a mandatory property is not defined for an object to be created
+        * @throws IOException
+        *             if scenario creation is failed
+        * @throws SQLException
+        *             if scenario creation is failed
+        * @throws NotApplicableException
+        *             if checkin failed
+        * @throws MismatchException
+        *             if checkin failed
+        */
+       @Test(groups = { "study", "sevice", "functional", "business" })
+       public void testCreateStudy() throws InvalidPropertyException,
+                       MissedPropertyException, MultiplyDefinedException, IOException,
+                       SQLException, MismatchException, NotApplicableException {
+               LOG.debug(">>>>> BEGIN testCreateStudy()");
+               startNestedTransaction();
+               
+               Database.getInstance().reset();
+               _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+               _projectSettings.configure(ClassLoader
+                               .getSystemResource("test/som.xml").getPath());
+               
+               // Create a test user
+               User.Properties uprop = new User.Properties();
+               uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
+                               .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
+                               .addRole("TST_user").setMailAddress(
+                                               "noreply@salome-platform.org");
+               uprop.disableCheck();
+               User anAuthor = new User(uprop);
+               
+               getHibernateTemplate().saveOrUpdate(anAuthor);
+               KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
+               Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+               SimulationContextType prodtype = _simulationContextService.selectType("product");
+               Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
+               
+               // Create admin
+               uprop.clear();
+               uprop.setUsername("TST_Admin").setName("TST_SimanUnitTestsAdmin")
+                               .setFirstName("TST_AdminFirstName").setDisplayName("TST_test.admin")
+                               .addRole("TST_user,sysadmin").setMailAddress(
+                                               "noreply@salome-platform.org");
+               uprop.disableCheck();
+               
+               getHibernateTemplate().saveOrUpdate(new User(uprop));
+               getHibernateTemplate().flush();
+               
+               Study.Properties sprop = new Study.Properties();
+               sprop.setTitle("Test study creation").setManager(anAuthor);
+               Scenario.Properties oprop = new Scenario.Properties();
+               oprop.setTitle("Test scenario for the created study");
+
+               // Addition of the entered project context
+               SimulationContext.Properties cprop = new SimulationContext.Properties();
+               // Input of new project context
+               cprop.setType(_simulationContextService.selectType("product"))
+                                       .setValue("Test Simulation Context: Product");
+               Study study = _scenarioService.createStudy(sprop, oprop, cprop);
+               
+               rollbackNestedTransaction();
+               LOG.debug(">>>>> END testCreateStudy()");
+       }
 }
diff --git a/Workspace/Siman-Common/testng_study.xml b/Workspace/Siman-Common/testng_study.xml
new file mode 100644 (file)
index 0000000..f35d3e3
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="SimanCommonTests" verbose="1">
+       <test name="all">
+               <method-selectors>
+                       <method-selector>
+                               <script language="beanshell">
+                                       <![CDATA[
+                (groups.containsKey("study")) && method.getName().toUpperCase().startsWith("TEST")             
+              ]]>
+                               </script>
+                       </method-selector>
+               </method-selectors>
+        <groups>
+            <!-- 
+                <define name="all">
+                <include name="business"/>
+                <include name="functional"/>
+                <include name="service"/>
+                </define>
+                <define name="new">
+                <include name="newservice"/>
+                </define>
+                <run>
+                <include name="all"/>
+                <exclude name="old"/>
+                </run>
+            -->
+
+        </groups>
+               <packages>
+                       <package name="test.*" />
+               </packages>
+       </test>
+</suite>
index 4cb9919cb1beb77ccd8f51cc62dc3fcb3ed5e903..c61d1bf6064a58e598178736b916b62e44d0ad75 100644 (file)
@@ -5,7 +5,8 @@ connection.password=admin
 connection.driver_class=com.p6spy.engine.spy.P6SpyDriver
 
 # Hibernate config
-hibernate.hbm2ddl.auto=validate
+#hibernate.hbm2ddl.auto=validate
+hibernate.hbm2ddl.auto=update
 hibernate.dialect=org.hibernate.dialect.MySQLDialect
 hibernate.current_session_context_class=thread