import org.splat.dal.dao.kernel.UserDAO;
import org.splat.dal.dao.som.Database;
import org.splat.dal.dao.som.ScenarioDAO;
+import org.splat.dal.dao.som.StudyDAO;
import org.splat.exception.BusinessException;
import org.splat.i18n.I18nUtils;
import org.splat.kernel.InvalidPropertyException;
import org.splat.service.StudyService;
import org.splat.service.dto.DocumentDTO;
import org.splat.service.dto.FileDTO;
+import org.splat.service.dto.ScenarioDTO;
import org.splat.service.dto.StepDTO;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.service.technical.RepositoryService;
@Qualifier("studyService")
private transient StudyService _studyService;
+ /**
+ * The StudyDAO. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("studyDAO")
+ private transient StudyDAO _studyDAO;
+
/**
* Test of getting a scenario content for building siman-salome.conf.<BR>
* <B>Description :</B> <BR>
BusinessException {
LOG.debug(">>>>> BEGIN testCreateStudyFromPython()");
startNestedTransaction();
+
+ HibernateTemplate ht = getHibernateTemplate();
+
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ _projectSettings.configure("classpath:test/som.xml");
+
+ // Create a test user
+ User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
+ _userDAO.create(goodUser);
+ SimulationContextType prodtype = _simulationContextService
+ .selectType("product");
+ Assert
+ .assertNotNull(prodtype,
+ "Simulation context type 'product' must be created in the database.");
+
+ String productName = "New Test Product " + new Date().toString();
+
+ ht.flush();
+ ht.clear();
+ long studyId1 = _scenarioService.createStudy("goodUser",
+ "Test Study 1", productName, "Test description");
+ Assert.assertTrue(studyId1 > 0);
+
+ ht.flush();
+ ht.clear();
+ try {
+ _scenarioService.createStudy("badbadUser", "Test Study 2",
+ productName, "Test description");
+ Assert.fail("Study must not be created for not existing user.");
+ } catch (InvalidPropertyException ipe) {
+ LOG.debug("Expected exception: " + ipe.getMessage());
+ }
+
+ ht.flush();
+ ht.clear();
+ long studyId3 = _scenarioService.createStudy("goodUser",
+ "Test Study 3", productName, "Test description");
+ Assert.assertTrue(studyId3 > 0);
+
+ // Check that the simulation context is the same
+ Study study1 = _studyService.selectStudy(studyId1);
+ Study study3 = _studyService.selectStudy(studyId3);
+ Assert.assertEquals(study1.SimulationContextIterator().next(), study3
+ .SimulationContextIterator().next());
+
+ // Check the title of the created scenario
+ String scTitle = study1.getScenarii()[0].getTitle();
+ Assert.assertEquals(scTitle, I18nUtils
+ .getMessageLocaleDefault("label.scenario")
+ + " 1");
+ Assert.assertFalse(scTitle.equals("label.scenario 1"));
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testCreateStudyFromPython()");
+ }
+
+ /**
+ * Test study content copy.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create a study.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method for a not existing source study.</i><BR>
+ * <i>1. call the method for a not existing source scenario.</i><BR>
+ * <i>1. call the method for a not existing source study.</i><BR>
+ * <i>2. call the method for an existing username and an existing product.</i><BR>
+ * <i>3. call the method for a not existing username expecting an exception.</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>no input parameters</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>1: The new study must be created. The new product simulation context must be created.</li>
+ * <li>2: The new study must be created.</li>
+ * <li>3: The new study must not be created. Exception must be thrown.</li>
+ * </ul>
+ * </i>
+ *
+ * @throws IOException
+ * if application configuration loading is failed
+ * @throws SQLException
+ * if application configuration loading is failed
+ * @throws BusinessException
+ * if test data creation is failed
+ */
+ @Test(groups = { "study", "sevice", "functional", "business" })
+ public void testCopyStudyContent() throws IOException, SQLException,
+ BusinessException {
+ LOG.debug(">>>>> BEGIN testCopyStudyContent()");
+ startNestedTransaction();
HibernateTemplate ht = getHibernateTemplate();
Assert.assertFalse(scTitle.equals("label.scenario 1"));
rollbackNestedTransaction();
- LOG.debug(">>>>> END testCreateStudyFromPython()");
+ LOG.debug(">>>>> END testCopyStudyContent()");
}
/**
SQLException, BusinessException {
LOG.debug(">>>>> BEGIN testAssignStudyContextFromPython()");
startNestedTransaction();
-
+
HibernateTemplate ht = getHibernateTemplate();
-
+
Database.getInstance().reset();
_projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
_projectSettings.configure("classpath:test/som.xml");
-
+
// Create a test user
User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
_userDAO.create(goodUser);
Assert
.assertNotNull(prodtype,
"Simulation context type 'product' must be created in the database.");
-
+
String productName = "New Test Product " + new Date().toString();
-
+
ht.flush();
ht.clear();
long studyId1 = _scenarioService.createStudy("goodUser",
"Test Study 1", productName, "Test description");
Assert.assertTrue(studyId1 > 0);
-
+
ht.flush();
ht.clear();
-
+
// //////// START OF TESTS
// 1. call the method for not existing study id.</i><BR>
try {
} catch (InvalidPropertyException ipe) {
LOG.debug("Expected exception: " + ipe.getMessage());
}
-
+
// 2. call the method for not existing context type and context value.</i><BR>
_scenarioService.assignStudyContext(studyId1, "new context type",
"new context value");
-
+
ht.flush();
ht.clear();
-
+
// Check the assigned simulation context
checkCtx(studyId1, "new context type", "new context value");
-
+
// 3. call the method for existing context type and context value.</i><BR>
_scenarioService.assignStudyContext(studyId1, "new context type",
"new context value");
-
+
ht.flush();
ht.clear();
-
+
// Check the assigned simulation context
checkCtx(studyId1, "new context type", "new context value");
-
+
// 4. call the method for existing context type and not existing context value.</i><BR>
_scenarioService.assignStudyContext(studyId1, "new context type",
"new context value1");
-
+
ht.flush();
ht.clear();
-
+
// Check the assigned simulation context
checkCtx(studyId1, "new context type", "new context value1");
-
+
// 5. call the method for empty context type.</i><BR>
try {
_scenarioService.assignStudyContext(studyId1, "",
} catch (InvalidPropertyException ipe) {
LOG.debug("Expected exception: " + ipe.getMessage());
}
-
+
rollbackNestedTransaction();
LOG.debug(">>>>> END testAssignStudyContextFromPython()");
}
+ /**
+ * Test getting a study scenarios DTO list.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create a study and get its scenarios DTO list.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method for not existing study id.</i><BR>
+ * <i>2. call the method for a study with one scenario.</i><BR>
+ * <i>3. call the method for a study with several scenarios.</i><BR>
+ * <B>Test data : </B><BR>
+ * <i>no input parameters</i><BR>
+ *
+ * <B>Outcome results:</B><BR>
+ * <i>
+ * <ul>
+ * <li>1: The returned list of DTO must be empty.</li>
+ * <li>2: The returned list of DTO must contain one scenario DTO.</li>
+ * <li>3: The returned list of DTO must contain several scenario DTOs.</li>
+ * </ul>
+ * </i>
+ *
+ * @throws IOException
+ * if application configuration loading is failed
+ * @throws SQLException
+ * if application configuration loading is failed
+ * @throws BusinessException
+ * if test data creation is failed
+ */
+ @Test(groups = { "study", "sevice", "functional", "business" })
+ public void testGetStudyScenarios() throws IOException,
+ SQLException, BusinessException {
+ LOG.debug(">>>>> BEGIN testGetStudyScenarios()");
+ startNestedTransaction();
+
+ HibernateTemplate ht = getHibernateTemplate();
+
+ Database.getInstance().reset();
+ _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
+ _projectSettings.configure("classpath:test/som.xml");
+
+ // Create a test user
+ User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
+ _userDAO.create(goodUser);
+ Study study = TestEntitiesGenerator.getTestStudy(goodUser);
+ long studyId1 = _studyDAO.create(study);
+ ht.flush();
+ Scenario scen = TestEntitiesGenerator.getTestScenario(study, "test scen11");
+ long id11 = _scenarioDAO.create(scen);
+ ht.flush();
+ study = TestEntitiesGenerator.getTestStudy(goodUser);
+ long studyId2 = _studyDAO.create(study);
+ ht.flush();
+ scen = TestEntitiesGenerator.getTestScenario(study, "test scen21");
+ long id21 = _scenarioDAO.create(scen);
+ ht.flush();
+ scen = TestEntitiesGenerator.getTestScenario(study, "test scen22");
+ long id22 = _scenarioDAO.create(scen);
+ ht.flush();
+ scen = TestEntitiesGenerator.getTestScenario(study, "test scen23");
+ long id23 = _scenarioDAO.create(scen);
+ ht.flush();
+ ht.clear();
+
+ // //////// START OF TESTS
+ // 1. call the method for not existing study id.
+ List<ScenarioDTO> scens = _scenarioService.getStudyScenarios(-1L);
+
+ Assert.assertNotNull(scens);
+ Assert.assertTrue(scens.isEmpty());
+
+ // 2. call the method for a study with one scenario.
+ scens = _scenarioService.getStudyScenarios(studyId1);
+
+ ht.flush();
+ ht.clear();
+ Assert.assertNotNull(scens);
+ Assert.assertEquals(scens.size(), 1);
+ Assert.assertEquals(scens.get(0).getIndex().longValue(), id11);
+ Assert.assertEquals(scens.get(0).getTitle(), "test scen11");
+
+ // 3. call the method for a study with several scenarios.
+ scens = _scenarioService.getStudyScenarios(studyId2);
+ Assert.assertEquals(scens.size(), 3);
+ Assert.assertEquals(scens.get(0).getIndex().longValue(), id21);
+ Assert.assertEquals(scens.get(0).getTitle(), "test scen21");
+ Assert.assertEquals(scens.get(1).getIndex().longValue(), id22);
+ Assert.assertEquals(scens.get(1).getTitle(), "test scen22");
+ Assert.assertEquals(scens.get(2).getIndex().longValue(), id23);
+ Assert.assertEquals(scens.get(2).getTitle(), "test scen23");
+
+ ht.flush();
+ ht.clear();
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testGetStudyScenarios()");
+ }
+
/**
* Check if the context is assigned to the study.
*