From: rkv Date: Mon, 11 Mar 2013 10:31:29 +0000 (+0000) Subject: Added tests for the new createStudy method which has been added for calling from... X-Git-Tag: Root_Delivery2_2013_04_22~113 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=01bdc9db606549aaffeb7008459ec9ac67f8890d;p=tools%2Fsiman.git Added tests for the new createStudy method which has been added for calling from Python. --- diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index 9afe64a..7661d62 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -34,8 +34,10 @@ 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.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; @@ -48,6 +50,7 @@ import org.splat.service.PublicationService; 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; @@ -62,6 +65,7 @@ import org.testng.annotations.Test; import org.testng.reporters.Files; import test.splat.common.BaseTest; +import test.splat.util.TestEntitiesGenerator; /** * Test class for ScenarioService. @@ -140,6 +144,20 @@ public class TestScenarioService extends BaseTest { @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.
* Description :
@@ -1008,58 +1026,35 @@ public class TestScenarioService extends BaseTest { } /** - * Test check-in scenario operation to be performed after SALOME session.
+ * Test study creation.
* Description :
- * Create a scenario and try to check-in it with some simulated SALOME results data.
- * After check-in verify following points: - * - *

+ * Create a study.
* Action :
- * 1. call the method for an existing scenario id.
- * 2. call the method for a not existing scenario id.
+ * 1. call the method for a not existing product.
+ * 2. call the method for an existing username and an existing product.
+ * 3. call the method for a not existing username expecting an exception.
* Test data :
* no input parameters
- * no input parameters
* * Outcome results:
* * * * - * @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(); @@ -1111,7 +1106,84 @@ public class TestScenarioService extends BaseTest { .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.
+ * Description :
+ * Create a study.
+ * Action :
+ * 1. call the method for a not existing product.
+ * 2. call the method for an existing username and an existing product.
+ * 3. call the method for a not existing username expecting an exception.
+ * Test data :
+ * no input parameters
+ * + * Outcome results:
+ * + * + * + * + * @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()"); + } }