Salome HOME
Fix for mantis #0022110: Same files should not be attached again to the document...
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestScenarioService.java
index 9776fc2727b8ceaeec3c21129d4ea4688a238eba..9afe64ac782902e0f3302edb1e99c67ba52ff226 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Set;
 
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.KnowledgeElementType;
@@ -350,7 +351,6 @@ public class TestScenarioService extends BaseTest {
                User user = aScen.getAuthor();
                long userId = user.getIndex();
 
-               
                // ////////////////////////////////////////////////////////
                // Call checkin method for empty list of modules.
 
@@ -374,9 +374,7 @@ public class TestScenarioService extends BaseTest {
                aScen = _scenarioDAO.get(scenarioId);
                Assert.assertFalse(aScen.isCheckedout(),
                                "Scenario is still marked as checked out after checkin.");
-               
-               
-               
+
                // ////////////////////////////////////////////////////////
                // Call checkin method for good prepared transient data.
 
@@ -384,6 +382,16 @@ public class TestScenarioService extends BaseTest {
                steps = _scenarioService.getScenarioInfo(scenarioId);
                _scenarioService.checkout(aScen, user);
 
+               // Remember modification dates of all attached files
+               Map<Long, Date> dates = new HashMap<Long, Date>();
+               for (Publication p : aScen.getDocums()) {
+                       for (Relation r : p.value().getRelations(ConvertsRelation.class)) {
+                               org.splat.dal.bo.som.File attach = ((ConvertsRelation) r)
+                                               .getTo();
+                               dates.put(attach.getIndex(), attach.getDate());
+                       }
+               }
+
                // Prepare test data for checkin
                // Checkin only two first steps (geom and mesh)
                for (StepDTO step : steps) {
@@ -401,6 +409,7 @@ public class TestScenarioService extends BaseTest {
                aScen = _scenarioDAO.get(scenarioId);
                Assert.assertFalse(aScen.isCheckedout(),
                                "Scenario is still marked as checked out after checkin.");
+               boolean modifDatesChecked = false;
                // Check that new document versions are created for checked in documents
                for (StepDTO step : stepsToCheckin) {
                        for (DocumentDTO docDTO : step.getDocs()) {
@@ -440,18 +449,21 @@ public class TestScenarioService extends BaseTest {
                                                Assert.assertFalse(aScen.publishes(prevDoc));
                                                // Check that presentation of the previous version is removed
                                                checkFiles(docDTO, newPub);
-                                               
+
                                                // Formats of files are new if they are according to the document's type on the study step
                                                if ("py".equals(prevDoc.getFormat())
-                                                               && "geometry".equals(prevDoc.getType().getName())) {
-                                                       Assert.assertEquals(newPub.value().getFormat(), "brep");
-                                                       Assert.assertEquals(newPub.getSourceFile().getFormat(),
+                                                               && "geometry".equals(prevDoc.getType()
+                                                                               .getName())) {
+                                                       Assert.assertEquals(newPub.value().getFormat(),
                                                                        "brep");
+                                                       Assert.assertEquals(newPub.getSourceFile()
+                                                                       .getFormat(), "brep");
                                                        Assert.assertEquals(newPub.getSourceFile()
                                                                        .getRelativePath().substring(
                                                                                        newPub.getSourceFile()
-                                                                                                       .getRelativePath().lastIndexOf(
-                                                                                                                       '.') + 1), "brep");
+                                                                                                       .getRelativePath()
+                                                                                                       .lastIndexOf('.') + 1),
+                                                                       "brep");
                                                }
 
                                                // Check that uses relations are copied correctly
@@ -468,7 +480,8 @@ public class TestScenarioService extends BaseTest {
                                                                        if ((lastPub.value().getPreviousVersion() != null)
                                                                                        && (lastPub.value()
                                                                                                        .getPreviousVersion()
-                                                                                                       .getIndex() == used.getIndex())) {
+                                                                                                       .getIndex() == used
+                                                                                                       .getIndex())) {
                                                                                toBeUsed = lastPub;
                                                                                break;
                                                                        }
@@ -506,11 +519,33 @@ public class TestScenarioService extends BaseTest {
                                                Assert.assertTrue(attFile.asFile().exists(), "File "
                                                                + docDTO.getFiles().get(0).getPath()
                                                                + " attached to the document "
-                                                               + docDTO.getTitle() + "#" + docDTO.getId() + " doesn't exist");
-                                               LOG.debug("Source format: " + curDoc.getFormat() + ", new format: " + newFormat);
+                                                               + docDTO.getTitle() + "#" + docDTO.getId()
+                                                               + " doesn't exist");
+                                               LOG.debug("Source format: " + curDoc.getFormat()
+                                                               + ", new format: " + newFormat);
+                                               // Check that attachment with the same format is not duplicated.
+                                               int attachNb = 0;
+                                               for (Relation conv : curDoc
+                                                               .getRelations(ConvertsRelation.class)) {
+                                                       if (newFormat.equals(((ConvertsRelation) conv)
+                                                                       .getTo().getFormat())) {
+                                                               attachNb++;
+                                                       }
+                                               }
+                                               Assert
+                                                               .assertEquals(attachNb, 1,
+                                                                               "Attachment with the same format must be only one.");
+
+                                               // Check that the attached file date is updated
+                                               if (dates.containsKey(attFile.getIndex())) {
+                                                       Assert
+                                                                       .assertTrue(attFile.getDate().compareTo(
+                                                                                       dates.get(attFile.getIndex())) > 0,
+                                                                                       "Attachment modification date is not updated.");
+                                                       modifDatesChecked = true;
+                                               }
                                        }
 
-
                                } else {
                                        // Check that new documents are created for new data
                                        boolean found = false;
@@ -563,6 +598,11 @@ public class TestScenarioService extends BaseTest {
                        }
                }
 
+               Assert
+                               .assertTrue(
+                                               modifDatesChecked,
+                                               "No modification date is checked because no files were attached when attachment with same extension already exists.");
+
                // ///////////////////////////////////////////////////////////
                // Call checkin method for a not existing id.
                try {
@@ -671,8 +711,7 @@ public class TestScenarioService extends BaseTest {
                                        for (FileDTO file : doc.getFiles()) {
                                                if (file.getPath().endsWith(format)
                                                                || (file.getPath().endsWith("py") && (format
-                                                                               .equals("brep") || format
-                                                                               .equals("med")))) {
+                                                                               .equals("brep") || format.equals("med")))) {
                                                        // Create a file in the download directory
                                                        docToCheckin.addFile(createDownloadedFile(userId,
                                                                        doc.getTitle() + "_result", format));
@@ -824,11 +863,10 @@ public class TestScenarioService extends BaseTest {
                                // <source-file>.brep
                                // <attached-file>.med
                                dprop.setName("document" + i++).setType(dtype);
-/*                             if (step.getNumber() > 3) {
-                                       dprop.setFormat("med");
-                               } else {
-*/                                     dprop.setFormat("py");
-//                             }
+                               /*
+                                * if (step.getNumber() > 3) { dprop.setFormat("med"); } else {
+                                */dprop.setFormat("py");
+                               // }
                                dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
                                Publication pub = createDoc(aScenario, aScStep, dprop, "med",
                                                false);