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.testng.Assert;
25 import org.testng.annotations.Test;
27 import test.splat.common.BaseTest;
30 * Test class for KnowledgeElementDAO.
32 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
35 public class TestProjectSettingsService extends BaseTest {
38 * Logger for the class.
40 private static final AppLogger LOG = AppLogger
41 .getLogger(TestProjectSettingsService.class);
44 * The ProjectSettingsService. Later injected by Spring.
47 @Qualifier("projectSettings")
48 private transient ProjectSettingsService _projectSettings;
51 * The DocumentTypeService. Later injected by Spring.
54 @Qualifier("documentTypeService")
55 private transient DocumentTypeService _documentTypeService;
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>
70 * <B>Outcome results:</B><BR>
73 * <li>doImport() must return true for mapped formats<BR>
75 * <li>doImport() must always return false<BR>
77 * <li>Exception is thrown<BR>
83 * if configuration loading is failed
84 * @throws SQLException
85 * if configuration loading is failed
88 public void testLoadMappings() throws IOException, SQLException {
89 LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
90 // ////// Load good workflow customization
92 * geometry: brep model: med loads: c3m results: med
94 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
96 _projectSettings.configure(ClassLoader.getSystemResource(
97 "test/som.xml").getPath());
98 } catch (FileNotFoundException e) {
99 Assert.fail("Can't find configuration file: ", e);
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"));
108 // ////// Load workflow customization with empty mappings
109 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
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);
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"));
123 // ////// Load workflow customization from not existing file
124 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
126 _projectSettings.configure(ClassLoader.getSystemResource("/")
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);
135 LOG.debug(">>>>> END testGetScenarioInfo()");
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>
151 * <B>Outcome results:</B><BR>
154 * <li>Following mappings must be loaded:<BR/>
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 -->
169 * <li>doc: design</li>
170 * <li>docx: design</li>
171 * <li>xml: design</li>
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>
185 * <li>py: geometry</li>
186 * <!-- GEOM Python script -->
191 * <li>doc: memorandum</li>
192 * <li>docx: memorandum</li>
193 * <li>xml: memorandum</li>
194 * <li>med: model</li>
196 * <!-- SMESH Python script -->
201 * <li>getDefaultDocumentType must always return null<BR>
203 * <li>Exception is thrown<BR>
208 * @throws IOException
209 * if configuration loading is failed
210 * @throws SQLException
211 * if configuration loading is failed
214 public void testLoadDefaultDocTypes() throws IOException, SQLException {
215 LOG.debug(">>>>> BEGIN testLoadDefaultDocTypes()");
216 // ////// Load good workflow customization
218 * geometry: brep model: med loads: c3m results: med
220 Database.getInstance().reset();
221 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
223 _projectSettings.configure(ClassLoader.getSystemResource(
224 "test/som.xml").getPath());
225 } catch (FileNotFoundException e) {
226 Assert.fail("Can't find configuration file: ", e);
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.");
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()) {
239 Assert.assertEquals(defTypes.size(), 4);
240 Assert.assertNotNull(_projectSettings
241 .getDefaultDocumentType(step, "pdf"));
242 Assert.assertEquals(_projectSettings
243 .getDefaultDocumentType(step, "pdf").getName(),
245 Assert.assertNotNull(_projectSettings
246 .getDefaultDocumentType(step, "doc"));
247 Assert.assertEquals(_projectSettings
248 .getDefaultDocumentType(step, "doc").getName(),
250 Assert.assertNotNull(_projectSettings
251 .getDefaultDocumentType(step, "docx"));
252 Assert.assertEquals(_projectSettings
253 .getDefaultDocumentType(step, "docx").getName(),
255 Assert.assertNotNull(_projectSettings
256 .getDefaultDocumentType(step, "xml"));
257 Assert.assertEquals(_projectSettings
258 .getDefaultDocumentType(step, "xml").getName(),
262 Assert.assertEquals(defTypes.size(), 3);
263 Assert.assertNull(_projectSettings.getDefaultDocumentType(
265 Assert.assertNotNull(_projectSettings
266 .getDefaultDocumentType(step, "doc"));
267 Assert.assertEquals(_projectSettings
268 .getDefaultDocumentType(step, "doc").getName(),
270 Assert.assertNotNull(_projectSettings
271 .getDefaultDocumentType(step, "docx"));
272 Assert.assertEquals(_projectSettings
273 .getDefaultDocumentType(step, "docx").getName(),
275 Assert.assertNotNull(_projectSettings
276 .getDefaultDocumentType(step, "xml"));
277 Assert.assertEquals(_projectSettings
278 .getDefaultDocumentType(step, "xml").getName(),
282 Assert.assertEquals(defTypes.size(), 7);
283 Assert.assertNull(_projectSettings.getDefaultDocumentType(
285 Assert.assertNotNull(_projectSettings
286 .getDefaultDocumentType(step, "sldprt"));
287 Assert.assertEquals(_projectSettings
288 .getDefaultDocumentType(step, "sldprt").getName(),
290 Assert.assertNotNull(_projectSettings
291 .getDefaultDocumentType(step, "sldasm"));
292 Assert.assertEquals(_projectSettings
293 .getDefaultDocumentType(step, "sldasm").getName(),
295 Assert.assertNotNull(_projectSettings
296 .getDefaultDocumentType(step, "part"));
297 Assert.assertEquals(_projectSettings
298 .getDefaultDocumentType(step, "part").getName(),
300 Assert.assertNotNull(_projectSettings
301 .getDefaultDocumentType(step, "py"));
302 Assert.assertEquals(_projectSettings
303 .getDefaultDocumentType(step, "py").getName(),
305 Assert.assertNotNull(_projectSettings
306 .getDefaultDocumentType(step, "doc"));
307 Assert.assertEquals(_projectSettings
308 .getDefaultDocumentType(step, "doc").getName(),
310 Assert.assertNotNull(_projectSettings
311 .getDefaultDocumentType(step, "docx"));
312 Assert.assertEquals(_projectSettings
313 .getDefaultDocumentType(step, "docx").getName(),
315 Assert.assertNotNull(_projectSettings
316 .getDefaultDocumentType(step, "xml"));
317 Assert.assertEquals(_projectSettings
318 .getDefaultDocumentType(step, "xml").getName(),
322 Assert.assertEquals(defTypes.size(), 5);
323 Assert.assertNull(_projectSettings.getDefaultDocumentType(
325 Assert.assertNotNull(_projectSettings
326 .getDefaultDocumentType(step, "med"));
327 Assert.assertEquals(_projectSettings
328 .getDefaultDocumentType(step, "med").getName(),
330 Assert.assertNotNull(_projectSettings
331 .getDefaultDocumentType(step, "py"));
332 Assert.assertEquals(_projectSettings
333 .getDefaultDocumentType(step, "py").getName(),
335 Assert.assertNotNull(_projectSettings
336 .getDefaultDocumentType(step, "doc"));
337 Assert.assertEquals(_projectSettings
338 .getDefaultDocumentType(step, "doc").getName(),
340 Assert.assertNotNull(_projectSettings
341 .getDefaultDocumentType(step, "docx"));
342 Assert.assertEquals(_projectSettings
343 .getDefaultDocumentType(step, "docx").getName(),
345 Assert.assertNotNull(_projectSettings
346 .getDefaultDocumentType(step, "xml"));
347 Assert.assertEquals(_projectSettings
348 .getDefaultDocumentType(step, "xml").getName(),
352 Assert.assertEquals(defTypes.size(), 0);
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(
367 Assert.assertNull(_projectSettings.getDefaultDocumentType(
369 Assert.assertNull(_projectSettings.getDefaultDocumentType(
374 // ////// Load workflow customization with empty mappings
375 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
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);
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,
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,
403 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
405 Assert.assertNull(_projectSettings.getDefaultDocumentType(step,
409 // ////// Load workflow customization from not existing file
410 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
412 _projectSettings.configure(ClassLoader.getSystemResource("/")
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);
421 LOG.debug(">>>>> END testLoadDefaultDocTypes()");