Salome HOME
SaveOrUpdate is introduced in DAO and is used for user creation.
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestScenarioService.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   12 Oct 2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9 package test.splat.service;
10
11 import java.io.File;
12 import java.io.FileNotFoundException;
13 import java.io.FileWriter;
14 import java.io.IOException;
15 import java.sql.SQLException;
16 import java.util.ArrayList;
17 import java.util.Date;
18 import java.util.List;
19
20 import org.splat.dal.bo.kernel.User;
21 import org.splat.dal.bo.som.Document;
22 import org.splat.dal.bo.som.Document.Properties;
23 import org.splat.dal.bo.som.DocumentType;
24 import org.splat.dal.bo.som.Publication;
25 import org.splat.dal.bo.som.Scenario;
26 import org.splat.dal.bo.som.Study;
27 import org.splat.dal.dao.som.Database;
28 import org.splat.dal.dao.som.ScenarioDAO;
29 import org.splat.kernel.InvalidPropertyException;
30 import org.splat.kernel.MismatchException;
31 import org.splat.kernel.MissedPropertyException;
32 import org.splat.kernel.MultiplyDefinedException;
33 import org.splat.kernel.NotApplicableException;
34 import org.splat.log.AppLogger;
35 import org.splat.service.DocumentTypeService;
36 import org.splat.service.PublicationService;
37 import org.splat.service.ScenarioService;
38 import org.splat.service.StepService;
39 import org.splat.service.dto.DocumentDTO;
40 import org.splat.service.dto.FileDTO;
41 import org.splat.service.dto.StepDTO;
42 import org.splat.service.technical.ProjectSettingsService;
43 import org.splat.service.technical.ProjectSettingsService.Step;
44 import org.splat.service.technical.RepositoryService;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.beans.factory.annotation.Qualifier;
47 import org.springframework.orm.hibernate3.HibernateTemplate;
48 import org.testng.Assert;
49 import org.testng.annotations.Test;
50
51 import test.splat.common.BaseTest;
52
53 /**
54  * Test class for KnowledgeElementDAO.
55  * 
56  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
57  * 
58  */
59 public class TestScenarioService extends BaseTest {
60
61         /**
62          * Logger for the class.
63          */
64         private static final AppLogger LOG = AppLogger
65                         .getLogger(TestScenarioService.class);
66
67         /**
68          * The tested ScenarioService. Later injected by Spring.
69          */
70         @Autowired
71         @Qualifier("scenarioService")
72         private transient ScenarioService _scenarioService;
73
74         /**
75          * The RepositoryService. Later injected by Spring.
76          */
77         @Autowired
78         @Qualifier("repositoryService")
79         private transient RepositoryService _repositoryService;
80
81         /**
82          * The Scenario DAO. Later injected by Spring.
83          */
84         @Autowired
85         @Qualifier("scenarioDAO")
86         private transient ScenarioDAO _scenarioDAO;
87
88         /**
89          * The PublicationService. Later injected by Spring.
90          */
91         @Autowired
92         @Qualifier("publicationService")
93         private transient PublicationService _publicationService;
94
95         /**
96          * The StepService. Later injected by Spring.
97          */
98         @Autowired
99         @Qualifier("stepService")
100         private transient StepService _stepService;
101
102         /**
103          * The ProjectSettingsService. Later injected by Spring.
104          */
105         @Autowired
106         @Qualifier("projectSettings")
107         private transient ProjectSettingsService _projectSettings;
108
109         /**
110          * The DocumentTypeService. Later injected by Spring.
111          */
112         @Autowired
113         @Qualifier("documentTypeService")
114         private transient DocumentTypeService _documentTypeService;
115
116         /**
117          * Test of getting a scenario content for building siman-salome.conf.<BR>
118          * <B>Description :</B> <BR>
119          * <i>Create a scenario and try to get an info for it.</i><BR>
120          * <B>Action : </B><BR>
121          * <i>1. call the method for an existing scenario id.</i><BR>
122          * <i>2. call the method for a not existing scenario id.</i><BR>
123          * <B>Test data : </B><BR>
124          * <i>no input parameters</i><BR>
125          * <i>no input parameters</i><BR>
126          * 
127          * <B>Outcome results:</B><BR>
128          * <i>
129          * <ul>
130          * <li>result DTO must contain list of all documents and files<BR>
131          * </li>
132          * <li>Exception is thrown<BR>
133          * </li>
134          * </ul>
135          * </i>
136          * 
137          * @throws InvalidPropertyException
138          *             if an invalid property is used when creating objects
139          * @throws MultiplyDefinedException
140          *             when trying to create an object with already existing id
141          * @throws MissedPropertyException
142          *             if a mandatory property is not defined for an object to be created
143          * @throws IOException
144          *             if scenario creation is failed
145          * @throws SQLException
146          *             if scenario creation is failed
147          */
148         @Test
149         public void testGetScenarioInfo() throws InvalidPropertyException,
150                         MissedPropertyException, MultiplyDefinedException, IOException,
151                         SQLException {
152                 LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
153                 long scenarioId = createScenario();
154                 // Call DAO's create method for a good transient knowledge element.
155                 List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
156                 Assert.assertNotNull(steps, "List of steps must not be null.");
157                 Assert.assertTrue(steps.size() > 0, "No steps are read.");
158
159                 List<Step> projSteps = _projectSettings.getStepsOf(Scenario.class);
160                 Assert.assertEquals(steps.size(), projSteps.size(),
161                                 "Not all steps are listed.");
162                 int docIndex = 0;
163                 for (StepDTO step : steps) {
164                         LOG.debug("check the step " + step.getNumber() + ":\n" + step);
165                         Assert.assertNotNull(step, "Step DTO must not be null.");
166                         Assert.assertNotNull(step.getKey(), "Step name must not be null.");
167                         Assert.assertFalse(step.getKey().isEmpty(),
168                                         "Step name must not empty.");
169                         Assert.assertTrue(step.getNumber() > 0,
170                                         "Step number must be positive integer.");
171                         Assert.assertNotNull(step.getDocs(),
172                                         "Step documents list must not be null.");
173
174                         Step aProjStep = null;
175                         for (Step projStep : projSteps) {
176                                 if (projStep.getNumber() == step.getNumber()) {
177                                         aProjStep = projStep;
178                                         break;
179                                 }
180                         }
181
182                         List<DocumentType> dtypes = _documentTypeService
183                                         .selectTypesOf(aProjStep);
184                         for (DocumentType dtype : dtypes) {
185                                 Assert.assertTrue(step.getDocs().size() > 0,
186                                                 "Step documents list must not be empty.");
187                                 String docName = "document" + docIndex;
188                                 for (DocumentDTO doc : step.getDocs()) {
189                                         if (docName.equals(doc.getTitle())) {
190                                                 Assert.assertTrue(doc.getId() > 0,
191                                                                 "Document id must be positive integer.");
192                                                 Assert.assertEquals(doc.getTitle(), docName);
193                                                 Assert.assertNotNull(doc.getFiles(),
194                                                                 "Document files list must not be null.");
195                                                 Assert
196                                                                 .assertTrue(doc.getFiles().size() > 1,
197                                                                                 "Document must have more then 1 attached file.");
198
199                                                 for (FileDTO file : doc.getFiles()) {
200                                                         Assert.assertNotNull(file.getPath(),
201                                                                         "File path must not be null.");
202                                                         Assert.assertFalse(file.getPath().isEmpty(),
203                                                                         "File path must not be empty.");
204                                                         /*
205                                                          * <mappings> <document type="geometry"> <import format="brep"/> <!-- Result Shape --> </document> <document
206                                                          * type="model"> <import format="med"/> <!-- Result mesh without input parameters --> </document> <document
207                                                          * type="loads"> <import format="c3m"/> <!-- Input data created interactively --> </document> <document
208                                                          * type="results"> <import format="med"/> <!-- Calculation results source file --> </document> </mappings>
209                                                          */
210                                                         // Check state and processing instruction
211                                                         String fileFormat = file.getPath().substring(
212                                                                         file.getPath().lastIndexOf('.') + 1);
213                                                         /*
214                                                          * if (_projectSettings.doImport(dtype.getName(), fileFormat)) { Assert.assertTrue(file.isResult(), "The file
215                                                          * must be a result file."); } else { Assert.assertFalse(file.isResult(), "The file must be a source file."); }
216                                                          */if ((docIndex % 2) == 0) { // New
217                                                                 Assert.assertEquals(file.getState(), 'Y',
218                                                                                 "File state must be actual ('Y').");
219                                                                 if (_projectSettings.doImport(dtype.getName(),
220                                                                                 fileFormat)) {
221                                                                         Assert.assertEquals(file.getProcessing(),
222                                                                                         "file-import",
223                                                                                         "File must be imported.");
224                                                                 } else {
225                                                                         Assert.assertEquals(file.getProcessing(),
226                                                                                         "file-download",
227                                                                                         "File must be downloaded.");
228                                                                 }
229                                                         } else { // Outdated
230                                                                 Assert.assertEquals(file.getState(), 'O',
231                                                                                 "File state must be actual ('O').");
232                                                                 Assert
233                                                                                 .assertEquals(file.getProcessing(),
234                                                                                                 "file-download",
235                                                                                                 "Outdated document should not be imported but downloaded.");
236                                                         }
237                                                 }
238                                         }
239                                 }
240                                 docIndex++;
241                         }
242                 }
243
244                 // Call DAO's get method for a not existing id.
245                 try {
246                         steps = _scenarioService.getScenarioInfo(-1L);
247                         // getHibernateTemplate().flush();
248                         Assert
249                                         .fail("Getting an object with not existing id must be failed.");
250                 } catch (Exception e) {
251                         LOG.debug("Expected exception is thrown: "
252                                         + e.getClass().getSimpleName() + ": " + e.getMessage());
253                 }
254                 LOG.debug(">>>>> END testGetScenarioInfo()");
255         }
256
257         /**
258          * Test check-in scenario operation to be performed after SALOME session.<BR>
259          * <B>Description :</B> <BR>
260          * <i>Create a scenario and try to check-in it with some simulated SALOME results data.<BR>
261          * After check-in verify following points:
262          * <ul>
263          * <li>scenario is no more marked as checked out</li>
264          * <li>new document versions are created for checked in documents</li>
265          * <li>presentation of the previous version is removed</li>
266          * <li>uses relations are copied correctly</li>
267          * <li>files are moved correctly</li>
268          * <li>new documents are created for new data</li>
269          * <li>uses relations are created correctly</li>
270          * <li>files are moved correctly</li>
271          * </ul>
272          * </i><BR>
273          * <B>Action : </B><BR>
274          * <i>1. call the method for an existing scenario id.</i><BR>
275          * <i>2. call the method for a not existing scenario id.</i><BR>
276          * <B>Test data : </B><BR>
277          * <i>no input parameters</i><BR>
278          * <i>no input parameters</i><BR>
279          * 
280          * <B>Outcome results:</B><BR>
281          * <i>
282          * <ul>
283          * <li>New version of existing documents must be created and new documents must be imported for documents with zero id. Correct
284          * relations must be created.<BR>
285          * </li>
286          * <li>Exception is thrown<BR>
287          * </li>
288          * </ul>
289          * </i>
290          * 
291          * @throws InvalidPropertyException
292          *             if an invalid property is used when creating objects
293          * @throws MultiplyDefinedException
294          *             when trying to create an object with already existing id
295          * @throws MissedPropertyException
296          *             if a mandatory property is not defined for an object to be created
297          * @throws IOException
298          *             if scenario creation is failed
299          * @throws SQLException
300          *             if scenario creation is failed
301          * @throws NotApplicableException
302          *             if checkin failed
303          * @throws MismatchException
304          *             if checkin failed
305          */
306         @Test(groups = {"checkin", "sevice", "functional", "business"})
307         public void testCheckin() throws InvalidPropertyException,
308                         MissedPropertyException, MultiplyDefinedException, IOException,
309                         SQLException, MismatchException, NotApplicableException {
310                 LOG.debug(">>>>> BEGIN testCheckin()");
311                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
312                 _projectSettings.configure(ClassLoader
313                                 .getSystemResource("test/som.xml").getPath());
314                 long scenarioId = createScenario();
315                 Scenario aScen = _scenarioDAO.get(scenarioId);
316                 User user = aScen.getAuthor();
317                 long userId = user.getIndex();
318
319                 // ////////////////////////////////////////////////////////
320                 // Call checkin method for good prepared transient data.
321
322                 // Simulate checkout
323                 List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
324                 _scenarioService.checkout(aScen, user);
325
326                 // Prepare test data for checkin
327                 // Checkin only two first steps (geom and mesh)
328                 List<StepDTO> stepsToCheckin = new ArrayList<StepDTO>();
329                 for (StepDTO step : steps) {
330                         // Prepare GEOM: checkin actual brep
331                         StepDTO stepToCheckin = createDocDTOForModule(null, "GEOM", "brep",
332                                         userId, step, stepsToCheckin);
333                         createDocDTOForModule(stepToCheckin, "SMESH", "med", userId, step,
334                                         stepsToCheckin);
335                 }
336                 // Do test checkin
337                 _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
338
339                 // Check that scenario is no more marked as checked out
340                 aScen = _scenarioDAO.get(scenarioId);
341                 Assert.assertFalse(aScen.isCheckedout(),
342                                 "Scenario is still marked as checked out after checkin.");
343                 // Check that new document versions are created for checked in documents
344                 for (StepDTO step : stepsToCheckin) {
345                         for (DocumentDTO docDTO : step.getDocs()) {
346                                 if ((docDTO.getId() != 0) && (docDTO.getId() != null)) {
347                                         boolean found = false;
348                                         Document prevDoc = null;
349                                         Publication newPub = null;
350                                         for (Publication pub : aScen.getDocums()) {
351                                                 prevDoc = pub.value().getPreviousVersion();
352                                                 if (prevDoc != null) {
353                                                         found = (prevDoc.getIndex() == docDTO.getId());
354                                                         if (found) { // Found next published version of the checked in document
355                                                                 newPub = pub;
356                                                                 break;
357                                                         }
358                                                 }
359                                         }
360                                         Assert.assertTrue(found,
361                                                         "New version of the existing checked in document \""
362                                                                         + docDTO.getTitle() + "\" (id="
363                                                                         + docDTO.getId()
364                                                                         + ") is not found in the scenario.");
365                                         // Check that presentation of the previous version is removed
366                                         Assert.assertFalse(aScen.publishes(prevDoc));
367                                         // Check that files are moved correctly
368                                         for (int j = 0; j < docDTO.getFiles().size(); j++) {
369                                                 FileDTO fileDTO = docDTO.getFiles().get(j);
370                                                 Assert
371                                                                 .assertFalse(
372                                                                                 new File(fileDTO.getPath()).exists(),
373                                                                                 "File"
374                                                                                                 + fileDTO.getPath()
375                                                                                                 + " was not removed from downloads directory.");
376                                                 String format = fileDTO.getPath().substring(
377                                                                 fileDTO.getPath().lastIndexOf('.') + 1);
378                                         }
379                                         // Check file by its internal content
380                                         // Check that uses relations are copied correctly
381
382                                 } else {
383                                         // Check that new documents are created for new data
384                                         boolean found = false;
385                                         Publication newPub = null;
386                                         for (Publication pub : aScen.getDocums()) {
387                                                 if (pub.value().getPreviousVersion() == null) {
388                                                         found = (docDTO.getTitle().equals(pub.value()
389                                                                         .getTitle()));
390                                                         if (found) { // Found next published version of the checked in document
391                                                                 newPub = pub;
392                                                                 break;
393                                                         }
394                                                 }
395                                         }
396                                         Assert.assertTrue(found,
397                                                         "New document is not created for checked in document \""
398                                                                         + docDTO.getTitle() + "\".");
399                                         // Check that uses relations are created correctly
400                                         // Check that files are moved correctly
401
402                                 }
403                         }
404                 }
405
406                 // ///////////////////////////////////////////////////////////
407                 // Call checkin method for a not existing id.
408                 try {
409                         _scenarioService.checkin(-1, userId, stepsToCheckin);
410                         Assert
411                                         .fail("Check in for scenario with not existing id must be failed.");
412                 } catch (Exception e) {
413                         LOG.debug("Expected exception is thrown: "
414                                         + e.getClass().getSimpleName() + ": " + e.getMessage());
415                 }
416
417                 LOG.debug(">>>>> END testCheckin()");
418         }
419
420         /**
421          * Prepare a document with a file for check-in.
422          * 
423          * @param stepTo
424          *            step DTO with data for check-in
425          * @param module
426          *            SALOME module name
427          * @param format
428          *            file extension
429          * @param userId
430          *            download directory
431          * @param stepFrom
432          *            checked out stepDTO
433          * @param stepsToCheckin
434          *            DTO for check-in
435          * @throws IOException
436          *             if file creation failed
437          * @return step DTO with data prepared for check-in (stepTo or new if stepTo is null)
438          */
439         private StepDTO createDocDTOForModule(final StepDTO stepTo,
440                         final String module, final String format, final long userId,
441                         final StepDTO stepFrom, final List<StepDTO> stepsToCheckin)
442                         throws IOException {
443                 StepDTO stepToCheckin = stepTo;
444                 if (stepToCheckin == null) {
445                         stepToCheckin = new StepDTO();
446                 }
447                 if (module.equals(stepFrom.getModule())) {
448                         stepsToCheckin.add(stepToCheckin);
449                         stepToCheckin.setNumber(stepFrom.getNumber());
450                         for (DocumentDTO doc : stepFrom.getDocs()) {
451                                 if (doc.getFiles().get(0).getState() != 'O') {
452                                         DocumentDTO docToCheckin = stepToCheckin.addDoc(
453                                                         doc.getId(), doc.getTitle());
454                                         for (FileDTO file : doc.getFiles()) {
455                                                 if (file.getPath().endsWith(format)) {
456                                                         // Create a file in the download directory
457                                                         docToCheckin.addFile(createDownloadedFile(userId,
458                                                                         doc.getTitle() + "_result", format));
459                                                 }
460                                         }
461                                 }
462                         }
463                         // Prepare new data
464                         stepToCheckin.addDoc(0, "newdoc" + stepFrom.getNumber()).addFile(
465                                         createDownloadedFile(userId, "newdoc"
466                                                         + stepFrom.getNumber(), "brep"));
467                 }
468                 return stepToCheckin;
469         }
470
471         /**
472          * Create a file in the user's repository downloads directory.
473          * 
474          * @param userId
475          *            user id
476          * @param name
477          *            file name
478          * @param format
479          *            file extension
480          * @return created file DTO
481          * @throws IOException
482          *             if file creation failed
483          */
484         private FileDTO createDownloadedFile(final long userId, final String name,
485                         final String format) throws IOException {
486                 // Create a file in the download directory
487                 String filePath = getDownloadPath(userId) + name + "." + format;
488                 FileWriter fw = new FileWriter(filePath);
489                 fw.write("Simulation of " + name + "." + format
490                                 + " file for checkin at " + new Date());
491                 fw.close();
492                 return new FileDTO(filePath);
493         }
494
495         /**
496          * Get path to the user's downloads directory. The directory is created if it is not exist yet.
497          * 
498          * @param userId
499          *            user id
500          * @return absolute path to downloads directory followed by slash
501          */
502         private String getDownloadPath(final long userId) {
503                 // Prepare download directory
504                 File tmpDir = _repositoryService.getDownloadDirectory(userId);
505                 if (!tmpDir.exists()) {
506                         Assert.assertTrue(tmpDir.mkdir(),
507                                         "Can't create temporary directory: "
508                                                         + tmpDir.getAbsolutePath());
509                 }
510
511                 return tmpDir.getAbsolutePath() + "/";
512         }
513
514         /**
515          * Create a persistent scenario for tests.
516          * 
517          * @return a persistent scenario
518          * @throws InvalidPropertyException
519          *             if an invalid property is used when creating objects
520          * @throws MultiplyDefinedException
521          *             when trying to create an object with already existing id
522          * @throws MissedPropertyException
523          *             if a mandatory property is not defined for an object to be created
524          * @throws IOException
525          *             if document creation is failed
526          * @throws SQLException
527          *             if project settings loading is failed
528          */
529         private long createScenario() throws InvalidPropertyException,
530                         MissedPropertyException, MultiplyDefinedException, IOException,
531                         SQLException {
532                 // Create a scenario for tests
533                 HibernateTemplate ht = getHibernateTemplate();
534
535                 Database.getInstance().reset();
536                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
537                 // Load workflow customization
538                 try {
539                         _projectSettings.configure(ClassLoader.getSystemResource(
540                                         "test/som.xml").getPath());
541                 } catch (FileNotFoundException e) {
542                         Assert.fail("Can't find som.xml: ", e);
543                 }
544                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
545                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
546
547                 // Create a test user
548                 User.Properties uprop = new User.Properties();
549                 uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
550                                 .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
551                                 .addRole("TST_user").setMailAddress(
552                                                 "noreply@salome-platform.org");
553                 uprop.disableCheck();
554                 User anAuthor = new User(uprop);
555                 ht.saveOrUpdate(anAuthor);
556
557                 // Create a test study
558                 Study.Properties stprops = new Study.Properties().setReference(
559                                 "TST_SID_01").setTitle("TST_Study").setManager(anAuthor);
560                 Study aStudy = new Study(stprops);
561                 ht.saveOrUpdate(aStudy);
562
563                 // Create a test scenario
564                 Scenario.Properties sprops = new Scenario.Properties().setTitle(
565                                 "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy);
566                 Scenario aScenario = new Scenario(sprops);
567                 aStudy.getScenariiList().add(aScenario);
568                 ht.saveOrUpdate(anAuthor);
569                 ht.saveOrUpdate(aStudy);
570                 ht.saveOrUpdate(aScenario);
571
572                 // Create documents for each scenario step
573                 Document.Properties dprop = new Document.Properties().setAuthor(
574                                 anAuthor).setDate(new Date());
575                 int i = 0;
576                 for (Step step : steps) {
577                         LOG.debug("Create scenario step: " + i);
578
579                         org.splat.som.Step aScStep = new org.splat.som.Step(step, aScenario);
580                         List<DocumentType> dtypes = _documentTypeService
581                                         .selectTypesOf(step);
582                         for (DocumentType dtype : dtypes) {
583                                 // Create a document published in the scenario
584                                 // document<i>: document type[0] - first type used on the step
585                                 // <source-file>.brep
586                                 // <attached-file>.med
587                                 dprop.setName("document" + i++).setType(dtype);
588                                 if (step.getNumber() > 3) {
589                                         dprop.setFormat("med");
590                                 } else {
591                                         dprop.setFormat("brep");
592                                 }
593                                 createDoc(aScenario, aScStep, dprop, "med", false);
594
595                                 // Create another document with outdated publication
596                                 dprop.setName("document" + i++).setType(dtype)
597                                                 .setFormat("brep");
598                                 createDoc(aScenario, aScStep, dprop, "med", true);
599
600                         }
601                         if (dtypes.size() <= 0) {
602                                 LOG.debug("No document types are found for scenario step " + i);
603                         }
604                 }
605
606                 // Check that the scenario and its documents have been created correctly.
607
608                 Assert.assertNotNull(ht.find("from Document"),
609                                 "No documents in the database.");
610                 Assert.assertTrue(ht.find("from Document").size() > 0,
611                                 "No documents in the database.");
612
613                 Assert.assertNotNull(ht.find("from Publication where owner="
614                                 + aScenario.getIndex()), "No publications in the database.");
615                 Assert.assertTrue(
616                                 ht.find("from Publication where owner=" + aScenario.getIndex())
617                                                 .size() > 0, "No publications in the database.");
618
619                 for (Publication p : (List<Publication>) ht
620                                 .find("from Publication where owner=" + aScenario.getIndex())) {
621                         LOG.debug("Publication found: [id=" + p.getIndex() + ", owner="
622                                         + p.getOwner().getIndex() + ", doc=" + p.value().getIndex()
623                                         + "]");
624                         Assert.assertEquals(p.getOwner().getIndex(), aScenario.getIndex(),
625                                         "The publication was not attached to the scenario.");
626                 }
627
628                 // Remove the scenario from the current hibernate session.
629                 ht.evict(aScenario);
630                 // Check that the scenario is created in the database.
631                 Scenario aScen = ht.load(Scenario.class, aScenario.getIndex());
632                 Assert.assertNotNull(aScen, "Scenario was not saved in the database.");
633                 Assert.assertTrue(aScen.getDocums().size() > 0,
634                                 "No publications in the scenario.");
635
636                 Assert.assertTrue(i > 0,
637                                 "More then one document must be in the database");
638
639                 return aScenario.getIndex();
640         }
641
642         /**
643          * Create a document published in the scenario. <BR>
644          * document:<BR>
645          * document type[0] - first type used on the step <BR>
646          * &lt;source-file&gt;.brep <BR>
647          * &lt;attached-file&gt;.med
648          * 
649          * @param aScenario
650          *            the scenario to add the document to
651          * @param aScStep
652          *            scenario step where the document to be published
653          * @param dprop
654          *            document properties
655          * @param attachedFileExt
656          *            extension of the secon attached (exported) file
657          * @param isOutdated
658          *            outdated document flag
659          * @return the publication of the created document
660          * @throws IOException
661          * @throws MultiplyDefinedException
662          * @throws InvalidPropertyException
663          * @throws MissedPropertyException
664          */
665         private Publication createDoc(final Scenario aScenario,
666                         final org.splat.som.Step aScStep, final Properties dprop,
667                         final String attachedFileExt, final boolean isOutdated)
668                         throws MissedPropertyException, InvalidPropertyException,
669                         MultiplyDefinedException, IOException {
670                 // Create a document published in the scenario
671                 // document<i>: document type[0] - first type used on the step
672                 // <source-file>.brep
673                 // <attached-file>.med
674                 Publication pub = _stepService.createDocument(aScStep, dprop);
675                 Assert.assertNotNull(pub.getOwner(),
676                                 "The publication must be attached to the scenario.");
677                 Assert.assertEquals(pub.getOwner().getIndex(), aScenario.getIndex(),
678                                 "The publication was not attached to the scenario.");
679
680                 if (isOutdated) {
681                         pub.setIsnew('O');
682                 }
683                 aScenario.add(pub);
684                 HibernateTemplate ht = getHibernateTemplate();
685                 ht.saveOrUpdate(pub);
686
687                 // Attach a file
688                 ht.save(pub.value());
689                 ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));
690
691                 return pub;
692         }
693 }