Salome HOME
Unit test for checkin is ammended for testing the case with empty input list of steps.
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestProjectSettingsService.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.FileNotFoundException;
12 import java.io.IOException;
13 import java.sql.SQLException;
14 import java.util.List;
15
16 import org.splat.dal.bo.som.KnowledgeElementType;
17 import org.splat.dal.bo.som.Scenario;
18 import org.splat.dal.bo.som.SimulationContextType;
19 import org.splat.dal.dao.som.Database;
20 import org.splat.log.AppLogger;
21 import org.splat.service.DocumentTypeService;
22 import org.splat.service.KnowledgeElementTypeService;
23 import org.splat.service.SimulationContextService;
24 import org.splat.service.technical.ProjectSettingsService;
25 import org.splat.service.technical.ProjectSettingsService.Step;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Qualifier;
28 import org.springframework.dao.DuplicateKeyException;
29 import org.testng.Assert;
30 import org.testng.annotations.Test;
31
32 import test.splat.common.BaseTest;
33
34 /**
35  * Test class for ProjectService.
36  * 
37  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
38  * 
39  */
40 public class TestProjectSettingsService extends BaseTest {
41
42         /**
43          * Logger for the class.
44          */
45         private static final AppLogger LOG = AppLogger
46                         .getLogger(TestProjectSettingsService.class);
47
48         /**
49          * The ProjectSettingsService. Later injected by Spring.
50          */
51         @Autowired
52         @Qualifier("projectSettings")
53         private transient ProjectSettingsService _projectSettings;
54
55         /**
56          * The DocumentTypeService. Later injected by Spring.
57          */
58         @Autowired
59         @Qualifier("documentTypeService")
60         private transient DocumentTypeService _documentTypeService;
61
62         /**
63          * The KnowledgeElementTypeService. Later injected by Spring.
64          */
65         @Autowired
66         @Qualifier("knowledgeElementTypeService")
67         private transient KnowledgeElementTypeService _knowledgeElementTypeService;
68
69         /**
70          * The DocumentTypeService. Later injected by Spring.
71          */
72         @Autowired
73         @Qualifier("simulationContextService")
74         private transient SimulationContextService _simulationContextService;
75         
76         /**
77          * Test of loading document mappings to file formats from customization XML file.<BR>
78          * <B>Description :</B> <BR>
79          * <i>Load customization and check the result.</i><BR>
80          * <B>Action : </B><BR>
81          * <i>1. call the method for som.xml</i><BR>
82          * <i>2. call the method for a xml without mappings.</i><BR>
83          * <i>3. call the method for a not existing file.</i><BR>
84          * <B>Test data : </B><BR>
85          * <i>test/som.xml</i><BR>
86          * <i>test/som-without-mappings.xml</i><BR>
87          * <i>not existing xxx.xml</i><BR>
88          * 
89          * <B>Outcome results:</B><BR>
90          * <i>
91          * <ul>
92          * <li>doImport() must return true for mapped formats<BR>
93          * </li>
94          * <li>doImport() must always return false<BR>
95          * </li>
96          * <li>Exception is thrown<BR>
97          * </li>
98          * </ul>
99          * </i>
100          * 
101          * @throws IOException
102          *             if configuration loading is failed
103          * @throws SQLException
104          *             if configuration loading is failed
105          */
106         @Test
107         public void testLoadMappings() throws IOException, SQLException {
108                 LOG.debug(">>>>> BEGIN testLoadMappings()()");
109                 startNestedTransaction();
110                 // ////// Load good workflow customization
111                 /*
112                  * geometry: brep model: med loads: c3m results: med
113                  */
114                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
115                 try {
116                         _projectSettings.configure(ClassLoader.getSystemResource(
117                                         "test/som.xml").getPath());
118                 } catch (FileNotFoundException e) {
119                         Assert.fail("Can't find configuration file: ", e);
120                 }
121                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
122                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
123                 Assert.assertTrue(_projectSettings.doImport("geometry", "brep"));
124                 Assert.assertTrue(_projectSettings.doImport("model", "med"));
125                 Assert.assertTrue(_projectSettings.doImport("loads", "c3m"));
126                 Assert.assertTrue(_projectSettings.doImport("results", "med"));
127
128                 // ////// Load workflow customization with empty mappings
129                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
130                 try {
131                         _projectSettings.configure(ClassLoader.getSystemResource(
132                                         "test/som-without-mappings.xml").getPath());
133                 } catch (FileNotFoundException e) {
134                         Assert.fail("Can't find configuration file: ", e);
135                 }
136                 steps = _projectSettings.getStepsOf(Scenario.class);
137                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
138                 Assert.assertFalse(_projectSettings.doImport("geometry", "brep"));
139                 Assert.assertFalse(_projectSettings.doImport("model", "med"));
140                 Assert.assertFalse(_projectSettings.doImport("loads", "c3m"));
141                 Assert.assertFalse(_projectSettings.doImport("results", "med"));
142
143                 // ////// Load workflow customization from not existing file
144                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
145                 try {
146                         _projectSettings.configure(ClassLoader.getSystemResource("/")
147                                         .getPath()
148                                         + "test/xxx.xml");
149                         Assert
150                                         .fail("Customization loading must fail for not existing configuration file.");
151                 } catch (FileNotFoundException e) {
152                         LOG.debug("Configuration file must not be found.", e);
153                 }
154
155                 rollbackNestedTransaction();
156                 LOG.debug(">>>>> END testLoadMappings()()");
157         }
158
159         /**
160          * Test of loading file formats mappings to document types from customization XML file.<BR>
161          * <B>Description :</B> <BR>
162          * <i>Load customization and check the result.</i><BR>
163          * <B>Action : </B><BR>
164          * <i>1. call the method for som.xml</i><BR>
165          * <i>2. call the method for a xml without mappings.</i><BR>
166          * <i>3. call the method for a not existing file.</i><BR>
167          * <B>Test data : </B><BR>
168          * <i>test/som.xml</i><BR>
169          * <i>test/som-without-mappings.xml</i><BR>
170          * <i>not existing xxx.xml</i><BR>
171          * 
172          * <B>Outcome results:</B><BR>
173          * <i>
174          * <ul>
175          * <li>Following mappings must be loaded:<BR/>
176          * <ul>
177          * <li>step 1
178          * <ul>
179          * <li>pdf: requirements</li>
180          * <li>doc: specification</li>
181          * <!-- Microsoft Word 2003 and earlier -->
182          * <li>docx: specification</li>
183          * <!-- Microsoft Word 2007 and later -->
184          * <li>xml: specification</li>
185          * <!-- Microsoft Word 2007 Open XML -->
186          * </ul>
187          * </li>
188          * <li>step 2
189          * <ul>
190          * <li>doc: design</li>
191          * <li>docx: design</li>
192          * <li>xml: design</li>
193          * </ul>
194          * </li>
195          * <li>step 3
196          * <ul>
197          * <li>doc: memorandum</li>
198          * <li>docx: memorandum</li>
199          * <li>xml: memorandum</li>
200          * <li>sldprt: geometry</li>
201          * <!-- SolidWorks Part -->
202          * <li>sldasm: geometry</li>
203          * <!-- SolidWorks Assembly -->
204          * <li>part: geometry</li>
205          * <!-- GEOM Part -->
206          * <li>py: geometry</li>
207          * <!-- GEOM Python script -->
208          * </ul>
209          * </li>
210          * <li>step 4
211          * <ul>
212          * <li>doc: memorandum</li>
213          * <li>docx: memorandum</li>
214          * <li>xml: memorandum</li>
215          * <li>med: model</li>
216          * <li>py: model</li>
217          * <!-- SMESH Python script -->
218          * </ul>
219          * </li>
220          * </ul>
221          * </li>
222          * <li>getDefaultDocumentType must always return null<BR>
223          * </li>
224          * <li>Exception is thrown<BR>
225          * </li>
226          * </ul>
227          * </i>
228          * 
229          * @throws IOException
230          *             if configuration loading is failed
231          * @throws SQLException
232          *             if configuration loading is failed
233          */
234         @Test
235         public void testLoadDefaultDocTypes() throws IOException, SQLException {
236                 LOG.debug(">>>>> BEGIN testLoadDefaultDocTypes()");
237                 startNestedTransaction();
238                 // ////// Load good workflow customization
239                 /*
240                  * geometry: brep model: med loads: c3m results: med
241                  */
242                 Database.getInstance().reset();
243                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
244                 try {
245                         _projectSettings.configure(ClassLoader.getSystemResource(
246                                         "test/som.xml").getPath());
247                 } catch (FileNotFoundException e) {
248                         Assert.fail("Can't find configuration file: ", e);
249                 }
250                 Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0,
251                                 "No document types are created.");
252                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
253                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
254
255                 for (Step step : steps) {
256                         List<String> defTypes = _projectSettings.getDefaultFormats(step);
257                         Assert.assertNotNull(defTypes,
258                                         "getDefaultFormats must always return not null list:");
259                         switch (step.getNumber()) {
260                                 case 1:
261                                         Assert.assertEquals(defTypes.size(), 4);
262                                         Assert.assertNotNull(_projectSettings
263                                                         .getDefaultDocumentType(step, "pdf"));
264                                         Assert.assertEquals(_projectSettings
265                                                         .getDefaultDocumentType(step, "pdf").getName(),
266                                                         "requirements");
267                                         Assert.assertNotNull(_projectSettings
268                                                         .getDefaultDocumentType(step, "doc"));
269                                         Assert.assertEquals(_projectSettings
270                                                         .getDefaultDocumentType(step, "doc").getName(),
271                                                         "specification");
272                                         Assert.assertNotNull(_projectSettings
273                                                         .getDefaultDocumentType(step, "docx"));
274                                         Assert.assertEquals(_projectSettings
275                                                         .getDefaultDocumentType(step, "docx").getName(),
276                                                         "specification");
277                                         Assert.assertNotNull(_projectSettings
278                                                         .getDefaultDocumentType(step, "xml"));
279                                         Assert.assertEquals(_projectSettings
280                                                         .getDefaultDocumentType(step, "xml").getName(),
281                                                         "specification");
282                                         break;
283                                 case 2:
284                                         Assert.assertEquals(defTypes.size(), 3);
285                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
286                                                         step, "pdf"));
287                                         Assert.assertNotNull(_projectSettings
288                                                         .getDefaultDocumentType(step, "doc"));
289                                         Assert.assertEquals(_projectSettings
290                                                         .getDefaultDocumentType(step, "doc").getName(),
291                                                         "design");
292                                         Assert.assertNotNull(_projectSettings
293                                                         .getDefaultDocumentType(step, "docx"));
294                                         Assert.assertEquals(_projectSettings
295                                                         .getDefaultDocumentType(step, "docx").getName(),
296                                                         "design");
297                                         Assert.assertNotNull(_projectSettings
298                                                         .getDefaultDocumentType(step, "xml"));
299                                         Assert.assertEquals(_projectSettings
300                                                         .getDefaultDocumentType(step, "xml").getName(),
301                                                         "design");
302                                         break;
303                                 case 3:
304                                         Assert.assertEquals(defTypes.size(), 8);
305                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
306                                                         step, "pdf"));
307                                         Assert.assertNotNull(_projectSettings
308                                                         .getDefaultDocumentType(step, "sldprt"));
309                                         Assert.assertEquals(_projectSettings
310                                                         .getDefaultDocumentType(step, "sldprt").getName(),
311                                                         "geometry");
312                                         Assert.assertNotNull(_projectSettings
313                                                         .getDefaultDocumentType(step, "sldasm"));
314                                         Assert.assertEquals(_projectSettings
315                                                         .getDefaultDocumentType(step, "sldasm").getName(),
316                                                         "geometry");
317                                         Assert.assertNotNull(_projectSettings
318                                                         .getDefaultDocumentType(step, "part"));
319                                         Assert.assertEquals(_projectSettings
320                                                         .getDefaultDocumentType(step, "part").getName(),
321                                                         "geometry");
322                                         Assert.assertNotNull(_projectSettings
323                                                         .getDefaultDocumentType(step, "py"));
324                                         Assert.assertEquals(_projectSettings
325                                                         .getDefaultDocumentType(step, "py").getName(),
326                                                         "geometry");
327                                         Assert.assertNotNull(_projectSettings
328                                                         .getDefaultDocumentType(step, "brep"));
329                                         Assert.assertEquals(_projectSettings
330                                                         .getDefaultDocumentType(step, "brep").getName(),
331                                                         "geometry");
332                                         Assert.assertNotNull(_projectSettings
333                                                         .getDefaultDocumentType(step, "doc"));
334                                         Assert.assertEquals(_projectSettings
335                                                         .getDefaultDocumentType(step, "doc").getName(),
336                                                         "memorandum");
337                                         Assert.assertNotNull(_projectSettings
338                                                         .getDefaultDocumentType(step, "docx"));
339                                         Assert.assertEquals(_projectSettings
340                                                         .getDefaultDocumentType(step, "docx").getName(),
341                                                         "memorandum");
342                                         Assert.assertNotNull(_projectSettings
343                                                         .getDefaultDocumentType(step, "xml"));
344                                         Assert.assertEquals(_projectSettings
345                                                         .getDefaultDocumentType(step, "xml").getName(),
346                                                         "memorandum");
347                                         break;
348                                 case 4:
349                                         Assert.assertEquals(defTypes.size(), 5);
350                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
351                                                         step, "pdf"));
352                                         Assert.assertNotNull(_projectSettings
353                                                         .getDefaultDocumentType(step, "med"));
354                                         Assert.assertEquals(_projectSettings
355                                                         .getDefaultDocumentType(step, "med").getName(),
356                                                         "model");
357                                         Assert.assertNotNull(_projectSettings
358                                                         .getDefaultDocumentType(step, "py"));
359                                         Assert.assertEquals(_projectSettings
360                                                         .getDefaultDocumentType(step, "py").getName(),
361                                                         "model");
362                                         Assert.assertNotNull(_projectSettings
363                                                         .getDefaultDocumentType(step, "doc"));
364                                         Assert.assertEquals(_projectSettings
365                                                         .getDefaultDocumentType(step, "doc").getName(),
366                                                         "memorandum");
367                                         Assert.assertNotNull(_projectSettings
368                                                         .getDefaultDocumentType(step, "docx"));
369                                         Assert.assertEquals(_projectSettings
370                                                         .getDefaultDocumentType(step, "docx").getName(),
371                                                         "memorandum");
372                                         Assert.assertNotNull(_projectSettings
373                                                         .getDefaultDocumentType(step, "xml"));
374                                         Assert.assertEquals(_projectSettings
375                                                         .getDefaultDocumentType(step, "xml").getName(),
376                                                         "memorandum");
377                                         break;
378                                 default:
379                                         Assert.assertEquals(defTypes.size(), 0);
380                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
381                                                         step, "pdf"));
382                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
383                                                         step, "doc"));
384                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
385                                                         step, "docx"));
386                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
387                                                         step, "xml"));
388                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
389                                                         step, "sldprt"));
390                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
391                                                         step, "sldasm"));
392                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
393                                                         step, "part"));
394                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
395                                                         step, "py"));
396                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
397                                                         step, "med"));
398                         }
399                 }
400
401                 // ////// Load workflow customization with empty mappings
402                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
403                 try {
404                         _projectSettings.configure(ClassLoader.getSystemResource(
405                                         "test/som-without-mappings.xml").getPath());
406                 } catch (FileNotFoundException e) {
407                         Assert.fail("Can't find configuration file: ", e);
408                 }
409                 steps = _projectSettings.getStepsOf(Scenario.class);
410                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
411                 for (Step step : steps) {
412                         List<String> defTypes = _projectSettings.getDefaultFormats(step);
413                         Assert.assertNotNull(defTypes,
414                                         "getDefaultFormats must always return not null list:");
415                         Assert.assertEquals(defTypes.size(), 0);
416                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
417                                         "pdf"));
418                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
419                                         "doc"));
420                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
421                                         "docx"));
422                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
423                                         "xml"));
424                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
425                                         "sldprt"));
426                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
427                                         "sldasm"));
428                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
429                                         "part"));
430                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
431                                         "py"));
432                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
433                                         "med"));
434                 }
435
436                 // ////// Load workflow customization from not existing file
437                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
438                 try {
439                         _projectSettings.configure(ClassLoader.getSystemResource("/")
440                                         .getPath()
441                                         + "test/xxx.xml");
442                         Assert
443                                         .fail("Customization loading must fail for not existing configuration file.");
444                 } catch (FileNotFoundException e) {
445                         LOG.debug("Configuration file must not be found.", e);
446                 }
447
448                 rollbackNestedTransaction();
449                 LOG.debug(">>>>> END testLoadDefaultDocTypes()");
450         }
451
452         /**
453          * Test of repeated database configuration method (dynamic reconfiguration).<BR>
454          * The problem - duplication of the simer user admin role. <B>Description :</B> <BR>
455          * <i>Load customization twice and check the result.</i><BR>
456          * <B>Action : </B><BR>
457          * <i>1. call the method twice for som.xml</i><BR>
458          * <B>Test data : </B><BR>
459          * <i>test/som.xml</i><BR>
460          * 
461          * <B>Outcome results:</B><BR>
462          * <i>
463          * <ul>
464          * <li>step must be configured<BR>
465          * </li>
466          * </ul>
467          * </i>
468          * 
469          * @throws IOException
470          *             if configuration loading is failed
471          * @throws SQLException
472          *             if configuration loading is failed
473          */
474         @Test
475         public void testConfigure() throws IOException, SQLException {
476                 LOG.debug(">>>>> BEGIN testConfigure()");
477                 startNestedTransaction();
478                 // ///////////////////////////////////////////////////
479                 // ////// Load good workflow customization
480                 getHibernateTemplate().clear();
481                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
482                 Database.getInstance().reset();
483                 try {
484                         _projectSettings.configure(ClassLoader.getSystemResource(
485                                         "test/som.xml").getPath());
486                 } catch (FileNotFoundException e) {
487                         Assert.fail("Can't find configuration file: ", e);
488                 }
489
490                 getHibernateTemplate().flush();
491                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
492                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
493                 KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
494                 Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
495                 SimulationContextType prodtype = _simulationContextService.selectType("product");
496                 Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
497
498                 // /////////////////////////////////////////////////////////
499                 // ////// Test reconfiguration attempt
500                 Database.getInstance().reset();
501                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
502                 try {
503                         _projectSettings.configure(ClassLoader.getSystemResource(
504                                         "test/som.xml").getPath());
505                 } catch (FileNotFoundException e) {
506                         Assert.fail("Can't find configuration file: ", e);
507                 }
508                 steps = _projectSettings.getStepsOf(Scenario.class);
509                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
510                 ucase = _knowledgeElementTypeService.selectType("usecase");
511                 Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
512                 prodtype = _simulationContextService.selectType("product");
513                 Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
514
515                 try {
516                         /*
517                          * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different
518                          * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested
519                          * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated
520                          * with the session: [org.splat.dal.bo.kernel.Role#simer] at
521                          * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at
522                          * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at
523                          * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at
524                          * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at
525                          * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
526                          */
527                         getHibernateTemplate().flush();
528                 } catch (DuplicateKeyException dke) {
529                         Assert.fail(
530                                         "User creation failed during the database reconfiguration: "
531                                                         + dke.getMessage(), dke);
532                 }
533
534                 rollbackNestedTransaction();
535                 LOG.debug(">>>>> END testConfigure()");
536         }
537
538         /**
539          * Test of repeated database configuration method (dynamic reconfiguration).<BR>
540          * The problem - duplication of the simer user admin role. <B>Description :</B> <BR>
541          * <i>Load customization twice and check the result.</i><BR>
542          * <B>Action : </B><BR>
543          * <i>1. call the method twice for som.xml</i><BR>
544          * <B>Test data : </B><BR>
545          * <i>test/som.xml</i><BR>
546          * 
547          * <B>Outcome results:</B><BR>
548          * <i>
549          * <ul>
550          * <li>step must be configured<BR>
551          * </li>
552          * </ul>
553          * </i>
554          * 
555          * @throws IOException
556          *             if configuration loading is failed
557          * @throws SQLException
558          *             if configuration loading is failed
559          */
560         @Test
561         public void testDatabaseInitialize() throws IOException, SQLException {
562                 LOG.debug(">>>>> BEGIN testDatabaseInitialize()");
563                 startNestedTransaction();
564                 // ///////////////////////////////////////////////////
565                 // ////// Load good workflow customization
566                 getHibernateTemplate().bulkUpdate("delete from Role");
567                 getHibernateTemplate().flush();
568                 Database.getInstance().reset();
569                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
570                 try {
571                         _projectSettings.configure(ClassLoader.getSystemResource(
572                                         "test/som.xml").getPath());
573                 } catch (FileNotFoundException e) {
574                         Assert.fail("Can't find configuration file: ", e);
575                 }
576                 try {
577                         /*
578                          * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different
579                          * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested
580                          * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated
581                          * with the session: [org.splat.dal.bo.kernel.Role#simer] at
582                          * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at
583                          * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at
584                          * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at
585                          * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at
586                          * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
587                          */
588                         Database.getInstance().initialize();
589                         getHibernateTemplate().flush();
590                 } catch (DuplicateKeyException dke) {
591                         Assert.fail(
592                                         "User creation failed during the database reconfiguration: "
593                                                         + dke.getMessage(), dke);
594                 }
595
596                 KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
597                 Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
598                 SimulationContextType prodtype = _simulationContextService.selectType("product");
599                 Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
600                 
601                 rollbackNestedTransaction();
602                 LOG.debug(">>>>> END testDatabaseInitialize()");
603         }
604 }