1 /*****************************************************************************
5 * Creation date 12 Oct 2012
8 *****************************************************************************/
9 package test.splat.service;
11 import java.io.FileNotFoundException;
12 import java.io.IOException;
13 import java.sql.SQLException;
14 import java.util.List;
16 import org.splat.dal.bo.som.Scenario;
17 import org.splat.dal.dao.som.Database;
18 import org.splat.log.AppLogger;
19 import org.splat.service.DocumentTypeService;
20 import org.splat.service.technical.ProjectSettingsService;
21 import org.splat.service.technical.ProjectSettingsService.Step;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.beans.factory.annotation.Qualifier;
24 import org.springframework.dao.DuplicateKeyException;
25 import org.testng.Assert;
26 import org.testng.annotations.Test;
28 import test.splat.common.BaseTest;
31 * Test class for KnowledgeElementDAO.
33 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
36 public class TestProjectSettingsService extends BaseTest {
39 * Logger for the class.
41 private static final AppLogger LOG = AppLogger
42 .getLogger(TestProjectSettingsService.class);
45 * The ProjectSettingsService. Later injected by Spring.
48 @Qualifier("projectSettings")
49 private transient ProjectSettingsService _projectSettings;
52 * The DocumentTypeService. Later injected by Spring.
55 @Qualifier("documentTypeService")
56 private transient DocumentTypeService _documentTypeService;
59 * Test of loading document mappings to file formats from customization XML file.<BR>
60 * <B>Description :</B> <BR>
61 * <i>Load customization and check the result.</i><BR>
62 * <B>Action : </B><BR>
63 * <i>1. call the method for som.xml</i><BR>
64 * <i>2. call the method for a xml without mappings.</i><BR>
65 * <i>3. call the method for a not existing file.</i><BR>
66 * <B>Test data : </B><BR>
67 * <i>test/som.xml</i><BR>
68 * <i>test/som-without-mappings.xml</i><BR>
69 * <i>not existing xxx.xml</i><BR>
71 * <B>Outcome results:</B><BR>
74 * <li>doImport() must return true for mapped formats<BR>
76 * <li>doImport() must always return false<BR>
78 * <li>Exception is thrown<BR>
84 * if configuration loading is failed
85 * @throws SQLException
86 * if configuration loading is failed
89 public void testLoadMappings() throws IOException, SQLException {
90 LOG.debug(">>>>> BEGIN testLoadMappings()()");
91 startNestedTransaction();
92 // ////// Load good workflow customization
94 * geometry: brep model: med loads: c3m results: med
96 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
98 _projectSettings.configure(ClassLoader.getSystemResource(
99 "test/som.xml").getPath());
100 } catch (FileNotFoundException e) {
101 Assert.fail("Can't find configuration file: ", e);
103 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
104 Assert.assertTrue(steps.size() > 0, "No steps are created.");
105 Assert.assertTrue(_projectSettings.doImport("geometry", "brep"));
106 Assert.assertTrue(_projectSettings.doImport("model", "med"));
107 Assert.assertTrue(_projectSettings.doImport("loads", "c3m"));
108 Assert.assertTrue(_projectSettings.doImport("results", "med"));
110 // ////// Load workflow customization with empty mappings
111 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
113 _projectSettings.configure(ClassLoader.getSystemResource(
114 "test/som-without-mappings.xml").getPath());
115 } catch (FileNotFoundException e) {
116 Assert.fail("Can't find configuration file: ", e);
118 steps = _projectSettings.getStepsOf(Scenario.class);
119 Assert.assertTrue(steps.size() > 0, "No steps are created.");
120 Assert.assertFalse(_projectSettings.doImport("geometry", "brep"));
121 Assert.assertFalse(_projectSettings.doImport("model", "med"));
122 Assert.assertFalse(_projectSettings.doImport("loads", "c3m"));
123 Assert.assertFalse(_projectSettings.doImport("results", "med"));
125 // ////// Load workflow customization from not existing file
126 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
128 _projectSettings.configure(ClassLoader.getSystemResource("/")
132 .fail("Customization loading must fail for not existing configuration file.");
133 } catch (FileNotFoundException e) {
134 LOG.debug("Configuration file must not be found.", e);
137 rollbackNestedTransaction();
138 LOG.debug(">>>>> END testLoadMappings()()");
142 * Test of loading file formats mappings to document types from customization XML file.<BR>
143 * <B>Description :</B> <BR>
144 * <i>Load customization and check the result.</i><BR>
145 * <B>Action : </B><BR>
146 * <i>1. call the method for som.xml</i><BR>
147 * <i>2. call the method for a xml without mappings.</i><BR>
148 * <i>3. call the method for a not existing file.</i><BR>
149 * <B>Test data : </B><BR>
150 * <i>test/som.xml</i><BR>
151 * <i>test/som-without-mappings.xml</i><BR>
152 * <i>not existing xxx.xml</i><BR>
154 * <B>Outcome results:</B><BR>
157 * <li>Following mappings must be loaded:<BR/>
161 * <li>pdf: requirements</li>
162 * <li>doc: specification</li>
163 * <!-- Microsoft Word 2003 and earlier -->
164 * <li>docx: specification</li>
165 * <!-- Microsoft Word 2007 and later -->
166 * <li>xml: specification</li>
167 * <!-- Microsoft Word 2007 Open XML -->
172 * <li>doc: design</li>
173 * <li>docx: design</li>
174 * <li>xml: design</li>
179 * <li>doc: memorandum</li>
180 * <li>docx: memorandum</li>
181 * <li>xml: memorandum</li>
182 * <li>sldprt: geometry</li>
183 * <!-- SolidWorks Part -->
184 * <li>sldasm: geometry</li>
185 * <!-- SolidWorks Assembly -->
186 * <li>part: geometry</li>
188 * <li>py: geometry</li>
189 * <!-- GEOM Python script -->
194 * <li>doc: memorandum</li>
195 * <li>docx: memorandum</li>
196 * <li>xml: memorandum</li>
197 * <li>med: model</li>
199 * <!-- SMESH Python script -->
204 * <li>getDefaultDocumentType must always return null<BR>
206 * <li>Exception is thrown<BR>
211 * @throws IOException
212 * if configuration loading is failed
213 * @throws SQLException
214 * if configuration loading is failed
217 public void testLoadDefaultDocTypes() throws IOException, SQLException {
218 LOG.debug(">>>>> BEGIN testLoadDefaultDocTypes()");
219 startNestedTransaction();
220 // ////// Load good workflow customization
222 * geometry: brep model: med loads: c3m results: med
224 Database.getInstance().reset();
225 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
227 _projectSettings.configure(ClassLoader.getSystemResource(
228 "test/som.xml").getPath());
229 } catch (FileNotFoundException e) {
230 Assert.fail("Can't find configuration file: ", e);
232 Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0,
233 "No document types are created.");
234 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
235 Assert.assertTrue(steps.size() > 0, "No steps are created.");
237 for (Step step : steps) {
238 List<String> defTypes = _projectSettings.getDefaultFormats(step);
239 Assert.assertNotNull(defTypes,
240 "getDefaultFormats must always return not null list:");
241 switch (step.getNumber()) {
243 Assert.assertEquals(defTypes.size(), 4);
244 Assert.assertNotNull(_projectSettings
245 .getDefaultDocumentType(step, "pdf"));
246 Assert.assertEquals(_projectSettings
247 .getDefaultDocumentType(step, "pdf").getName(),
249 Assert.assertNotNull(_projectSettings
250 .getDefaultDocumentType(step, "doc"));
251 Assert.assertEquals(_projectSettings
252 .getDefaultDocumentType(step, "doc").getName(),
254 Assert.assertNotNull(_projectSettings
255 .getDefaultDocumentType(step, "docx"));
256 Assert.assertEquals(_projectSettings
257 .getDefaultDocumentType(step, "docx").getName(),
259 Assert.assertNotNull(_projectSettings
260 .getDefaultDocumentType(step, "xml"));
261 Assert.assertEquals(_projectSettings
262 .getDefaultDocumentType(step, "xml").getName(),
266 Assert.assertEquals(defTypes.size(), 3);
267 Assert.assertNull(_projectSettings.getDefaultDocumentType(
269 Assert.assertNotNull(_projectSettings
270 .getDefaultDocumentType(step, "doc"));
271 Assert.assertEquals(_projectSettings
272 .getDefaultDocumentType(step, "doc").getName(),
274 Assert.assertNotNull(_projectSettings
275 .getDefaultDocumentType(step, "docx"));
276 Assert.assertEquals(_projectSettings
277 .getDefaultDocumentType(step, "docx").getName(),
279 Assert.assertNotNull(_projectSettings
280 .getDefaultDocumentType(step, "xml"));
281 Assert.assertEquals(_projectSettings
282 .getDefaultDocumentType(step, "xml").getName(),
286 Assert.assertEquals(defTypes.size(), 7);
287 Assert.assertNull(_projectSettings.getDefaultDocumentType(
289 Assert.assertNotNull(_projectSettings
290 .getDefaultDocumentType(step, "sldprt"));
291 Assert.assertEquals(_projectSettings
292 .getDefaultDocumentType(step, "sldprt").getName(),
294 Assert.assertNotNull(_projectSettings
295 .getDefaultDocumentType(step, "sldasm"));
296 Assert.assertEquals(_projectSettings
297 .getDefaultDocumentType(step, "sldasm").getName(),
299 Assert.assertNotNull(_projectSettings
300 .getDefaultDocumentType(step, "part"));
301 Assert.assertEquals(_projectSettings
302 .getDefaultDocumentType(step, "part").getName(),
304 Assert.assertNotNull(_projectSettings
305 .getDefaultDocumentType(step, "py"));
306 Assert.assertEquals(_projectSettings
307 .getDefaultDocumentType(step, "py").getName(),
309 Assert.assertNotNull(_projectSettings
310 .getDefaultDocumentType(step, "doc"));
311 Assert.assertEquals(_projectSettings
312 .getDefaultDocumentType(step, "doc").getName(),
314 Assert.assertNotNull(_projectSettings
315 .getDefaultDocumentType(step, "docx"));
316 Assert.assertEquals(_projectSettings
317 .getDefaultDocumentType(step, "docx").getName(),
319 Assert.assertNotNull(_projectSettings
320 .getDefaultDocumentType(step, "xml"));
321 Assert.assertEquals(_projectSettings
322 .getDefaultDocumentType(step, "xml").getName(),
326 Assert.assertEquals(defTypes.size(), 5);
327 Assert.assertNull(_projectSettings.getDefaultDocumentType(
329 Assert.assertNotNull(_projectSettings
330 .getDefaultDocumentType(step, "med"));
331 Assert.assertEquals(_projectSettings
332 .getDefaultDocumentType(step, "med").getName(),
334 Assert.assertNotNull(_projectSettings
335 .getDefaultDocumentType(step, "py"));
336 Assert.assertEquals(_projectSettings
337 .getDefaultDocumentType(step, "py").getName(),
339 Assert.assertNotNull(_projectSettings
340 .getDefaultDocumentType(step, "doc"));
341 Assert.assertEquals(_projectSettings
342 .getDefaultDocumentType(step, "doc").getName(),
344 Assert.assertNotNull(_projectSettings
345 .getDefaultDocumentType(step, "docx"));
346 Assert.assertEquals(_projectSettings
347 .getDefaultDocumentType(step, "docx").getName(),
349 Assert.assertNotNull(_projectSettings
350 .getDefaultDocumentType(step, "xml"));
351 Assert.assertEquals(_projectSettings
352 .getDefaultDocumentType(step, "xml").getName(),
356 Assert.assertEquals(defTypes.size(), 0);
357 Assert.assertNull(_projectSettings.getDefaultDocumentType(
359 Assert.assertNull(_projectSettings.getDefaultDocumentType(
361 Assert.assertNull(_projectSettings.getDefaultDocumentType(
363 Assert.assertNull(_projectSettings.getDefaultDocumentType(
365 Assert.assertNull(_projectSettings.getDefaultDocumentType(
367 Assert.assertNull(_projectSettings.getDefaultDocumentType(
369 Assert.assertNull(_projectSettings.getDefaultDocumentType(
371 Assert.assertNull(_projectSettings.getDefaultDocumentType(
373 Assert.assertNull(_projectSettings.getDefaultDocumentType(
378 // ////// Load workflow customization with empty mappings
379 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
381 _projectSettings.configure(ClassLoader.getSystemResource(
382 "test/som-without-mappings.xml").getPath());
383 } catch (FileNotFoundException e) {
384 Assert.fail("Can't find configuration file: ", e);
386 steps = _projectSettings.getStepsOf(Scenario.class);
387 Assert.assertTrue(steps.size() > 0, "No steps are created.");
388 for (Step step : steps) {
389 List<String> defTypes = _projectSettings.getDefaultFormats(step);
390 Assert.assertNotNull(defTypes,
391 "getDefaultFormats must always return not null list:");
392 Assert.assertEquals(defTypes.size(), 0);
393 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
395 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
397 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
399 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
401 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
403 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
405 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
407 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
409 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
413 // ////// Load workflow customization from not existing file
414 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
416 _projectSettings.configure(ClassLoader.getSystemResource("/")
420 .fail("Customization loading must fail for not existing configuration file.");
421 } catch (FileNotFoundException e) {
422 LOG.debug("Configuration file must not be found.", e);
425 rollbackNestedTransaction();
426 LOG.debug(">>>>> END testLoadDefaultDocTypes()");
430 * Test of repeated database configuration method (dynamic reconfiguration).<BR>
431 * The problem - duplication of the simer user admin role. <B>Description :</B> <BR>
432 * <i>Load customization twice and check the result.</i><BR>
433 * <B>Action : </B><BR>
434 * <i>1. call the method twice for som.xml</i><BR>
435 * <B>Test data : </B><BR>
436 * <i>test/som.xml</i><BR>
438 * <B>Outcome results:</B><BR>
441 * <li>step must be configured<BR>
446 * @throws IOException
447 * if configuration loading is failed
448 * @throws SQLException
449 * if configuration loading is failed
452 public void testConfigure() throws IOException, SQLException {
453 LOG.debug(">>>>> BEGIN testConfigure()");
454 startNestedTransaction();
455 // ///////////////////////////////////////////////////
456 // ////// Load good workflow customization
457 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
459 _projectSettings.configure(ClassLoader.getSystemResource(
460 "test/som.xml").getPath());
461 } catch (FileNotFoundException e) {
462 Assert.fail("Can't find configuration file: ", e);
465 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
466 Assert.assertTrue(steps.size() > 0, "No steps are created.");
468 // /////////////////////////////////////////////////////////
469 // ////// Test reconfiguration attempt
470 Database.getInstance().reset();
471 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
473 _projectSettings.configure(ClassLoader.getSystemResource(
474 "test/som.xml").getPath());
475 } catch (FileNotFoundException e) {
476 Assert.fail("Can't find configuration file: ", e);
478 steps = _projectSettings.getStepsOf(Scenario.class);
479 Assert.assertTrue(steps.size() > 0, "No steps are created.");
483 * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different
484 * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested
485 * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated
486 * with the session: [org.splat.dal.bo.kernel.Role#simer] at
487 * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at
488 * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at
489 * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at
490 * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at
491 * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
493 getHibernateTemplate().flush();
494 } catch (DuplicateKeyException dke) {
496 "User creation failed during the database reconfiguration: "
497 + dke.getMessage(), dke);
500 rollbackNestedTransaction();
501 LOG.debug(">>>>> END testConfigure()");