Salome HOME
Uses relations for new documents are created during checkin. Unit test is improved...
[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.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.testng.Assert;
25 import org.testng.annotations.Test;
26
27 import test.splat.common.BaseTest;
28
29 /**
30  * Test class for KnowledgeElementDAO.
31  * 
32  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
33  * 
34  */
35 public class TestProjectSettingsService extends BaseTest {
36
37         /**
38          * Logger for the class.
39          */
40         private static final AppLogger LOG = AppLogger
41                         .getLogger(TestProjectSettingsService.class);
42
43         /**
44          * The ProjectSettingsService. Later injected by Spring.
45          */
46         @Autowired
47         @Qualifier("projectSettings")
48         private transient ProjectSettingsService _projectSettings;
49
50         /**
51          * The DocumentTypeService. Later injected by Spring.
52          */
53         @Autowired
54         @Qualifier("documentTypeService")
55         private transient DocumentTypeService _documentTypeService;
56
57         /**
58          * Test of loading document mappings to file formats from customization XML file.<BR>
59          * <B>Description :</B> <BR>
60          * <i>Load customization and check the result.</i><BR>
61          * <B>Action : </B><BR>
62          * <i>1. call the method for som.xml</i><BR>
63          * <i>2. call the method for a xml without mappings.</i><BR>
64          * <i>3. call the method for a not existing file.</i><BR>
65          * <B>Test data : </B><BR>
66          * <i>test/som.xml</i><BR>
67          * <i>test/som-without-mappings.xml</i><BR>
68          * <i>not existing xxx.xml</i><BR>
69          * 
70          * <B>Outcome results:</B><BR>
71          * <i>
72          * <ul>
73          * <li>doImport() must return true for mapped formats<BR>
74          * </li>
75          * <li>doImport() must always return false<BR>
76          * </li>
77          * <li>Exception is thrown<BR>
78          * </li>
79          * </ul>
80          * </i>
81          * 
82          * @throws IOException
83          *             if configuration loading is failed
84          * @throws SQLException
85          *             if configuration loading is failed
86          */
87         @Test
88         public void testLoadMappings() throws IOException, SQLException {
89                 LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
90                 // ////// Load good workflow customization
91                 /*
92                  * geometry: brep model: med loads: c3m results: med
93                  */
94                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
95                 try {
96                         _projectSettings.configure(ClassLoader.getSystemResource(
97                                         "test/som.xml").getPath());
98                 } catch (FileNotFoundException e) {
99                         Assert.fail("Can't find configuration file: ", e);
100                 }
101                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
102                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
103                 Assert.assertTrue(_projectSettings.doImport("geometry", "brep"));
104                 Assert.assertTrue(_projectSettings.doImport("model", "med"));
105                 Assert.assertTrue(_projectSettings.doImport("loads", "c3m"));
106                 Assert.assertTrue(_projectSettings.doImport("results", "med"));
107
108                 // ////// Load workflow customization with empty mappings
109                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
110                 try {
111                         _projectSettings.configure(ClassLoader.getSystemResource(
112                                         "test/som-without-mappings.xml").getPath());
113                 } catch (FileNotFoundException e) {
114                         Assert.fail("Can't find configuration file: ", e);
115                 }
116                 steps = _projectSettings.getStepsOf(Scenario.class);
117                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
118                 Assert.assertFalse(_projectSettings.doImport("geometry", "brep"));
119                 Assert.assertFalse(_projectSettings.doImport("model", "med"));
120                 Assert.assertFalse(_projectSettings.doImport("loads", "c3m"));
121                 Assert.assertFalse(_projectSettings.doImport("results", "med"));
122
123                 // ////// Load workflow customization from not existing file
124                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
125                 try {
126                         _projectSettings.configure(ClassLoader.getSystemResource("/")
127                                         .getPath()
128                                         + "test/xxx.xml");
129                         Assert
130                                         .fail("Customization loading must fail for not existing configuration file.");
131                 } catch (FileNotFoundException e) {
132                         LOG.debug("Configuration file must not be found.", e);
133                 }
134
135                 LOG.debug(">>>>> END testGetScenarioInfo()");
136         }
137
138         /**
139          * Test of loading file formats mappings to document types from customization XML file.<BR>
140          * <B>Description :</B> <BR>
141          * <i>Load customization and check the result.</i><BR>
142          * <B>Action : </B><BR>
143          * <i>1. call the method for som.xml</i><BR>
144          * <i>2. call the method for a xml without mappings.</i><BR>
145          * <i>3. call the method for a not existing file.</i><BR>
146          * <B>Test data : </B><BR>
147          * <i>test/som.xml</i><BR>
148          * <i>test/som-without-mappings.xml</i><BR>
149          * <i>not existing xxx.xml</i><BR>
150          * 
151          * <B>Outcome results:</B><BR>
152          * <i>
153          * <ul>
154          * <li>Following mappings must be loaded:<BR/>
155          * <ul>
156          * <li>step 1
157          * <ul>
158          * <li>pdf: requirements</li>
159          * <li>doc: specification</li>
160          * <!-- Microsoft Word 2003 and earlier -->
161          * <li>docx: specification</li>
162          * <!-- Microsoft Word 2007 and later -->
163          * <li>xml: specification</li>
164          * <!-- Microsoft Word 2007 Open XML -->
165          * </ul>
166          * </li>
167          * <li>step 2
168          * <ul>
169          * <li>doc: design</li>
170          * <li>docx: design</li>
171          * <li>xml: design</li>
172          * </ul>
173          * </li>
174          * <li>step 3
175          * <ul>
176          * <li>doc: memorandum</li>
177          * <li>docx: memorandum</li>
178          * <li>xml: memorandum</li>
179          * <li>sldprt: geometry</li>
180          * <!-- SolidWorks Part -->
181          * <li>sldasm: geometry</li>
182          * <!-- SolidWorks Assembly -->
183          * <li>part: geometry</li>
184          * <!-- GEOM Part -->
185          * <li>py: geometry</li>
186          * <!-- GEOM Python script -->
187          * </ul>
188          * </li>
189          * <li>step 4
190          * <ul>
191          * <li>doc: memorandum</li>
192          * <li>docx: memorandum</li>
193          * <li>xml: memorandum</li>
194          * <li>med: model</li>
195          * <li>py: model</li>
196          * <!-- SMESH Python script -->
197          * </ul>
198          * </li>
199          * </ul>
200          * </li>
201          * <li>getDefaultDocumentType must always return null<BR>
202          * </li>
203          * <li>Exception is thrown<BR>
204          * </li>
205          * </ul>
206          * </i>
207          * 
208          * @throws IOException
209          *             if configuration loading is failed
210          * @throws SQLException
211          *             if configuration loading is failed
212          */
213         @Test
214         public void testLoadDefaultDocTypes() throws IOException, SQLException {
215                 LOG.debug(">>>>> BEGIN testLoadDefaultDocTypes()");
216                 // ////// Load good workflow customization
217                 /*
218                  * geometry: brep model: med loads: c3m results: med
219                  */
220                 Database.getInstance().reset();
221                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
222                 try {
223                         _projectSettings.configure(ClassLoader.getSystemResource(
224                                         "test/som.xml").getPath());
225                 } catch (FileNotFoundException e) {
226                         Assert.fail("Can't find configuration file: ", e);
227                 }
228                 Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0,
229                                 "No document types are created.");
230                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
231                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
232
233                 for (Step step : steps) {
234                         List<String> defTypes = _projectSettings.getDefaultFormats(step);
235                         Assert.assertNotNull(defTypes,
236                                         "getDefaultFormats must always return not null list:");
237                         switch (step.getNumber()) {
238                                 case 1:
239                                         Assert.assertEquals(defTypes.size(), 4);
240                                         Assert.assertNotNull(_projectSettings
241                                                         .getDefaultDocumentType(step, "pdf"));
242                                         Assert.assertEquals(_projectSettings
243                                                         .getDefaultDocumentType(step, "pdf").getName(),
244                                                         "requirements");
245                                         Assert.assertNotNull(_projectSettings
246                                                         .getDefaultDocumentType(step, "doc"));
247                                         Assert.assertEquals(_projectSettings
248                                                         .getDefaultDocumentType(step, "doc").getName(),
249                                                         "specification");
250                                         Assert.assertNotNull(_projectSettings
251                                                         .getDefaultDocumentType(step, "docx"));
252                                         Assert.assertEquals(_projectSettings
253                                                         .getDefaultDocumentType(step, "docx").getName(),
254                                                         "specification");
255                                         Assert.assertNotNull(_projectSettings
256                                                         .getDefaultDocumentType(step, "xml"));
257                                         Assert.assertEquals(_projectSettings
258                                                         .getDefaultDocumentType(step, "xml").getName(),
259                                                         "specification");
260                                         break;
261                                 case 2:
262                                         Assert.assertEquals(defTypes.size(), 3);
263                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
264                                                         step, "pdf"));
265                                         Assert.assertNotNull(_projectSettings
266                                                         .getDefaultDocumentType(step, "doc"));
267                                         Assert.assertEquals(_projectSettings
268                                                         .getDefaultDocumentType(step, "doc").getName(),
269                                                         "design");
270                                         Assert.assertNotNull(_projectSettings
271                                                         .getDefaultDocumentType(step, "docx"));
272                                         Assert.assertEquals(_projectSettings
273                                                         .getDefaultDocumentType(step, "docx").getName(),
274                                                         "design");
275                                         Assert.assertNotNull(_projectSettings
276                                                         .getDefaultDocumentType(step, "xml"));
277                                         Assert.assertEquals(_projectSettings
278                                                         .getDefaultDocumentType(step, "xml").getName(),
279                                                         "design");
280                                         break;
281                                 case 3:
282                                         Assert.assertEquals(defTypes.size(), 7);
283                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
284                                                         step, "pdf"));
285                                         Assert.assertNotNull(_projectSettings
286                                                         .getDefaultDocumentType(step, "sldprt"));
287                                         Assert.assertEquals(_projectSettings
288                                                         .getDefaultDocumentType(step, "sldprt").getName(),
289                                                         "geometry");
290                                         Assert.assertNotNull(_projectSettings
291                                                         .getDefaultDocumentType(step, "sldasm"));
292                                         Assert.assertEquals(_projectSettings
293                                                         .getDefaultDocumentType(step, "sldasm").getName(),
294                                                         "geometry");
295                                         Assert.assertNotNull(_projectSettings
296                                                         .getDefaultDocumentType(step, "part"));
297                                         Assert.assertEquals(_projectSettings
298                                                         .getDefaultDocumentType(step, "part").getName(),
299                                                         "geometry");
300                                         Assert.assertNotNull(_projectSettings
301                                                         .getDefaultDocumentType(step, "py"));
302                                         Assert.assertEquals(_projectSettings
303                                                         .getDefaultDocumentType(step, "py").getName(),
304                                                         "geometry");
305                                         Assert.assertNotNull(_projectSettings
306                                                         .getDefaultDocumentType(step, "doc"));
307                                         Assert.assertEquals(_projectSettings
308                                                         .getDefaultDocumentType(step, "doc").getName(),
309                                                         "memorandum");
310                                         Assert.assertNotNull(_projectSettings
311                                                         .getDefaultDocumentType(step, "docx"));
312                                         Assert.assertEquals(_projectSettings
313                                                         .getDefaultDocumentType(step, "docx").getName(),
314                                                         "memorandum");
315                                         Assert.assertNotNull(_projectSettings
316                                                         .getDefaultDocumentType(step, "xml"));
317                                         Assert.assertEquals(_projectSettings
318                                                         .getDefaultDocumentType(step, "xml").getName(),
319                                                         "memorandum");
320                                         break;
321                                 case 4:
322                                         Assert.assertEquals(defTypes.size(), 5);
323                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
324                                                         step, "pdf"));
325                                         Assert.assertNotNull(_projectSettings
326                                                         .getDefaultDocumentType(step, "med"));
327                                         Assert.assertEquals(_projectSettings
328                                                         .getDefaultDocumentType(step, "med").getName(),
329                                                         "model");
330                                         Assert.assertNotNull(_projectSettings
331                                                         .getDefaultDocumentType(step, "py"));
332                                         Assert.assertEquals(_projectSettings
333                                                         .getDefaultDocumentType(step, "py").getName(),
334                                                         "model");
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                                 default:
352                                         Assert.assertEquals(defTypes.size(), 0);
353                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
354                                                         step, "pdf"));
355                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
356                                                         step, "doc"));
357                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
358                                                         step, "docx"));
359                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
360                                                         step, "xml"));
361                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
362                                                         step, "sldprt"));
363                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
364                                                         step, "sldasm"));
365                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
366                                                         step, "part"));
367                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
368                                                         step, "py"));
369                                         Assert.assertNull(_projectSettings.getDefaultDocumentType(
370                                                         step, "med"));
371                         }
372                 }
373
374                 // ////// Load workflow customization with empty mappings
375                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
376                 try {
377                         _projectSettings.configure(ClassLoader.getSystemResource(
378                                         "test/som-without-mappings.xml").getPath());
379                 } catch (FileNotFoundException e) {
380                         Assert.fail("Can't find configuration file: ", e);
381                 }
382                 steps = _projectSettings.getStepsOf(Scenario.class);
383                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
384                 for (Step step : steps) {
385                         List<String> defTypes = _projectSettings.getDefaultFormats(step);
386                         Assert.assertNotNull(defTypes,
387                                         "getDefaultFormats must always return not null list:");
388                         Assert.assertEquals(defTypes.size(), 0);
389                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
390                                         "pdf"));
391                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
392                                         "doc"));
393                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
394                                         "docx"));
395                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
396                                         "xml"));
397                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
398                                         "sldprt"));
399                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
400                                         "sldasm"));
401                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
402                                         "part"));
403                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
404                                         "py"));
405                         Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
406                                         "med"));
407                 }
408
409                 // ////// Load workflow customization from not existing file
410                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
411                 try {
412                         _projectSettings.configure(ClassLoader.getSystemResource("/")
413                                         .getPath()
414                                         + "test/xxx.xml");
415                         Assert
416                                         .fail("Customization loading must fail for not existing configuration file.");
417                 } catch (FileNotFoundException e) {
418                         LOG.debug("Configuration file must not be found.", e);
419                 }
420
421                 LOG.debug(">>>>> END testLoadDefaultDocTypes()");
422         }
423 }