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>no input parameters</i><BR>
66 * <i>no input parameters</i><BR>
67 * <i>no input parameters</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
94 _projectSettings.configure(ClassLoader.getSystemResource(
95 "test/som.xml").getPath());
96 } catch (FileNotFoundException e) {
97 Assert.fail("Can't find configuration file: ", e);
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"));
106 // ////// Load workflow customization with empty mappings
107 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
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);
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"));
121 // ////// Load workflow customization from not existing file
122 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
124 _projectSettings.configure(ClassLoader.getSystemResource("/")
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);
133 LOG.debug(">>>>> END testGetScenarioInfo()");