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.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;
26 import test.splat.common.BaseTest;
29 * Test class for KnowledgeElementDAO.
31 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
34 public class TestProjectSettingsService extends BaseTest {
37 * Logger for the class.
39 private static final AppLogger LOG = AppLogger
40 .getLogger(TestProjectSettingsService.class);
43 * The ProjectSettingsService. Later injected by Spring.
46 @Qualifier("projectSettings")
47 private transient ProjectSettingsService _projectSettings;
50 * The DocumentTypeService. Later injected by Spring.
53 @Qualifier("documentTypeService")
54 private transient DocumentTypeService _documentTypeService;
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>
69 * <B>Outcome results:</B><BR>
72 * <li>doImport() must return true for mapped formats<BR>
74 * <li>doImport() must always return false<BR>
76 * <li>Exception is thrown<BR>
82 * if configuration loading is failed
83 * @throws SQLException
84 * if configuration loading is failed
87 public void testLoadMappings() throws IOException, SQLException {
88 LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
89 // ////// Load good workflow customization
91 * geometry: brep model: med loads: c3m results: med
93 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
95 _projectSettings.configure(ClassLoader.getSystemResource(
96 "test/som.xml").getPath());
97 } catch (FileNotFoundException e) {
98 Assert.fail("Can't find configuration file: ", e);
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"));
107 // ////// Load workflow customization with empty mappings
108 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
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);
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"));
122 // ////// Load workflow customization from not existing file
123 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
125 _projectSettings.configure(ClassLoader.getSystemResource("/")
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);
134 LOG.debug(">>>>> END testGetScenarioInfo()");
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>
150 * <B>Outcome results:</B><BR>
153 * <li>Following mappings must be loaded:<BR/>
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 -->
168 * <li>doc: design</li>
169 * <li>docx: design</li>
170 * <li>xml: design</li>
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>
184 * <li>py: geometry</li>
185 * <!-- GEOM Python script -->
190 * <li>doc: memorandum</li>
191 * <li>docx: memorandum</li>
192 * <li>xml: memorandum</li>
193 * <li>med: model</li>
195 * <!-- SMESH Python script -->
200 * <li>getDefaultDocumentType must always return null<BR>
202 * <li>Exception is thrown<BR>
207 * @throws IOException
208 * if configuration loading is failed
209 * @throws SQLException
210 * if configuration loading is failed
213 public void testLoadDefaultDocTypes() throws IOException, SQLException {
214 LOG.debug(">>>>> BEGIN testLoadDefaultDocTypes()");
215 // ////// Load good workflow customization
217 * geometry: brep model: med loads: c3m results: med
219 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
221 _projectSettings.configure(ClassLoader.getSystemResource(
222 "test/som.xml").getPath());
223 } catch (FileNotFoundException e) {
224 Assert.fail("Can't find configuration file: ", e);
226 List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
227 Assert.assertTrue(steps.size() > 0, "No steps are created.");
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()) {
235 Assert.assertEquals(defTypes.size(), 4);
236 Assert.assertNotNull(_projectSettings
237 .getDefaultDocumentType(step, "pdf"));
238 Assert.assertEquals(_projectSettings
239 .getDefaultDocumentType(step, "pdf").getName(),
241 Assert.assertNotNull(_projectSettings
242 .getDefaultDocumentType(step, "doc"));
243 Assert.assertEquals(_projectSettings
244 .getDefaultDocumentType(step, "doc").getName(),
246 Assert.assertNotNull(_projectSettings
247 .getDefaultDocumentType(step, "docx"));
248 Assert.assertEquals(_projectSettings
249 .getDefaultDocumentType(step, "docx").getName(),
251 Assert.assertNotNull(_projectSettings
252 .getDefaultDocumentType(step, "xml"));
253 Assert.assertEquals(_projectSettings
254 .getDefaultDocumentType(step, "xml").getName(),
258 Assert.assertEquals(defTypes.size(), 3);
259 Assert.assertNull(_projectSettings.getDefaultDocumentType(
261 Assert.assertNotNull(_projectSettings
262 .getDefaultDocumentType(step, "xml"));
263 Assert.assertEquals(_projectSettings
264 .getDefaultDocumentType(step, "xml").getName(),
266 Assert.assertNotNull(_projectSettings
267 .getDefaultDocumentType(step, "doc"));
268 Assert.assertEquals(_projectSettings
269 .getDefaultDocumentType(step, "doc").getName(),
271 Assert.assertNotNull(_projectSettings
272 .getDefaultDocumentType(step, "docx"));
273 Assert.assertEquals(_projectSettings
274 .getDefaultDocumentType(step, "docx").getName(),
278 Assert.assertEquals(defTypes.size(), 7);
279 Assert.assertNull(_projectSettings.getDefaultDocumentType(
281 Assert.assertNotNull(_projectSettings
282 .getDefaultDocumentType(step, "sldprt"));
283 Assert.assertEquals(_projectSettings
284 .getDefaultDocumentType(step, "sldprt").getName(),
286 Assert.assertNotNull(_projectSettings
287 .getDefaultDocumentType(step, "sldasm"));
288 Assert.assertEquals(_projectSettings
289 .getDefaultDocumentType(step, "sldasm").getName(),
291 Assert.assertNotNull(_projectSettings
292 .getDefaultDocumentType(step, "part"));
293 Assert.assertEquals(_projectSettings
294 .getDefaultDocumentType(step, "part").getName(),
296 Assert.assertNotNull(_projectSettings
297 .getDefaultDocumentType(step, "py"));
298 Assert.assertEquals(_projectSettings
299 .getDefaultDocumentType(step, "py").getName(),
301 Assert.assertNotNull(_projectSettings
302 .getDefaultDocumentType(step, "doc"));
303 Assert.assertEquals(_projectSettings
304 .getDefaultDocumentType(step, "doc").getName(),
306 Assert.assertNotNull(_projectSettings
307 .getDefaultDocumentType(step, "docx"));
308 Assert.assertEquals(_projectSettings
309 .getDefaultDocumentType(step, "docx").getName(),
311 Assert.assertNotNull(_projectSettings
312 .getDefaultDocumentType(step, "xml"));
313 Assert.assertEquals(_projectSettings
314 .getDefaultDocumentType(step, "xml").getName(),
318 Assert.assertEquals(defTypes.size(), 5);
319 Assert.assertNull(_projectSettings.getDefaultDocumentType(
321 Assert.assertNotNull(_projectSettings
322 .getDefaultDocumentType(step, "med"));
323 Assert.assertEquals(_projectSettings
324 .getDefaultDocumentType(step, "med").getName(),
326 Assert.assertNotNull(_projectSettings
327 .getDefaultDocumentType(step, "py"));
328 Assert.assertEquals(_projectSettings
329 .getDefaultDocumentType(step, "py").getName(),
331 Assert.assertNotNull(_projectSettings
332 .getDefaultDocumentType(step, "doc"));
333 Assert.assertEquals(_projectSettings
334 .getDefaultDocumentType(step, "doc").getName(),
336 Assert.assertNotNull(_projectSettings
337 .getDefaultDocumentType(step, "docx"));
338 Assert.assertEquals(_projectSettings
339 .getDefaultDocumentType(step, "docx").getName(),
341 Assert.assertNotNull(_projectSettings
342 .getDefaultDocumentType(step, "xml"));
343 Assert.assertEquals(_projectSettings
344 .getDefaultDocumentType(step, "xml").getName(),
348 Assert.assertEquals(defTypes.size(), 0);
349 Assert.assertNull(_projectSettings.getDefaultDocumentType(
351 Assert.assertNull(_projectSettings.getDefaultDocumentType(
353 Assert.assertNull(_projectSettings.getDefaultDocumentType(
355 Assert.assertNull(_projectSettings.getDefaultDocumentType(
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(
370 // ////// Load workflow customization with empty mappings
371 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
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);
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,
387 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
389 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
391 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
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,
405 // ////// Load workflow customization from not existing file
406 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
408 _projectSettings.configure(ClassLoader.getSystemResource("/")
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);
417 LOG.debug(">>>>> END testLoadDefaultDocTypes()");