<!-- <natural-id>-->
<property name="username" column="username" access="field" />
<many-to-one name="role" column="username" insert="false"
- update="false" unique="true" cascade="save-update" access="field" />
+ update="false" unique="true" cascade="merge,save-update" access="field" />
<property name="email" column="email" access="field" />
<!-- </natural-id>-->
import java.util.Map;
import java.util.Set;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
import org.splat.common.properties.MessageKeyEnum;
import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.kernel.Role;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
+import org.splat.dal.dao.kernel.RoleDAO;
import org.splat.dal.dao.kernel.UserDAO;
import org.splat.dal.dao.som.KnowledgeElementDAO;
import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
*/
private UserDAO _userDAO;
+ /**
+ * Injected role DAO.
+ */
+ private RoleDAO _roleDAO;
+
/**
* Injected knowledge element type DAO.
*/
KnowledgeElementType ucase = getKnowledgeElementTypeService()
.selectType("usecase");
KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
- User admin = getUserService().selectUser(1); // First user created when creating the database
+ // TODO: Get appropriate user by its role: UserService.getAdmin();
+ // User admin = getUserService().selectUser(1); // First user created when creating the database
+ Role adminRole = getRoleDAO().getFilteredList(
+ Restrictions.like("role", "%sysadmin%")).get(0);
+ User admin = getUserDAO().getFilteredList(
+ Restrictions.eq("role", adminRole), Order.asc("rid")).get(0); // First sysadmin in the database
+
kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
// knowledges
_documentTypeService = documentTypeService;
}
+ /**
+ * Get the roleDAO.
+ *
+ * @return the roleDAO
+ */
+ public RoleDAO getRoleDAO() {
+ return _roleDAO;
+ }
+
+ /**
+ * Set the roleDAO.
+ *
+ * @param roleDAO
+ * the roleDAO to set
+ */
+ public void setRoleDAO(final RoleDAO roleDAO) {
+ _roleDAO = roleDAO;
+ }
+
}
// 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);
+ nuser = getUserDAO().merge(nuser);
getUserDAO().saveOrUpdate(nuser);
//getUserDAO().create(nuser);
}
/**
- * Check if a file of the given format should be imported during check-in of a document of the given type.
+ * Check if a file of the given format should be imported during check-out of a document of the given type.
*
* @param type
* document type
* @return true if file should be imported
*/
public boolean doImport(final String type, final String format) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Do import for ("
+ + type
+ + ", "
+ + format
+ + "): "
+ + (_mapimport.containsKey(type) && _mapimport.get(type)
+ .contains(format)));
+ }
return (_mapimport.containsKey(type) && _mapimport.get(type).contains(
format));
}
<property name="knowledgeElementTypeService"
ref="knowledgeElementTypeService" />
<property name="userService" ref="userService" />
- <property name="userDAO" ref="userDAO" />
+ <property name="userDAO" ref="userDAO" />
+ <property name="roleDAO" ref="roleDAO" />
<property name="knowledgeElementTypeDAO"
ref="knowledgeElementTypeDAO" />
<property name="simulationContextService"
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.ProjectSettingsService.Step;
import org.springframework.beans.factory.annotation.Autowired;
@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>
startNestedTransaction();
// ///////////////////////////////////////////////////
// ////// Load good workflow customization
+ getHibernateTemplate().clear();
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
try {
_projectSettings.configure(ClassLoader.getSystemResource(
List<Step> steps = _projectSettings.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
}
steps = _projectSettings.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 {
/*
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 Role");
+ getHibernateTemplate().flush();
+ 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);
+ }
+ 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()");
+ }
}
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.kernel.NotApplicableException;
import org.splat.log.AppLogger;
import org.splat.service.DocumentTypeService;
+import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.PublicationService;
import org.splat.service.ScenarioService;
+import org.splat.service.SimulationContextService;
import org.splat.service.StepService;
import org.splat.service.dto.DocumentDTO;
import org.splat.service.dto.FileDTO;
@Qualifier("stepService")
private transient StepService _stepService;
+ /**
+ * The SimulationContextService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("simulationContextService")
+ private transient SimulationContextService _simulationContextService;
+
/**
* The ProjectSettingsService. Later injected by Spring.
*/
@Qualifier("documentTypeService")
private transient DocumentTypeService _documentTypeService;
+ /**
+ * The KnowledgeElementTypeService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("knowledgeElementTypeService")
+ private transient KnowledgeElementTypeService _knowledgeElementTypeService;
+
/**
* Test of getting a scenario content for building siman-salome.conf.<BR>
* <B>Description :</B> <BR>
return pub;
}
+
+
+ /**
+ * Test check-in scenario operation to be performed after SALOME session.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create a scenario and try to check-in it with some simulated SALOME results data.<BR>
+ * After check-in verify following points:
+ * <ul>
+ * <li>scenario is no more marked as checked out</li>
+ * <li>new document versions are created for checked in documents</li>
+ * <li>presentation of the previous version is removed</li>
+ * <li>uses relations are copied correctly</li>
+ * <li>files are moved correctly</li>
+ * <li>new documents are created for new data</li>
+ * <li>uses relations are created correctly</li>
+ * <li>files are moved correctly</li>
+ * </ul>
+ * </i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method for an existing scenario id.</i><BR>
+ * <i>2. call the method for a not existing scenario id.</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>no input parameters</i><BR>
+ * <i>no input parameters</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>New version of existing documents must be created and new documents must be imported for documents with zero id. Correct
+ * relations must be created.<BR>
+ * </li>
+ * <li>Exception is thrown<BR>
+ * </li>
+ * </ul>
+ * </i>
+ *
+ * @throws InvalidPropertyException
+ * if an invalid property is used when creating objects
+ * @throws MultiplyDefinedException
+ * when trying to create an object with already existing id
+ * @throws MissedPropertyException
+ * if a mandatory property is not defined for an object to be created
+ * @throws IOException
+ * if scenario creation is failed
+ * @throws SQLException
+ * if scenario creation is failed
+ * @throws NotApplicableException
+ * if checkin failed
+ * @throws MismatchException
+ * if checkin failed
+ */
+ @Test(groups = { "study", "sevice", "functional", "business" })
+ public void testCreateStudy() throws InvalidPropertyException,
+ MissedPropertyException, MultiplyDefinedException, IOException,
+ SQLException, MismatchException, NotApplicableException {
+ LOG.debug(">>>>> BEGIN testCreateStudy()");
+ startNestedTransaction();
+
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ _projectSettings.configure(ClassLoader
+ .getSystemResource("test/som.xml").getPath());
+
+ // Create a test user
+ User.Properties uprop = new User.Properties();
+ uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
+ .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
+ .addRole("TST_user").setMailAddress(
+ "noreply@salome-platform.org");
+ uprop.disableCheck();
+ User anAuthor = new User(uprop);
+
+ getHibernateTemplate().saveOrUpdate(anAuthor);
+ 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.");
+
+ // Create admin
+ uprop.clear();
+ uprop.setUsername("TST_Admin").setName("TST_SimanUnitTestsAdmin")
+ .setFirstName("TST_AdminFirstName").setDisplayName("TST_test.admin")
+ .addRole("TST_user,sysadmin").setMailAddress(
+ "noreply@salome-platform.org");
+ uprop.disableCheck();
+
+ getHibernateTemplate().saveOrUpdate(new User(uprop));
+ getHibernateTemplate().flush();
+
+ Study.Properties sprop = new Study.Properties();
+ sprop.setTitle("Test study creation").setManager(anAuthor);
+ Scenario.Properties oprop = new Scenario.Properties();
+ oprop.setTitle("Test scenario for the created study");
+
+ // Addition of the entered project context
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ // Input of new project context
+ cprop.setType(_simulationContextService.selectType("product"))
+ .setValue("Test Simulation Context: Product");
+ Study study = _scenarioService.createStudy(sprop, oprop, cprop);
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testCreateStudy()");
+ }
}
--- /dev/null
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="SimanCommonTests" verbose="1">
+ <test name="all">
+ <method-selectors>
+ <method-selector>
+ <script language="beanshell">
+ <![CDATA[
+ (groups.containsKey("study")) && method.getName().toUpperCase().startsWith("TEST")
+ ]]>
+ </script>
+ </method-selector>
+ </method-selectors>
+ <groups>
+ <!--
+ <define name="all">
+ <include name="business"/>
+ <include name="functional"/>
+ <include name="service"/>
+ </define>
+ <define name="new">
+ <include name="newservice"/>
+ </define>
+ <run>
+ <include name="all"/>
+ <exclude name="old"/>
+ </run>
+ -->
+
+ </groups>
+ <packages>
+ <package name="test.*" />
+ </packages>
+ </test>
+</suite>
connection.driver_class=com.p6spy.engine.spy.P6SpyDriver
# Hibernate config
-hibernate.hbm2ddl.auto=validate
+#hibernate.hbm2ddl.auto=validate
+hibernate.hbm2ddl.auto=update
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.current_session_context_class=thread