import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.bo.som.Document.Properties;
+import org.splat.dal.dao.kernel.UserDAO;
import org.splat.dal.dao.som.Database;
import org.splat.dal.dao.som.ScenarioDAO;
+import org.splat.exception.BusinessException;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MismatchException;
import org.splat.kernel.MissedPropertyException;
import org.splat.service.ScenarioService;
import org.splat.service.SimulationContextService;
import org.splat.service.StepService;
+import org.splat.service.StudyService;
import org.splat.service.dto.DocumentDTO;
import org.splat.service.dto.FileDTO;
import org.splat.service.dto.StepDTO;
import org.testng.reporters.Files;
import test.splat.common.BaseTest;
+import test.splat.util.TestEntitiesGenerator;
/**
* Test class for ScenarioService.
@Qualifier("knowledgeElementTypeService")
private transient KnowledgeElementTypeService _knowledgeElementTypeService;
+ /**
+ * The UserDAO. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("userDAO")
+ private transient UserDAO _userDAO;
+
+ /**
+ * The StudyService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("studyService")
+ private transient StudyService _studyService;
+
/**
* Test of getting a scenario content for building siman-salome.conf.<BR>
* <B>Description :</B> <BR>
}
/**
- * Test check-in scenario operation to be performed after SALOME session.<BR>
+ * Test study creation.<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>
+ * <i>Create a study.</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>
+ * <i>1. call the method for a not existing product.</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>
- * <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>
+ * <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 is thrown.</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
+ * if application configuration loading is failed
* @throws SQLException
- * if scenario creation is failed
- * @throws NotApplicableException
- * if checkin failed
- * @throws MismatchException
- * if checkin failed
+ * if application configuration loading is failed
+ * @throws BusinessException
+ * if test data creation is failed
*/
@Test(groups = { "study", "sevice", "functional", "business" })
- public void testCreateStudy() throws InvalidPropertyException,
- MissedPropertyException, MultiplyDefinedException, IOException,
- SQLException, MismatchException, NotApplicableException {
+ public void testCreateStudy() throws BusinessException, IOException,
+ SQLException {
LOG.debug(">>>>> BEGIN testCreateStudy()");
startNestedTransaction();
.setValue("Test Simulation Context: Product");
Study study = _scenarioService.createStudy(sprop, oprop, cprop);
+ Assert.assertNotNull(study);
+ Assert.assertTrue(study.getIndex() > 0);
+
rollbackNestedTransaction();
LOG.debug(">>>>> END testCreateStudy()");
}
+
+ /**
+ * Test study creation.<BR>
+ * <B>Description :</B> <BR>
+ * <i>Create a study.</i><BR>
+ * <B>Action : </B><BR>
+ * <i>1. call the method for a not existing product.</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 is 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 testCreateStudyFromPython() throws IOException, SQLException,
+ BusinessException {
+ LOG.debug(">>>>> BEGIN testCreateStudyFromPython()");
+ 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 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();
+ long studyId1 = _scenarioService.createStudy("goodUser",
+ "Test Study 1", productName, "Test description");
+ Assert.assertTrue(studyId1 > 0);
+
+ 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());
+ }
+
+ 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());
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testCreateStudyFromPython()");
+ }
}