]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Check of results of scenario checkin is added to the unit test.
authorrkv <rkv@opencascade.com>
Fri, 23 Nov 2012 11:44:26 +0000 (11:44 +0000)
committerrkv <rkv@opencascade.com>
Fri, 23 Nov 2012 11:44:26 +0000 (11:44 +0000)
Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java

index 1823de7a3fe01bdfe0205a7c6072c3c583f10b9d..ed044b3ae8f8fc1d0cb1d9c0d932e0569bf869e7 100644 (file)
@@ -257,7 +257,19 @@ public class TestScenarioService extends BaseTest {
        /**
         * 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.</i><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>
@@ -304,15 +316,8 @@ public class TestScenarioService extends BaseTest {
                User user = aScen.getAuthor();
                long userId = user.getIndex();
 
-               // Prepare download directory
-               File tmpDir = _repositoryService.getDownloadDirectory(userId);
-               if (!tmpDir.exists()) {
-                       Assert.assertTrue(tmpDir.mkdir(),
-                                       "Can't create temporary directory: "
-                                                       + tmpDir.getAbsolutePath());
-               }
-
-               // Call DAO's create method for a good transient knowledge element.
+               // ////////////////////////////////////////////////////////
+               // Call checkin method for good prepared transient data.
 
                // Simulate checkout
                List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
@@ -323,13 +328,83 @@ public class TestScenarioService extends BaseTest {
                List<StepDTO> stepsToCheckin = new ArrayList<StepDTO>();
                for (StepDTO step : steps) {
                        // Prepare GEOM: checkin actual brep
-                       createDocForModule("GEOM", "brep", tmpDir, step, stepsToCheckin);
-                       createDocForModule("SMESH", "med", tmpDir, step, stepsToCheckin);
+                       StepDTO stepToCheckin = createDocDTOForModule(null, "GEOM", "brep",
+                                       userId, step, stepsToCheckin);
+                       createDocDTOForModule(stepToCheckin, "SMESH", "med", userId, step,
+                                       stepsToCheckin);
                }
                // Do test checkin
                _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
 
-               // Call DAO's get method for a not existing id.
+               // Check that scenario is no more marked as checked out
+               aScen = _scenarioDAO.get(scenarioId);
+               Assert.assertFalse(aScen.isCheckedout(),
+                               "Scenario is still marked as checked out after checkin.");
+               // Check that new document versions are created for checked in documents
+               for (StepDTO step : stepsToCheckin) {
+                       for (DocumentDTO docDTO : step.getDocs()) {
+                               if (docDTO.getId() != 0) {
+                                       boolean found = false;
+                                       Document prevDoc = null;
+                                       Publication newPub = null;
+                                       for (Publication pub : aScen.getDocums()) {
+                                               prevDoc = pub.value().getPreviousVersion();
+                                               if (prevDoc != null) {
+                                                       found = (prevDoc.getIndex() == docDTO.getId());
+                                                       if (found) { // Found next published version of the checked in document
+                                                               newPub = pub;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+                                       Assert.assertTrue(found,
+                                                       "New version of existing checked in document \""
+                                                                       + docDTO.getTitle() + "\" (id="
+                                                                       + docDTO.getId()
+                                                                       + ") is not found in the scenario.");
+                                       // Check that presentation of the previous version is removed
+                                       Assert.assertFalse(aScen.publishes(prevDoc));
+                                       // Check that files are moved correctly
+                                       for (int j = 0; j < docDTO.getFiles().size(); j++) {
+                                               FileDTO fileDTO = docDTO.getFiles().get(j);
+                                               Assert
+                                                               .assertFalse(
+                                                                               new File(fileDTO.getPath()).exists(),
+                                                                               "File"
+                                                                                               + fileDTO.getPath()
+                                                                                               + " was not removed from downloads directory.");
+                                               String format = fileDTO.getPath().substring(
+                                                               fileDTO.getPath().lastIndexOf('.') + 1);
+                                       }
+                                       // Check file by its internal content
+                                       // Check that uses relations are copied correctly
+
+                               } else {
+                                       // Check that new documents are created for new data
+                                       boolean found = false;
+                                       Publication newPub = null;
+                                       for (Publication pub : aScen.getDocums()) {
+                                               if (pub.value().getPreviousVersion() == null) {
+                                                       found = (docDTO.getTitle().equals(pub.value()
+                                                                       .getTitle()));
+                                                       if (found) { // Found next published version of the checked in document
+                                                               newPub = pub;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+                                       Assert.assertTrue(found,
+                                                       "New document is not created for checked in document \""
+                                                                       + docDTO.getTitle() + "\".");
+                                       // Check that uses relations are created correctly
+                                       // Check that files are moved correctly
+
+                               }
+                       }
+               }
+
+               // ///////////////////////////////////////////////////////////
+               // Call checkin method for a not existing id.
                try {
                        _scenarioService.checkin(-1, userId, stepsToCheckin);
                        Assert
@@ -338,52 +413,102 @@ public class TestScenarioService extends BaseTest {
                        LOG.debug("Expected exception is thrown: "
                                        + e.getClass().getSimpleName() + ": " + e.getMessage());
                }
+
                LOG.debug(">>>>> END testCheckin()");
        }
 
        /**
         * Prepare a document with a file for check-in.
         * 
+        * @param stepTo
+        *            step DTO with data for check-in
         * @param module
         *            SALOME module name
         * @param format
         *            file extension
-        * @param tmpDir
+        * @param userId
         *            download directory
-        * @param step
+        * @param stepFrom
         *            checked out stepDTO
         * @param stepsToCheckin
         *            DTO for check-in
         * @throws IOException
         *             if file creation failed
+        * @return step DTO with data prepared for check-in (stepTo or new if stepTo is null)
         */
-       private void createDocForModule(final String module, final String format,
-                       final File tmpDir, final StepDTO step,
-                       final List<StepDTO> stepsToCheckin) throws IOException {
-               if (module.equals(step.getModule())) {
-                       StepDTO stepToCheckin = new StepDTO();
+       private StepDTO createDocDTOForModule(final StepDTO stepTo,
+                       final String module, final String format, final long userId,
+                       final StepDTO stepFrom, final List<StepDTO> stepsToCheckin)
+                       throws IOException {
+               StepDTO stepToCheckin = stepTo;
+               if (stepToCheckin == null) {
+                       stepToCheckin = new StepDTO();
+               }
+               if (module.equals(stepFrom.getModule())) {
                        stepsToCheckin.add(stepToCheckin);
-                       stepToCheckin.setNumber(step.getNumber());
-                       for (DocumentDTO doc : step.getDocs()) {
+                       stepToCheckin.setNumber(stepFrom.getNumber());
+                       for (DocumentDTO doc : stepFrom.getDocs()) {
                                if (doc.getFiles().get(0).getState() != 'O') {
                                        DocumentDTO docToCheckin = stepToCheckin.addDoc(
                                                        doc.getId(), doc.getTitle());
                                        for (FileDTO file : doc.getFiles()) {
                                                if (file.getPath().endsWith(format)) {
                                                        // Create a file in the download directory
-                                                       String filePath = tmpDir.getAbsolutePath() + "/"
-                                                                       + doc.getTitle() + "_result." + format;
-                                                       FileWriter fw = new FileWriter(filePath);
-                                                       fw.write("Simulation of " + format
-                                                                       + " file for checkin at " + new Date());
-                                                       fw.close();
-                                                       FileDTO fileToCheckin = new FileDTO(filePath);
-                                                       docToCheckin.addFile(fileToCheckin);
+                                                       docToCheckin.addFile(createDownloadedFile(userId,
+                                                                       doc.getTitle() + "_result", format));
                                                }
                                        }
                                }
                        }
+                       // Prepare new data
+                       stepToCheckin.addDoc(0, "newdoc" + stepFrom.getNumber()).addFile(
+                                       createDownloadedFile(userId, "newdoc"
+                                                       + stepFrom.getNumber(), "brep"));
+               }
+               return stepToCheckin;
+       }
+
+       /**
+        * Create a file in the user's repository downloads directory.
+        * 
+        * @param userId
+        *            user id
+        * @param name
+        *            file name
+        * @param format
+        *            file extension
+        * @return created file DTO
+        * @throws IOException
+        *             if file creation failed
+        */
+       private FileDTO createDownloadedFile(final long userId, final String name,
+                       final String format) throws IOException {
+               // Create a file in the download directory
+               String filePath = getDownloadPath(userId) + name + "." + format;
+               FileWriter fw = new FileWriter(filePath);
+               fw.write("Simulation of " + name + "." + format
+                               + " file for checkin at " + new Date());
+               fw.close();
+               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() + "/";
        }
 
        /**
@@ -479,7 +604,7 @@ public class TestScenarioService extends BaseTest {
                }
 
                // Check that the scenario and its documents have been created correctly.
-               
+
                Assert.assertNotNull(ht.find("from Document"),
                                "No documents in the database.");
                Assert.assertTrue(ht.find("from Document").size() > 0,