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