]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java
Salome HOME
Fix for generating a description for version relation during checkin.
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestScenarioService.java
index b402d1d9cac2e17b2f1fe8f1112d488407ac946a..baddb0191ebade1c24ed126f47637be8797899b6 100644 (file)
@@ -34,12 +34,18 @@ 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;
+import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.dal.bo.som.ValidationCycleRelation;
+import org.splat.dal.bo.som.ValidationStep;
+import org.splat.dal.bo.som.VersionsRelation;
 import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.dao.kernel.UserDAO;
 import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.dal.dao.som.StudyDAO;
+import org.splat.dal.dao.som.ValidationCycleDAO;
 import org.splat.exception.BusinessException;
+import org.splat.exception.InvalidParameterException;
 import org.splat.i18n.I18nUtils;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
@@ -49,6 +55,7 @@ import org.splat.kernel.NotApplicableException;
 import org.splat.log.AppLogger;
 import org.splat.service.DocumentTypeService;
 import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.ProjectElementService;
 import org.splat.service.PublicationService;
 import org.splat.service.ScenarioService;
 import org.splat.service.SimulationContextService;
@@ -177,6 +184,20 @@ public class TestScenarioService extends BaseTest {
        @Qualifier("studyDAO")
        private transient StudyDAO _studyDAO;
 
+       /**
+        * The ValidationCycleDAO. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("validationCycleDAO")
+       private transient ValidationCycleDAO _validationCycleDAO;
+
+       /**
+        * The ProjectElementService. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("projectElementService")
+       private transient ProjectElementService _projectElementService;
+
        /**
         * Test of getting a scenario content for building siman-salome.conf.<BR>
         * <B>Description :</B> <BR>
@@ -437,6 +458,7 @@ public class TestScenarioService extends BaseTest {
                        createDocDTOForModule(stepToCheckin, "SMESH", "med", userId, step,
                                        stepsToCheckin);
                }
+               // /////////////////////////////////////////////////////////////////
                // Do test checkin
                _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
 
@@ -491,15 +513,15 @@ public class TestScenarioService extends BaseTest {
                                                                && "geometry".equals(prevDoc.getType()
                                                                                .getName())) {
                                                        Assert.assertEquals(newPub.value().getFormat(),
-                                                                       "brep");
+                                                                       newFormat);
                                                        Assert.assertEquals(newPub.getSourceFile()
-                                                                       .getFormat(), "brep");
+                                                                       .getFormat(), newFormat);
                                                        Assert.assertEquals(newPub.getSourceFile()
                                                                        .getRelativePath().substring(
                                                                                        newPub.getSourceFile()
                                                                                                        .getRelativePath()
                                                                                                        .lastIndexOf('.') + 1),
-                                                                       "brep");
+                                                                       newFormat);
                                                }
 
                                                // Check that uses relations are copied correctly
@@ -543,6 +565,21 @@ public class TestScenarioService extends BaseTest {
                                                                                                + ") must become outdated.");
                                                        }
                                                }
+
+                                               // Check that a correct comment is generated for VersionsRelation
+                                               VersionsRelation versRel = (VersionsRelation) newPub
+                                                               .value().getFirstRelation(
+                                                                               VersionsRelation.class);
+                                               Assert.assertNotNull(versRel,
+                                                               "VersionsRelation must be created.");
+                                               Assert
+                                                               .assertNotNull(versRel.getDescription(),
+                                                                               "VersionsRelation description was not generated.");
+                                               int descrLen = versRel.getDescription().length();
+                                               Assert.assertTrue(descrLen > 0,
+                                                               "VersionsRelation description is empty.");
+                                               LOG.debug("Version description: "
+                                                               + versRel.getDescription());
                                        } else {
                                                // Otherwise the new file format must differ from the previous one
                                                // and the new file must be attached to the same document
@@ -749,8 +786,17 @@ public class TestScenarioService extends BaseTest {
                                                                || (file.getPath().endsWith("py") && (format
                                                                                .equals("brep") || format.equals("med")))) {
                                                        // Create a file in the download directory
-                                                       docToCheckin.addFile(createDownloadedFile(userId,
-                                                                       doc.getTitle() + "_result", format));
+                                                       if ("GEOM".equals(module)) {
+                                                               // New version case
+                                                               docToCheckin.addFile(createDownloadedFile(
+                                                                               userId, doc.getTitle() + "_newvers",
+                                                                               "py"));
+                                                       } else {
+                                                               // Attached generated result case
+                                                               docToCheckin.addFile(createDownloadedFile(
+                                                                               userId, doc.getTitle() + "_result",
+                                                                               format));
+                                                       }
                                                }
                                        }
                                }
@@ -804,25 +850,6 @@ public class TestScenarioService extends BaseTest {
                return new FileDTO(filePath);
        }
 
-       /**
-        * Get path to the user's downloads directory. The directory is created if it is not exist yet.
-        * 
-        * @param userId
-        *            user id
-        * @return absolute path to downloads directory followed by slash
-        */
-       private String getDownloadPath(final long userId) {
-               // Prepare download directory
-               File tmpDir = _repositoryService.getDownloadDirectory(userId);
-               if (!tmpDir.exists()) {
-                       Assert.assertTrue(tmpDir.mkdir(),
-                                       "Can't create temporary directory: "
-                                                       + tmpDir.getAbsolutePath());
-               }
-
-               return tmpDir.getAbsolutePath() + "/";
-       }
-
        /**
         * Create a persistent scenario for tests.
         * 
@@ -1161,13 +1188,13 @@ public class TestScenarioService extends BaseTest {
                        BusinessException {
                LOG.debug(">>>>> BEGIN testCreateStudyFromPython()");
                startNestedTransaction();
-       
+
                HibernateTemplate ht = getHibernateTemplate();
-       
+
                Database.getInstance().reset();
                _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                _projectSettings.configure("classpath:test/som.xml");
-       
+
                // Create a test user
                User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
                _userDAO.create(goodUser);
@@ -1176,15 +1203,15 @@ public class TestScenarioService extends BaseTest {
                Assert
                                .assertNotNull(prodtype,
                                                "Simulation context type 'product' must be created in the database.");
-       
+
                String productName = "New Test Product " + new Date().toString();
-       
+
                ht.flush();
                ht.clear();
                long studyId1 = _scenarioService.createStudy("goodUser",
                                "Test Study 1", productName, "Test description");
                Assert.assertTrue(studyId1 > 0);
-       
+
                ht.flush();
                ht.clear();
                try {
@@ -1194,26 +1221,26 @@ public class TestScenarioService extends BaseTest {
                } catch (InvalidPropertyException ipe) {
                        LOG.debug("Expected exception: " + ipe.getMessage());
                }
-       
+
                ht.flush();
                ht.clear();
                long studyId3 = _scenarioService.createStudy("goodUser",
                                "Test Study 3", productName, "Test description");
                Assert.assertTrue(studyId3 > 0);
-       
+
                // Check that the simulation context is the same
                Study study1 = _studyService.selectStudy(studyId1);
                Study study3 = _studyService.selectStudy(studyId3);
                Assert.assertEquals(study1.SimulationContextIterator().next(), study3
                                .SimulationContextIterator().next());
-       
+
                // Check the title of the created scenario
                String scTitle = study1.getScenarii()[0].getTitle();
                Assert.assertEquals(scTitle, I18nUtils
                                .getMessageLocaleDefault("label.scenario")
                                + " 1");
                Assert.assertFalse(scTitle.equals("label.scenario 1"));
-       
+
                rollbackNestedTransaction();
                LOG.debug(">>>>> END testCreateStudyFromPython()");
        }
@@ -1224,19 +1251,19 @@ public class TestScenarioService extends BaseTest {
         * <i>Create a study.</i><BR>
         * <B>Action : </B><BR>
         * <i>1. call the method for a not existing source study.</i><BR>
-        * <i>1. call the method for a not existing source scenario.</i><BR>
-        * <i>1. call the method for a not existing source study.</i><BR>
-        * <i>2. call the method for an existing username and an existing product.</i><BR>
-        * <i>3. call the method for a not existing username expecting an exception.</i><BR>
+        * <i>2. call the method for a not existing source scenario with not evolving step.</i><BR>
+        * <i>3. call the method for a not existing source scenario with evolving step.</i><BR>
+        * <i>4. call the method for an existing source scenario with evolving step.</i><BR>
         * <B>Test data : </B><BR>
         * <i>no input parameters</i><BR>
         * 
         * <B>Outcome results:</B><BR>
         * <i>
         * <ul>
-        * <li>1: The new study must be created. The new product simulation context must be created.</li>
-        * <li>2: The new study must be created.</li>
-        * <li>3: The new study must not be created. Exception must be thrown.</li>
+        * <li>1: Exception must be thrown.</li>
+        * <li>2: The study content must be copied.</li>
+        * <li>3: Exception must be thrown.</li>
+        * <li>4: The study content must be copied.</li>
         * </ul>
         * </i>
         * 
@@ -1259,51 +1286,200 @@ public class TestScenarioService extends BaseTest {
                _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                _projectSettings.configure("classpath:test/som.xml");
 
-               // Create a test user
-               User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
+               User goodUser = TestEntitiesGenerator.getTestUser("GoodUser");
                _userDAO.create(goodUser);
-               SimulationContextType prodtype = _simulationContextService
-                               .selectType("product");
-               Assert
-                               .assertNotNull(prodtype,
-                                               "Simulation context type 'product' must be created in the database.");
+               User otherUser = TestEntitiesGenerator.getTestUser("otherUser");
+               _userDAO.create(otherUser);
 
-               String productName = "New Test Product " + new Date().toString();
+               // Create private study
+               Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
+               aStudy.setTitle("0.This is private study");
+               Long studyId = _studyDAO.create(aStudy);
 
+               // Add a scenario to the study
+               Scenario scen = TestEntitiesGenerator.getTestScenario(aStudy);
+               _scenarioDAO.create(scen);
                ht.flush();
-               ht.clear();
-               long studyId1 = _scenarioService.createStudy("goodUser",
-                               "Test Study 1", productName, "Test description");
-               Assert.assertTrue(studyId1 > 0);
+               // Add a second scenario to the study
+               scen = TestEntitiesGenerator.getTestScenario(aStudy);
+               Long aScenId = _scenarioDAO.create(scen);
+               ht.flush();
+
+               // Add a validation cycle with otherUser as a reviewer
+               ValidationCycle.Properties vprop = new ValidationCycle.Properties();
+               DocumentType dtype = _documentTypeService.selectType("minutes");
+               vprop.setDocumentType(dtype);
+               vprop.setActor(ValidationStep.REVIEW, otherUser);
+               ValidationCycle cycle = new ValidationCycle(aStudy, vprop);
+               _validationCycleDAO.create(cycle);
+               ValidationCycleRelation link = cycle.getContext();
+               aStudy.addRelation(link);
+               ht.flush();
+
+               // Add documents to the first study activity
+               // Add a converts relations
+               Map<Integer, org.splat.som.Step> stSteps = _projectElementService
+                               .getStepsMap(aStudy);
+               org.splat.som.Step aStep = stSteps.get(1);
+               Publication pub1 = addDoc(aStudy, aStep, "document1", dtype);
+               Publication pub2 = addDoc(aStudy, aStep, "document2", dtype);
+               Publication pub3 = addDoc(aStudy, aStep, "document3", dtype);
+               ht.flush();
+
+               LOG.debug("pub1 version doc: " + pub1.value().getTitle() + " ["
+                               + pub1.value().getReference() + "]" + " ["
+                               + pub1.value().getRid() + "]");
+               LOG.debug("pub2 version doc: " + pub2.value().getTitle() + " ["
+                               + pub2.value().getReference() + "]" + " ["
+                               + pub2.value().getRid() + "]");
+               LOG.debug("pub3 version doc: " + pub3.value().getTitle() + " ["
+                               + pub3.value().getReference() + "]" + " ["
+                               + pub3.value().getRid() + "]");
+
+               ht.update(aStudy);
 
+               ht.flush();
+               LOG.debug("Before versioning:");
+               for (Publication doc : _projectElementService.getFirstStep(aStudy)
+                               .getAllDocuments()) {
+                       LOG.debug("Study doc: " + doc.value().getTitle() + " ["
+                                       + doc.value().getReference() + "]" + " ["
+                                       + doc.value().getRid() + "]");
+               }
+               // Add a version relations
+               Publication pub31 = version(pub3);
+               ht.flush();
+               //
+               // LOG.debug("pub31 version doc: " + pub31.value().getTitle() + " ["
+               // + pub31.value().getReference() + "]" + " ["
+               // + pub31.value().getRid() + "]");
+               // ht.saveOrUpdate(aStudy);
+
+               // LOG.debug("After versioning:");
+               // for (Publication doc : aStudy.getDocums()) {
+               // LOG.debug("Study doc: " + doc.value().getTitle() + " ["
+               // + doc.value().getReference() + "]" + " ["
+               // + doc.value().getRid() + "]");
+               // }
+
+               // Add documents to the first scenario activity
+               Map<Integer, org.splat.som.Step> scSteps = _projectElementService
+                               .getStepsMap(scen);
+               aStep = scSteps.get(2);
+               Publication spub1 = addDoc(scen, aStep, "sdocument1", dtype);
+               Publication spub2 = addDoc(scen, aStep, "sdocument2", dtype);
+               Publication spub3 = addDoc(scen, aStep, "sdocument3", dtype);
+               LOG.debug("spub1 version doc: " + spub1.value().getTitle() + " ["
+                               + spub1.value().getReference() + "]" + " ["
+                               + spub1.value().getRid() + "]");
+               LOG.debug("spub2 version doc: " + spub2.value().getTitle() + " ["
+                               + spub2.value().getReference() + "]" + " ["
+                               + spub2.value().getRid() + "]");
+               LOG.debug("spub3 version doc: " + spub3.value().getTitle() + " ["
+                               + spub3.value().getReference() + "]" + " ["
+                               + spub3.value().getRid() + "]");
+               ht.flush();
+
+               // Create a scenario document version
+               Publication spub31 = version(spub3);
+               // LOG.debug("spub31 version doc: " + spub31.value().getTitle() + " ["
+               // + spub31.value().getReference() + "]" + " ["
+               // + spub31.value().getRid() + "]");
+               ht.flush();
+
+               // Add uses relations
+               pub2.addDependency(pub1);
+               ht.saveOrUpdate(pub2.value());
+               pub3.addDependency(pub2);
+               ht.saveOrUpdate(pub3.value());
+
+               spub2.addDependency(pub1);
+               spub2.addDependency(spub1);
+               spub2.addDependency(pub2);
+               spub2.addDependency(pub3);
+               ht.saveOrUpdate(spub2.value());
+               spub3.addDependency(spub2);
+               ht.saveOrUpdate(spub3.value());
+               spub31.addDependency(pub31);
+               ht.saveOrUpdate(spub31.value());
+               ht.flush();
+
+               // Create target study1
+               Study aStudy1 = TestEntitiesGenerator.getTestStudy(goodUser);
+               aStudy1.setTitle("1.This is a target study1");
+               aStudy1.setReference("tst1");
+               Long studyId1 = _studyDAO.create(aStudy1);
+
+               // Add a scenario to the study
+               Scenario scen1 = TestEntitiesGenerator.getTestScenario(aStudy1);
+               _scenarioDAO.create(scen1);
+               ht.flush();
+
+               // Create target study2
+               Study aStudy2 = TestEntitiesGenerator.getTestStudy(goodUser);
+               aStudy2.setTitle("2.This is a target study2");
+               aStudy2.setReference("tst2");
+               Long studyId2 = _studyDAO.create(aStudy2);
+
+               // Add a scenario to the study
+               Scenario scen2 = TestEntitiesGenerator.getTestScenario(aStudy2);
+               _scenarioDAO.create(scen2);
                ht.flush();
                ht.clear();
+
+               // //////////////////// TEST CALL /////////////////////////////////////
+               // 1. call the method for a not existing source study.
                try {
-                       _scenarioService.createStudy("badbadUser", "Test Study 2",
-                                       productName, "Test description");
-                       Assert.fail("Study must not be created for not existing user.");
-               } catch (InvalidPropertyException ipe) {
-                       LOG.debug("Expected exception: " + ipe.getMessage());
+                       _scenarioService.copyStudyContent(-1, -1, -1, -1);
+                       Assert.fail("Exception must be thrown for not existing study id.");
+               } catch (InvalidParameterException e) {
+                       LOG.debug("Expected exception: " + e.getClass().getSimpleName()
+                                       + ": " + e.getMessage());
                }
 
                ht.flush();
                ht.clear();
-               long studyId3 = _scenarioService.createStudy("goodUser",
-                               "Test Study 3", productName, "Test description");
-               Assert.assertTrue(studyId3 > 0);
 
-               // Check that the simulation context is the same
-               Study study1 = _studyService.selectStudy(studyId1);
-               Study study3 = _studyService.selectStudy(studyId3);
-               Assert.assertEquals(study1.SimulationContextIterator().next(), study3
-                               .SimulationContextIterator().next());
+               // 2. call the method for a not existing source scenario with not evolving step.
+               _scenarioService.copyStudyContent(studyId, -1, 1, studyId1);
 
-               // Check the title of the created scenario
-               String scTitle = study1.getScenarii()[0].getTitle();
-               Assert.assertEquals(scTitle, I18nUtils
-                               .getMessageLocaleDefault("label.scenario")
-                               + " 1");
-               Assert.assertFalse(scTitle.equals("label.scenario 1"));
+               ht.flush();
+               ht.clear();
+
+               aStudy = _studyService.selectStudy(studyId);
+               aStudy1 = _studyService.selectStudy(studyId1);
+               for (Publication pub : aStudy.getDocums()) {
+                       // Find the same document in the created copy of the study
+                       Publication found = null;
+                       for (Publication newPub : aStudy1.getDocums()) {
+                               if (pub.value().getTitle().equals(newPub.value().getTitle())
+                                               && pub.value().getType().equals(
+                                                               newPub.value().getType())) {
+                                       found = newPub;
+                                       break;
+                               }
+                       }
+                       Assert.assertNotNull(found, "The document "
+                                       + pub.value().getTitle() + "is not copied");
+                       // Check that all files are copied (source and attached)
+               }
+
+               // 3. call the method for a not existing source scenario with evolving step.
+               try {
+                       _scenarioService.copyStudyContent(studyId, -1, 2, studyId2);
+                       Assert
+                                       .fail("Exception must be thrown for not existing scenario id and evolving step.");
+               } catch (InvalidParameterException e) {
+                       LOG.debug("Expected exception: " + e.getClass().getSimpleName()
+                                       + ": " + e.getMessage());
+               }
+
+               ht.flush();
+               ht.clear();
+
+               // 4. call the method for an existing source scenario with evolving step.
+               _scenarioService.copyStudyContent(studyId, aScenId, 9, studyId2);
+               ht.flush();
 
                rollbackNestedTransaction();
                LOG.debug(">>>>> END testCopyStudyContent()");
@@ -1347,13 +1523,13 @@ public class TestScenarioService extends BaseTest {
                        SQLException, BusinessException {
                LOG.debug(">>>>> BEGIN testAssignStudyContextFromPython()");
                startNestedTransaction();
-       
+
                HibernateTemplate ht = getHibernateTemplate();
-       
+
                Database.getInstance().reset();
                _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                _projectSettings.configure("classpath:test/som.xml");
-       
+
                // Create a test user
                User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
                _userDAO.create(goodUser);
@@ -1362,18 +1538,18 @@ public class TestScenarioService extends BaseTest {
                Assert
                                .assertNotNull(prodtype,
                                                "Simulation context type 'product' must be created in the database.");
-       
+
                String productName = "New Test Product " + new Date().toString();
-       
+
                ht.flush();
                ht.clear();
                long studyId1 = _scenarioService.createStudy("goodUser",
                                "Test Study 1", productName, "Test description");
                Assert.assertTrue(studyId1 > 0);
-       
+
                ht.flush();
                ht.clear();
-       
+
                // //////// START OF TESTS
                // 1. call the method for not existing study id.</i><BR>
                try {
@@ -1383,37 +1559,37 @@ public class TestScenarioService extends BaseTest {
                } catch (InvalidPropertyException ipe) {
                        LOG.debug("Expected exception: " + ipe.getMessage());
                }
-       
+
                // 2. call the method for not existing context type and context value.</i><BR>
                _scenarioService.assignStudyContext(studyId1, "new context type",
                                "new context value");
-       
+
                ht.flush();
                ht.clear();
-       
+
                // Check the assigned simulation context
                checkCtx(studyId1, "new context type", "new context value");
-       
+
                // 3. call the method for existing context type and context value.</i><BR>
                _scenarioService.assignStudyContext(studyId1, "new context type",
                                "new context value");
-       
+
                ht.flush();
                ht.clear();
-       
+
                // Check the assigned simulation context
                checkCtx(studyId1, "new context type", "new context value");
-       
+
                // 4. call the method for existing context type and not existing context value.</i><BR>
                _scenarioService.assignStudyContext(studyId1, "new context type",
                                "new context value1");
-       
+
                ht.flush();
                ht.clear();
-       
+
                // Check the assigned simulation context
                checkCtx(studyId1, "new context type", "new context value1");
-       
+
                // 5. call the method for empty context type.</i><BR>
                try {
                        _scenarioService.assignStudyContext(studyId1, "",
@@ -1430,7 +1606,7 @@ public class TestScenarioService extends BaseTest {
                } catch (InvalidPropertyException ipe) {
                        LOG.debug("Expected exception: " + ipe.getMessage());
                }
-       
+
                rollbackNestedTransaction();
                LOG.debug(">>>>> END testAssignStudyContextFromPython()");
        }
@@ -1463,8 +1639,8 @@ public class TestScenarioService extends BaseTest {
         *             if test data creation is failed
         */
        @Test(groups = { "study", "sevice", "functional", "business" })
-       public void testGetStudyScenarios() throws IOException,
-                       SQLException, BusinessException {
+       public void testGetStudyScenarios() throws IOException, SQLException,
+                       BusinessException {
                LOG.debug(">>>>> BEGIN testGetStudyScenarios()");
                startNestedTransaction();
 
@@ -1480,7 +1656,8 @@ public class TestScenarioService extends BaseTest {
                Study study = TestEntitiesGenerator.getTestStudy(goodUser);
                long studyId1 = _studyDAO.create(study);
                ht.flush();
-               Scenario scen = TestEntitiesGenerator.getTestScenario(study, "test scen11");
+               Scenario scen = TestEntitiesGenerator.getTestScenario(study,
+                               "test scen11");
                long id11 = _scenarioDAO.create(scen);
                ht.flush();
                study = TestEntitiesGenerator.getTestStudy(goodUser);
@@ -1496,14 +1673,14 @@ public class TestScenarioService extends BaseTest {
                long id23 = _scenarioDAO.create(scen);
                ht.flush();
                ht.clear();
-               
+
                // //////// START OF TESTS
                // 1. call the method for not existing study id.
                List<ScenarioDTO> scens = _scenarioService.getStudyScenarios(-1L);
 
                Assert.assertNotNull(scens);
                Assert.assertTrue(scens.isEmpty());
-               
+
                // 2. call the method for a study with one scenario.
                scens = _scenarioService.getStudyScenarios(studyId1);