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 ddb34ac2c23a4361f052b6a02ce766b6c5ec1788..baddb0191ebade1c24ed126f47637be8797899b6 100644 (file)
@@ -27,7 +27,6 @@ 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;
-import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
@@ -38,6 +37,7 @@ 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;
@@ -458,6 +458,7 @@ public class TestScenarioService extends BaseTest {
                        createDocDTOForModule(stepToCheckin, "SMESH", "med", userId, step,
                                        stepsToCheckin);
                }
+               // /////////////////////////////////////////////////////////////////
                // Do test checkin
                _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
 
@@ -512,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
@@ -564,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
@@ -770,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));
+                                                       }
                                                }
                                        }
                                }
@@ -825,42 +850,6 @@ public class TestScenarioService extends BaseTest {
                return new FileDTO(filePath);
        }
 
-       /**
-        * Create a file.
-        * 
-        * @param fname
-        *            file name
-        * @throws IOException
-        *             if file creation failed
-        */
-       private void createFile(final String fname) throws IOException {
-               // Create a file in the download directory
-               LOG.debug("Create file: " + fname);
-               String filePath = fname;
-               FileWriter fw = new FileWriter(filePath);
-               fw.write("Simulation of " + fname + " data file at " + new Date());
-               fw.close();
-       }
-
-       /**
-        * 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.
         * 
@@ -1357,8 +1346,9 @@ public class TestScenarioService extends BaseTest {
                                        + doc.value().getReference() + "]" + " ["
                                        + doc.value().getRid() + "]");
                }
-               // // Add a version relations
-               // Publication pub31 = version(pub3);
+               // Add a version relations
+               Publication pub31 = version(pub3);
+               ht.flush();
                //
                // LOG.debug("pub31 version doc: " + pub31.value().getTitle() + " ["
                // + pub31.value().getReference() + "]" + " ["
@@ -1391,10 +1381,11 @@ public class TestScenarioService extends BaseTest {
                ht.flush();
 
                // Create a scenario document version
-               // Publication spub31 = version(spub3);
+               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);
@@ -1409,8 +1400,8 @@ public class TestScenarioService extends BaseTest {
                ht.saveOrUpdate(spub2.value());
                spub3.addDependency(spub2);
                ht.saveOrUpdate(spub3.value());
-               // spub31.addDependency(spub31);
-               // ht.saveOrUpdate(spub31.value());
+               spub31.addDependency(pub31);
+               ht.saveOrUpdate(spub31.value());
                ht.flush();
 
                // Create target study1
@@ -1494,72 +1485,6 @@ public class TestScenarioService extends BaseTest {
                LOG.debug(">>>>> END testCopyStudyContent()");
        }
 
-       /**
-        * Create a document and publish it in the project element.
-        * 
-        * @param aProjElem
-        *            the project element
-        * @param aStep
-        *            the project element step
-        * @param docname
-        *            document name
-        * @param dtype
-        *            document type
-        * @return publication of the created document
-        * @throws BusinessException
-        *             if document creation is failed
-        * @throws IOException
-        *             if file creation is failed
-        */
-       private Publication addDoc(final ProjectElement aProjElem,
-                       final org.splat.som.Step aStep, final String docname,
-                       final DocumentType dtype) throws BusinessException, IOException {
-               HibernateTemplate ht = getHibernateTemplate();
-               // Add documents to the study activity
-               Document.Properties dprop = new Document.Properties().setAuthor(
-                               aProjElem.getAuthor()).setDate(new Date()).setName(docname)
-                               .setType(dtype).setFormat("py");
-               dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
-               dprop.setStep(aStep.getStep());
-               Publication pub = _stepService.createDocument(aStep, dprop);
-               pub.setStep(aStep);
-               aProjElem.add(pub);
-               aStep.getDocuments().add(pub);
-               ht.saveOrUpdate(pub);
-               ht.save(pub.value());
-               // Add a converts relation
-               // Attach a med file
-               ht.saveOrUpdate(_publicationService.attach(pub, "med"));
-               String filepath = pub.getSourceFile().asFile().getAbsolutePath();
-               createFile(filepath);
-               createFile(filepath.substring(0, filepath.lastIndexOf(".")) + ".med");
-               return pub;
-       }
-
-       /**
-        * Create a new version of the document.
-        * 
-        * @param pub
-        *            the current document publication
-        * @return the new document version publication
-        * @throws IOException
-        *             if versioning is failed
-        * @throws BusinessException
-        *             if versioning is failed
-        */
-       private Publication version(final Publication pub)
-                       throws BusinessException, IOException {
-               Document.Properties dprop = new Document.Properties();
-               dprop.setDocument(pub.value(), pub.getStep().getStep());
-               Publication newpub = _stepService.versionDocument(pub.getStep(), pub,
-                               dprop);
-               pub.getOwner().getDocums().remove(pub);
-               pub.getStep().getDocuments().remove(pub);
-               pub.getOwner().add(newpub);
-               pub.getStep().getDocuments().add(newpub);
-               return newpub;
-       }
-
        /**
         * Test assigning a simulation context to a study.<BR>
         * <B>Description :</B> <BR>