import java.sql.SQLException;
import java.util.List;
+import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.SimulationContextType;
+import org.splat.dal.dao.som.Database;
import org.splat.log.AppLogger;
import org.splat.service.DocumentTypeService;
+import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.SimulationContextService;
import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.StepsConfigService;
import org.splat.service.technical.ProjectSettingsService.Step;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.dao.DuplicateKeyException;
import org.testng.Assert;
import org.testng.annotations.Test;
import test.splat.common.BaseTest;
/**
- * Test class for KnowledgeElementDAO.
+ * Test class for ProjectService.
*
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*
@Qualifier("projectSettings")
private transient ProjectSettingsService _projectSettings;
+ /**
+ * The StepsConfigService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("stepsConfigService")
+ private transient StepsConfigService _stepsConfigService;
+
/**
* The DocumentTypeService. Later injected by Spring.
*/
@Qualifier("documentTypeService")
private transient DocumentTypeService _documentTypeService;
+ /**
+ * The KnowledgeElementTypeService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("knowledgeElementTypeService")
+ private transient KnowledgeElementTypeService _knowledgeElementTypeService;
+
+ /**
+ * The DocumentTypeService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("simulationContextService")
+ private transient SimulationContextService _simulationContextService;
+
/**
* Test of loading document mappings to file formats from customization XML file.<BR>
* <B>Description :</B> <BR>
*/
@Test
public void testLoadMappings() throws IOException, SQLException {
- LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
+ LOG.debug(">>>>> BEGIN testLoadMappings()()");
+ startNestedTransaction();
// ////// Load good workflow customization
/*
* geometry: brep model: med loads: c3m results: med
*/
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
- _projectSettings.configure(ClassLoader.getSystemResource(
- "test/som.xml").getPath());
+ _projectSettings.configure("classpath:test/som.xml");
} catch (FileNotFoundException e) {
Assert.fail("Can't find configuration file: ", e);
}
- List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
+ List<Step> steps = _stepsConfigService.getStepsOf(Scenario.class);
Assert.assertTrue(steps.size() > 0, "No steps are created.");
Assert.assertTrue(_projectSettings.doImport("geometry", "brep"));
Assert.assertTrue(_projectSettings.doImport("model", "med"));
// ////// Load workflow customization with empty mappings
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
- _projectSettings.configure(ClassLoader.getSystemResource(
- "test/som-without-mappings.xml").getPath());
+ _projectSettings.configure("classpath:test/som-without-mappings.xml");
} catch (FileNotFoundException e) {
Assert.fail("Can't find configuration file: ", e);
}
- steps = _projectSettings.getStepsOf(Scenario.class);
+ steps = _stepsConfigService.getStepsOf(Scenario.class);
Assert.assertTrue(steps.size() > 0, "No steps are created.");
Assert.assertFalse(_projectSettings.doImport("geometry", "brep"));
Assert.assertFalse(_projectSettings.doImport("model", "med"));
// ////// Load workflow customization from not existing file
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
- _projectSettings.configure(ClassLoader.getSystemResource("/")
- .getPath()
- + "test/xxx.xml");
+ _projectSettings.configure("classpath:test/xxx.xml");
Assert
.fail("Customization loading must fail for not existing configuration file.");
} catch (FileNotFoundException e) {
LOG.debug("Configuration file must not be found.", e);
}
- LOG.debug(">>>>> END testGetScenarioInfo()");
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testLoadMappings()()");
}
/**
@Test
public void testLoadDefaultDocTypes() throws IOException, SQLException {
LOG.debug(">>>>> BEGIN testLoadDefaultDocTypes()");
+ startNestedTransaction();
// ////// Load good workflow customization
/*
* geometry: brep model: med loads: c3m results: med
*/
+ Database.getInstance().reset();
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
- _projectSettings.configure(ClassLoader.getSystemResource(
- "test/som.xml").getPath());
+ _projectSettings.configure("classpath:test/som.xml");
} catch (FileNotFoundException e) {
Assert.fail("Can't find configuration file: ", e);
}
- List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0,
+ "No document types are created.");
+ List<Step> steps = _stepsConfigService.getStepsOf(Scenario.class);
Assert.assertTrue(steps.size() > 0, "No steps are created.");
for (Step step : steps) {
Assert.assertEquals(defTypes.size(), 3);
Assert.assertNull(_projectSettings.getDefaultDocumentType(
step, "pdf"));
- Assert.assertNotNull(_projectSettings
- .getDefaultDocumentType(step, "xml"));
- Assert.assertEquals(_projectSettings
- .getDefaultDocumentType(step, "xml").getName(),
- "design");
Assert.assertNotNull(_projectSettings
.getDefaultDocumentType(step, "doc"));
Assert.assertEquals(_projectSettings
Assert.assertEquals(_projectSettings
.getDefaultDocumentType(step, "docx").getName(),
"design");
+ Assert.assertNotNull(_projectSettings
+ .getDefaultDocumentType(step, "xml"));
+ Assert.assertEquals(_projectSettings
+ .getDefaultDocumentType(step, "xml").getName(),
+ "design");
break;
case 3:
- Assert.assertEquals(defTypes.size(), 7);
+ Assert.assertEquals(defTypes.size(), 8);
Assert.assertNull(_projectSettings.getDefaultDocumentType(
step, "pdf"));
Assert.assertNotNull(_projectSettings
Assert.assertEquals(_projectSettings
.getDefaultDocumentType(step, "py").getName(),
"geometry");
+ Assert.assertNotNull(_projectSettings
+ .getDefaultDocumentType(step, "brep"));
+ Assert.assertEquals(_projectSettings
+ .getDefaultDocumentType(step, "brep").getName(),
+ "geometry");
Assert.assertNotNull(_projectSettings
.getDefaultDocumentType(step, "doc"));
Assert.assertEquals(_projectSettings
// ////// Load workflow customization with empty mappings
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
- _projectSettings.configure(ClassLoader.getSystemResource(
- "test/som-without-mappings.xml").getPath());
+ _projectSettings.configure("classpath:test/som-without-mappings.xml");
} catch (FileNotFoundException e) {
Assert.fail("Can't find configuration file: ", e);
}
- steps = _projectSettings.getStepsOf(Scenario.class);
+ steps = _stepsConfigService.getStepsOf(Scenario.class);
Assert.assertTrue(steps.size() > 0, "No steps are created.");
for (Step step : steps) {
List<String> defTypes = _projectSettings.getDefaultFormats(step);
// ////// Load workflow customization from not existing file
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
- _projectSettings.configure(ClassLoader.getSystemResource("/")
- .getPath()
- + "test/xxx.xml");
+ _projectSettings.configure("classpath:test/xxx.xml");
Assert
.fail("Customization loading must fail for not existing configuration file.");
} catch (FileNotFoundException e) {
LOG.debug("Configuration file must not be found.", e);
}
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testLoadDefaultDocTypes()");
}
+
+ /**
+ * Test of repeated database configuration method (dynamic reconfiguration).<BR>
+ * The problem - duplication of the simer user admin role. <B>Description :</B> <BR>
+ * <i>Load customization twice and check the result.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method twice for som.xml</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>test/som.xml</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>step must be configured<BR>
+ * </li>
+ * </ul>
+ * </i>
+ *
+ * @throws IOException
+ * if configuration loading is failed
+ * @throws SQLException
+ * if configuration loading is failed
+ */
+ @Test
+ public void testConfigure() throws IOException, SQLException {
+ LOG.debug(">>>>> BEGIN testConfigure()");
+ startNestedTransaction();
+ // ///////////////////////////////////////////////////
+ // ////// Load good workflow customization
+ getHibernateTemplate().clear();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ Database.getInstance().reset();
+ try {
+ _projectSettings.configure("classpath:test/som.xml");
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find configuration file: ", e);
+ }
+
+ getHibernateTemplate().flush();
+ List<Step> steps = _stepsConfigService.getStepsOf(Scenario.class);
+ Assert.assertTrue(steps.size() > 0, "No steps are created.");
+ KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
+ Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+ SimulationContextType prodtype = _simulationContextService.selectType("product");
+ Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
+
+ // /////////////////////////////////////////////////////////
+ // ////// Test reconfiguration attempt
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ try {
+ _projectSettings.configure("classpath:test/som.xml");
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find configuration file: ", e);
+ }
+ steps = _stepsConfigService.getStepsOf(Scenario.class);
+ Assert.assertTrue(steps.size() > 0, "No steps are created.");
+ ucase = _knowledgeElementTypeService.selectType("usecase");
+ Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+ prodtype = _simulationContextService.selectType("product");
+ Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
+
+ try {
+ /*
+ * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different
+ * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested
+ * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated
+ * with the session: [org.splat.dal.bo.kernel.Role#simer] at
+ * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at
+ * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at
+ * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at
+ * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at
+ * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
+ */
+ getHibernateTemplate().flush();
+ } catch (DuplicateKeyException dke) {
+ Assert.fail(
+ "User creation failed during the database reconfiguration: "
+ + dke.getMessage(), dke);
+ }
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testConfigure()");
+ }
+
+ /**
+ * Test of repeated database configuration method (dynamic reconfiguration).<BR>
+ * The problem - duplication of the simer user admin role. <B>Description :</B> <BR>
+ * <i>Load customization twice and check the result.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method twice for som.xml</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>test/som.xml</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>step must be configured<BR>
+ * </li>
+ * </ul>
+ * </i>
+ *
+ * @throws IOException
+ * if configuration loading is failed
+ * @throws SQLException
+ * if configuration loading is failed
+ */
+ @Test
+ public void testDatabaseInitialize() throws IOException, SQLException {
+ LOG.debug(">>>>> BEGIN testDatabaseInitialize()");
+ startNestedTransaction();
+ // ///////////////////////////////////////////////////
+ // ////// Load good workflow customization
+ getHibernateTemplate().bulkUpdate("delete from User");
+ getHibernateTemplate().bulkUpdate("delete from Role");
+ getHibernateTemplate().flush();
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ try {
+ _projectSettings.configure("classpath:test/som.xml");
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find configuration file: ", e);
+ }
+ try {
+ /*
+ * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different
+ * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested
+ * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated
+ * with the session: [org.splat.dal.bo.kernel.Role#simer] at
+ * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at
+ * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at
+ * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at
+ * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at
+ * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
+ */
+ Database.getInstance().initialize();
+ getHibernateTemplate().flush();
+ } catch (DuplicateKeyException dke) {
+ Assert.fail(
+ "User creation failed during the database reconfiguration: "
+ + dke.getMessage(), dke);
+ }
+
+ KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase");
+ Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database.");
+ SimulationContextType prodtype = _simulationContextService.selectType("product");
+ Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database.");
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testDatabaseInitialize()");
+ }
}