]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java
Salome HOME
Loading of mappings of document types to lists of file formats is implemented. Projec...
[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>no input parameters</i><BR>
66          * <i>no input parameters</i><BR>
67          * <i>no input parameters</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                 try {
94                         _projectSettings.configure(ClassLoader.getSystemResource(
95                                         "test/som.xml").getPath());
96                 } catch (FileNotFoundException e) {
97                         Assert.fail("Can't find configuration file: ", e);
98                 }
99                 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
100                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
101                 Assert.assertTrue(_projectSettings.doImport("geometry", "brep"));
102                 Assert.assertTrue(_projectSettings.doImport("model", "med"));
103                 Assert.assertTrue(_projectSettings.doImport("loads", "c3m"));
104                 Assert.assertTrue(_projectSettings.doImport("results", "med"));
105
106                 // ////// Load workflow customization with empty mappings
107                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
108                 try {
109                         _projectSettings.configure(ClassLoader.getSystemResource(
110                                         "test/som-without-mappings.xml").getPath());
111                 } catch (FileNotFoundException e) {
112                         Assert.fail("Can't find configuration file: ", e);
113                 }
114                 steps = _projectSettings.getStepsOf(Scenario.class);
115                 Assert.assertTrue(steps.size() > 0, "No steps are created.");
116                 Assert.assertFalse(_projectSettings.doImport("geometry", "brep"));
117                 Assert.assertFalse(_projectSettings.doImport("model", "med"));
118                 Assert.assertFalse(_projectSettings.doImport("loads", "c3m"));
119                 Assert.assertFalse(_projectSettings.doImport("results", "med"));
120
121                 // ////// Load workflow customization from not existing file
122                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
123                 try {
124                         _projectSettings.configure(ClassLoader.getSystemResource("/")
125                                         .getPath()
126                                         + "test/xxx.xml");
127                         Assert
128                                         .fail("Customization loading must fail for not existing configuration file.");
129                 } catch (FileNotFoundException e) {
130                         LOG.debug("Configuration file must not be found.", e);
131                 }
132
133                 LOG.debug(">>>>> END testGetScenarioInfo()");
134         }
135
136 }