]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java
Salome HOME
Fix for checkin: attach a new file to the same version if format differs from the...
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestScenarioService.java
index 7c8dbbcbc900ae7df1332c9cbbe8644427d587ed..1c486123b063568e997415d0c98871c1aee437a2 100644 (file)
@@ -382,6 +382,7 @@ public class TestScenarioService extends BaseTest {
                                if ((docDTO.getId() != 0) && (docDTO.getId() != null)) {
                                        boolean found = false;
                                        Document prevDoc = null;
+                                       Document curDoc = null;
                                        Publication newPub = null;
                                        for (Publication pub : aScen.getDocums()) {
                                                prevDoc = pub.value().getPreviousVersion();
@@ -392,71 +393,99 @@ public class TestScenarioService extends BaseTest {
                                                                break;
                                                        }
                                                }
+                                               if (pub.value().getIndex() == docDTO.getId()) {
+                                                       // Document version was not changed, old document is still published
+                                                       curDoc = pub.value();
+                                                       break;
+                                               }
                                        }
-                                       Assert.assertTrue(found,
-                                                       "New version of the existing checked in document \""
+                                       Assert.assertTrue(found || (curDoc != null),
+                                                       "New version or new attached file of the 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));
-                                       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(),
-                                                               "brep");
-                                               Assert.assertEquals(newPub.getSourceFile()
-                                                               .getRelativePath().substring(
-                                                                               newPub.getSourceFile()
-                                                                                               .getRelativePath().lastIndexOf(
-                                                                                                               '.') + 1), "brep");
-                                       }
+                                       // If previous version is found then the format must be the same
+                                       String newFormat = docDTO.getFiles().get(0).getPath()
+                                                       .substring(
+                                                                       docDTO.getFiles().get(0).getPath()
+                                                                                       .lastIndexOf('.') + 1);
+                                       if (found) {
+                                               Assert.assertEquals(prevDoc.getFormat(), newFormat,
+                                                               "Formats of versions must be same");
+                                               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(),
+                                                                       "brep");
+                                                       Assert.assertEquals(newPub.getSourceFile()
+                                                                       .getRelativePath().substring(
+                                                                                       newPub.getSourceFile()
+                                                                                                       .getRelativePath().lastIndexOf(
+                                                                                                                       '.') + 1), "brep");
+                                               }
 
-                                       // Check that uses relations are copied correctly
-
-                                       // 1. Get all uses relations of the previous document version
-                                       for (Relation rel : prevDoc
-                                                       .getRelations(UsesRelation.class)) {
-                                               Document used = ((UsesRelation) rel).getTo();
-                                               // 2.1. Get the latest version of the document published in this scenario
-                                               Publication toBeUsed = aScen.getPublication(used);
-                                               if (toBeUsed == null) {
-                                                       // Find the latest published version
-                                                       for (Publication lastPub : aScen.getDocums()) {
-                                                               if ((lastPub.value().getPreviousVersion() != null)
-                                                                               && (lastPub.value()
-                                                                                               .getPreviousVersion()
-                                                                                               .getIndex() == used.getIndex())) {
-                                                                       toBeUsed = lastPub;
-                                                                       break;
+                                               // Check that uses relations are copied correctly
+
+                                               // 1. Get all uses relations of the previous document version
+                                               for (Relation rel : prevDoc
+                                                               .getRelations(UsesRelation.class)) {
+                                                       Document used = ((UsesRelation) rel).getTo();
+                                                       // 2.1. Get the latest version of the document published in this scenario
+                                                       Publication toBeUsed = aScen.getPublication(used);
+                                                       if (toBeUsed == null) {
+                                                               // Find the latest published version
+                                                               for (Publication lastPub : aScen.getDocums()) {
+                                                                       if ((lastPub.value().getPreviousVersion() != null)
+                                                                                       && (lastPub.value()
+                                                                                                       .getPreviousVersion()
+                                                                                                       .getIndex() == used.getIndex())) {
+                                                                               toBeUsed = lastPub;
+                                                                               break;
+                                                                       }
                                                                }
                                                        }
+                                                       if ((toBeUsed != null) && (!toBeUsed.isOutdated())) {
+                                                               // 2.2. For each used document check that its latest not outdated version
+                                                               // is used by the new checked in document version.
+                                                               checkUsesRelation(newPub, toBeUsed);
+                                                       }
                                                }
-                                               if ((toBeUsed != null) && (!toBeUsed.isOutdated())) {
-                                                       // 2.2. For each used document check that its latest not outdated version
-                                                       // is used by the new checked in document version.
-                                                       checkUsesRelation(newPub, toBeUsed);
-                                               }
-                                       }
-                                       // 1. Get all usedBy relations of the previous document version
-                                       for (Relation rel : prevDoc
-                                                       .getRelations(UsedByRelation.class)) {
-                                               Document using = ((UsedByRelation) rel).getTo();
-                                               // Check that not checked in dependent documents became outdated
-                                               Publication usingPub = aScen.getPublication(using);
-                                               if (usingPub != null) { // if the document using the old version is still published
-                                                       Assert.assertTrue(usingPub.isOutdated(),
-                                                                       "Not checked in dependent document "
-                                                                                       + using.getTitle() + " ("
-                                                                                       + using.getType().getName()
-                                                                                       + ") must become outdated.");
-                                                       caseFound = true;
+                                               // 1. Get all usedBy relations of the previous document version
+                                               for (Relation rel : prevDoc
+                                                               .getRelations(UsedByRelation.class)) {
+                                                       Document using = ((UsedByRelation) rel).getTo();
+                                                       // Check that not checked in dependent documents became outdated
+                                                       Publication usingPub = aScen.getPublication(using);
+                                                       if (usingPub != null) { // if the document using the old version is still published
+                                                               Assert.assertTrue(usingPub.isOutdated(),
+                                                                               "Not checked in dependent document "
+                                                                                               + using.getTitle() + " ("
+                                                                                               + using.getType().getName()
+                                                                                               + ") must become outdated.");
+                                                               caseFound = true;
+                                                       }
                                                }
+                                       } else {
+                                               // Otherwise the new file format must differ from the previous one
+                                               // and the new file must be attached to the same document
+                                               org.splat.dal.bo.som.File attFile = curDoc
+                                                               .getAttachedFile(newFormat);
+                                               Assert.assertNotNull(attFile, "File "
+                                                               + docDTO.getFiles().get(0).getPath()
+                                                               + " must be attached to the document "
+                                                               + docDTO.getTitle() + "#" + docDTO.getId());
+                                               Assert.assertTrue(attFile.asFile().exists(), "File "
+                                                               + docDTO.getFiles().get(0).getPath()
+                                                               + " attached to the document "
+                                                               + docDTO.getTitle() + "#" + docDTO.getId() + " doesn't exist");
                                        }
 
+
                                } else {
                                        // Check that new documents are created for new data
                                        boolean found = false;