MultiplyDefinedException, RuntimeException {
User nuser = new User(uprop);
// Do merge to synchronize Role object with the current hibernate session
- // and to avoid th exception:
+ // and to avoid the exception:
// org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the
// session: [org.splat.dal.bo.kernel.Role#simer]
+ getUserDAO().merge(nuser);
getUserDAO().saveOrUpdate(nuser);
//getUserDAO().create(nuser);
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
* @see test.areva.hewis.mlst2.service.gpao.rpta.TaBaseService#rollbackNestedTransaction()
*/
protected void startNestedTransaction() {
- DataSourceTransactionManager txManager =
- (DataSourceTransactionManager) applicationContext.getBean("txManager");
+ AbstractPlatformTransactionManager txManager =
+ (AbstractPlatformTransactionManager) applicationContext.getBean("txManager");
DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();
txDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
* @see test.areva.hewis.mlst2.service.gpao.rpta.TaBaseService#startNestedTransaction()
*/
protected void rollbackNestedTransaction() {
- DataSourceTransactionManager txManager =
- (DataSourceTransactionManager) applicationContext.getBean("txManager");
+ AbstractPlatformTransactionManager txManager =
+ (AbstractPlatformTransactionManager) applicationContext.getBean("txManager");
txManager.rollback(_nestedTxStatus);
}
public void testCreate() throws InvalidPropertyException,
MissedPropertyException, MultiplyDefinedException {
LOG.debug(">>>>> BEGIN testCreate()");
-
+ startNestedTransaction();
+
KnowledgeElement aKelm = getKnowledgeElement();
// Call DAO's create method for a good transient knowledge element.
Long id = _knowledgeElementDAO.create(aKelm);
LOG.debug("Expected exception is thrown: "
+ e.getClass().getSimpleName() + ": " + e.getMessage());
}
+
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testCreate()");
}
public void testGet() throws InvalidPropertyException,
MissedPropertyException, MultiplyDefinedException {
LOG.debug(">>>>> BEGIN testGet()");
+ startNestedTransaction();
+
KnowledgeElement aKelm = getKnowledgeElement();
// Call DAO's create method for a good transient knowledge element.
Long id = _knowledgeElementDAO.create(aKelm);
LOG.debug("Expected exception is thrown: "
+ e.getClass().getSimpleName() + ": " + e.getMessage());
}
+
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testGet()");
}
public void testUpdate() throws InvalidPropertyException,
MissedPropertyException, MultiplyDefinedException {
LOG.debug(">>>>> BEGIN testUpdate()");
+ startNestedTransaction();
+
KnowledgeElement aKelm = getKnowledgeElement();
// Call DAO's create method for a good transient knowledge element.
Long id = _knowledgeElementDAO.create(aKelm);
LOG.debug("Expected exception is thrown: "
+ e.getClass().getSimpleName() + ": " + e.getMessage());
}
+
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testUpdate()");
}
public void testDelete() throws InvalidPropertyException,
MissedPropertyException, MultiplyDefinedException {
LOG.debug(">>>>> BEGIN testDelete()");
+ startNestedTransaction();
+
KnowledgeElement aKelm = getKnowledgeElement();
// Call DAO's create method for a good transient knowledge element.
Long id = _knowledgeElementDAO.create(aKelm);
LOG.debug("Expected exception is thrown: "
+ e.getClass().getSimpleName() + ": " + e.getMessage());
}
+
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testDelete()");
}
* @param anExpected
* the expected object
*/
- private void compareObjects(KnowledgeElement anActual,
- KnowledgeElement anExpected) {
+ private void compareObjects(final KnowledgeElement anActual,
+ final KnowledgeElement anExpected) {
Assert.assertNotNull(anActual,
"Created object is not found in the database.");
Assert.assertEquals(anActual.getAuthor(), anExpected.getAuthor(),
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;
*/
@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
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
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
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ try {
+ _projectSettings.configure(ClassLoader.getSystemResource(
+ "test/som.xml").getPath());
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find configuration file: ", e);
+ }
+
+ List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertTrue(steps.size() > 0, "No steps are created.");
+
+ // /////////////////////////////////////////////////////////
+ // ////// Test reconfiguration attempt
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ try {
+ _projectSettings.configure(ClassLoader.getSystemResource(
+ "test/som.xml").getPath());
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find configuration file: ", e);
+ }
+ steps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertTrue(steps.size() > 0, "No steps are created.");
+
+ 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()");
+ }
}
MissedPropertyException, MultiplyDefinedException, IOException,
SQLException {
LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
+ startNestedTransaction();
+
long scenarioId = createScenario();
// Call DAO's create method for a good transient knowledge element.
List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
}
} else { // Outdated
Assert.assertEquals(file.getState(), 'O',
- "File state must be actual ('O').");
+ "File state must be outdated ('O').");
Assert
.assertEquals(file.getProcessing(),
"file-download",
LOG.debug("Expected exception is thrown: "
+ e.getClass().getSimpleName() + ": " + e.getMessage());
}
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testGetScenarioInfo()");
}
MissedPropertyException, MultiplyDefinedException, IOException,
SQLException, MismatchException, NotApplicableException {
LOG.debug(">>>>> BEGIN testCheckin()");
+ startNestedTransaction();
+
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
_projectSettings.configure(ClassLoader
.getSystemResource("test/som.xml").getPath());
+ getHibernateTemplate().flush();
long scenarioId = createScenario();
Scenario aScen = _scenarioDAO.get(scenarioId);
User user = aScen.getAuthor();
LOG.debug("Expected exception is thrown: "
+ e.getClass().getSimpleName() + ": " + e.getMessage());
}
-
+
+ rollbackNestedTransaction();
LOG.debug(">>>>> END testCheckin()");
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
- <!-- <bean id="simanDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="jndiName" value="jdbc/ibatis"/>
- </bean> -->
+ <!-- <bean id="simanDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+ <property name="jndiName" value="jdbc/ibatis"/>
+ </bean> -->
- <!-- <bean id="simanDatasource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName"
- value="${connection.driver_class}" />
- <property name="url" value="${connection.url}" />
- <property name="username" value="${connection.username}" />
- <property name="password" value="${connection.password}" />
- </bean>
- -->
+ <bean id="simanDatasource"
+ class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName"
+ value="${connection.driver_class}" />
+ <property name="url" value="${connection.url}" />
+ <property name="username" value="${connection.username}" />
+ <property name="password" value="${connection.password}" />
+ </bean>
- <bean id="simanDatasource"
- class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
- <property name="driverClassName"
- value="${connection.driver_class}" />
- <property name="url" value="${connection.url}" />
- <property name="username" value="${connection.username}" />
- <property name="password" value="${connection.password}" />
- <property name="suppressClose" value="true" />
- <property name="autoCommit" value="false" />
- </bean>
+ <!-- <bean id="simanDatasource"
+ class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
+ <property name="driverClassName"
+ value="${connection.driver_class}" />
+ <property name="url" value="${connection.url}" />
+ <property name="username" value="${connection.username}" />
+ <property name="password" value="${connection.password}" />
+ <property name="suppressClose" value="true" />
+ <property name="autoCommit" value="false" />
+ </bean>-->
- <bean id="p6spySimanDatasource"
- class="com.p6spy.engine.spy.P6DataSource">
- <constructor-arg>
- <ref local="simanDatasource" />
- </constructor-arg>
- </bean>
+ <bean id="p6spySimanDatasource"
+ class="com.p6spy.engine.spy.P6DataSource">
+ <constructor-arg>
+ <ref local="simanDatasource" />
+ </constructor-arg>
+ </bean>
- <bean id="hibernateProperties"
- class="org.springframework.beans.factory.config.PropertiesFactoryBean">
- <property name="properties">
- <props>
- <!-- normal properties -->
- </props>
- </property>
- <!-- hibernate.config should be defined somewhere in the spring.properties layers -->
- <property name="locations">
- <list>
- <value>classpath:test/${hibernate.config.file}</value>
- </list>
- </property>
- </bean>
+ <bean id="hibernateProperties"
+ class="org.springframework.beans.factory.config.PropertiesFactoryBean">
+ <property name="properties">
+ <props>
+ <!-- normal properties -->
+ </props>
+ </property>
+ <!-- hibernate.config should be defined somewhere in the spring.properties layers -->
+ <property name="locations">
+ <list>
+ <value>classpath:test/${hibernate.config.file}</value>
+ </list>
+ </property>
+ </bean>
- <bean id="simanSessionFactory"
- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="dataSource" ref="simanDatasource" />
- <property name="mappingResources">
- <list>
- <value>
- org/splat/dal/bo/kernel/Persistent.hbm.xml
- </value>
- <value>org/splat/dal/bo/kernel/Any.hbm.xml</value>
- <value>org/splat/dal/bo/kernel/Entity.hbm.xml</value>
- <value>org/splat/dal/bo/kernel/Attribute.hbm.xml</value>
- <value>org/splat/dal/bo/kernel/Relation.hbm.xml</value>
- <value>
- org/splat/dal/bo/kernel/TextAttribute.hbm.xml
- </value>
- <value>org/splat/dal/bo/kernel/User.hbm.xml</value>
+ <bean id="simanSessionFactory"
+ class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <property name="dataSource" ref="simanDatasource" />
+ <property name="mappingResources">
+ <list>
+ <value>
+ org/splat/dal/bo/kernel/Persistent.hbm.xml
+ </value>
+ <value>org/splat/dal/bo/kernel/Any.hbm.xml</value>
+ <value>org/splat/dal/bo/kernel/Entity.hbm.xml</value>
+ <value>org/splat/dal/bo/kernel/Attribute.hbm.xml</value>
+ <value>org/splat/dal/bo/kernel/Relation.hbm.xml</value>
+ <value>
+ org/splat/dal/bo/kernel/TextAttribute.hbm.xml
+ </value>
+ <value>org/splat/dal/bo/kernel/User.hbm.xml</value>
- <value>
- org/splat/dal/bo/som/ProjectElement.hbm.xml
- </value>
- <value>org/splat/dal/bo/som/Study.hbm.xml</value>
- <value>org/splat/dal/bo/som/Scenario.hbm.xml</value>
- <value>org/splat/dal/bo/som/Attributes.hbm.xml</value>
- <value>org/splat/dal/bo/som/Relations.hbm.xml</value>
- <value>org/splat/dal/bo/som/File.hbm.xml</value>
- <value>org/splat/dal/bo/som/Document.hbm.xml</value>
- <value>org/splat/dal/bo/som/Publication.hbm.xml</value>
- <value>
- org/splat/dal/bo/som/ValidationCycle.hbm.xml
- </value>
- <value>org/splat/dal/bo/som/Timestamp.hbm.xml</value>
- <value>
- org/splat/dal/bo/som/SimulationContext.hbm.xml
- </value>
- <value>
- org/splat/dal/bo/som/KnowledgeElement.hbm.xml
- </value>
- <value>org/splat/dal/bo/som/IDBuilder.hbm.xml</value>
- </list>
- </property>
- <!-- hibernate.connection.driver_class=com.p6spy.engine.spy.P6SpyDriver -->
+ <value>
+ org/splat/dal/bo/som/ProjectElement.hbm.xml
+ </value>
+ <value>org/splat/dal/bo/som/Study.hbm.xml</value>
+ <value>org/splat/dal/bo/som/Scenario.hbm.xml</value>
+ <value>org/splat/dal/bo/som/Attributes.hbm.xml</value>
+ <value>org/splat/dal/bo/som/Relations.hbm.xml</value>
+ <value>org/splat/dal/bo/som/File.hbm.xml</value>
+ <value>org/splat/dal/bo/som/Document.hbm.xml</value>
+ <value>org/splat/dal/bo/som/Publication.hbm.xml</value>
+ <value>
+ org/splat/dal/bo/som/ValidationCycle.hbm.xml
+ </value>
+ <value>org/splat/dal/bo/som/Timestamp.hbm.xml</value>
+ <value>
+ org/splat/dal/bo/som/SimulationContext.hbm.xml
+ </value>
+ <value>
+ org/splat/dal/bo/som/KnowledgeElement.hbm.xml
+ </value>
+ <value>org/splat/dal/bo/som/IDBuilder.hbm.xml</value>
+ </list>
+ </property>
+ <!-- hibernate.connection.driver_class=com.p6spy.engine.spy.P6SpyDriver -->
- <property name="hibernateProperties">
- <ref local="hibernateProperties" />
- </property>
- <!-- The following property is used temporary to be able to manage transactions manually. -->
- <!-- TODO: use annotations to mark transaction methods
- instead of programmatic transaction management -->
-<!-- <property name="exposeTransactionAwareSessionFactory">
- <value>false</value>
- </property>-->
-<!-- <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />-->
- </bean>
+ <property name="hibernateProperties">
+ <ref local="hibernateProperties" />
+ </property>
+ <!-- The following property is used temporary to be able to manage transactions manually. -->
+ <!-- TODO: use annotations to mark transaction methods
+ instead of programmatic transaction management -->
+ <!-- <property name="exposeTransactionAwareSessionFactory">
+ <value>false</value>
+ </property>-->
+ <!-- <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />-->
+ </bean>
- <bean id="txManager"
- class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="simanSessionFactory" />
- </bean>
+ <bean id="txManager"
+ class="org.springframework.orm.hibernate3.HibernateTransactionManager">
+ <property name="sessionFactory" ref="simanSessionFactory" />
+ <property name="nestedTransactionAllowed" value="true" />
+ </bean>
- <tx:annotation-driven transaction-manager="txManager" />
+ <tx:annotation-driven transaction-manager="txManager" />
</beans>