Salome HOME
Don't attach format to the file name when adding a document.
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestScenarioService.java
index 4b9aa4727024d07c21a94429ff0588e69e379b4a..7c8dbbcbc900ae7df1332c9cbbe8644427d587ed 100644 (file)
@@ -370,6 +370,7 @@ public class TestScenarioService extends BaseTest {
                // Do test checkin
                _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
 
+               _scenarioDAO.flush();
                // Check that scenario is no more marked as checked out
                aScen = _scenarioDAO.get(scenarioId);
                Assert.assertFalse(aScen.isCheckedout(),
@@ -650,10 +651,27 @@ public class TestScenarioService extends BaseTest {
        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;
+               return createDownloadedFile(userId, name + "." + format);
+       }
+
+       /**
+        * Create a file in the user's repository downloads directory.
+        * 
+        * @param userId
+        *            user id
+        * @param fname
+        *            file name
+        * @return created file DTO
+        * @throws IOException
+        *             if file creation failed
+        */
+       private FileDTO createDownloadedFile(final long userId, final String fname)
+                       throws IOException {
+               // Create a file in the download directory
+               String filePath = getDownloadPath(userId) + fname;
                FileWriter fw = new FileWriter(filePath);
-               fw.write("Simulation of " + name + "." + format
-                               + " file for checkin at " + new Date());
+               fw.write("Simulation of " + fname + " file for checkin at "
+                               + new Date());
                fw.close();
                return new FileDTO(filePath);
        }
@@ -758,6 +776,7 @@ public class TestScenarioService extends BaseTest {
                                } else {
                                        dprop.setFormat("py");
                                }
+                               dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
                                Publication pub = createDoc(aScenario, aScStep, dprop, "med",
                                                false);
                                if (usedPub != null) {
@@ -770,6 +789,7 @@ public class TestScenarioService extends BaseTest {
 
                                // Create another document with outdated publication
                                dprop.setName("document" + i++).setType(dtype).setFormat("py");
+                               dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
                                createDoc(aScenario, aScStep, dprop, "med", true);
 
                        }
@@ -870,6 +890,8 @@ public class TestScenarioService extends BaseTest {
                // document<i>: document type[0] - first type used on the step
                // <source-file>.brep
                // <attached-file>.med
+               createDownloadedFile(aScenario.getAuthor().getIndex(), dprop
+                               .getLocalPath());
                Publication pub = _stepService.createDocument(aScStep, dprop);
                Assert.assertNotNull(pub.getOwner(),
                                "The publication must be attached to the scenario.");
@@ -884,6 +906,10 @@ public class TestScenarioService extends BaseTest {
                ht.saveOrUpdate(pub);
 
                // Attach a file
+               createDownloadedFile(aScenario.getAuthor().getIndex(), dprop
+                               .getLocalPath().substring(0,
+                                               dprop.getLocalPath().lastIndexOf(".") - 1),
+                               attachedFileExt);
                ht.save(pub.value());
                ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));