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