]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/test/splat/util/TestEntitiesGenerator.java
Salome HOME
Search knowledge is implemented. Unit tests are improved. Lucene index is not used...
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / util / TestEntitiesGenerator.java
index 95783bd4915d95889457d0f86fab51a0e3a1ddcd..7e8c9f3e11fd710802b679e30d00e6b0d00a983f 100644 (file)
@@ -7,13 +7,16 @@
  * @version        $Revision$
  *****************************************************************************/
 
-package test.splat.util; 
+package test.splat.util;
 
 import java.util.ArrayList;
 import java.util.Date;
 
 import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.exception.BusinessException;
@@ -22,23 +25,24 @@ import org.splat.exception.BusinessException;
  * Utility class for creating test entities.
  */
 public class TestEntitiesGenerator {
-       
+
        /**
         * Create a transient user.
-        *
-        * @param userName the userName
+        * 
+        * @param userName
+        *            the userName
         * @return a transient StepCommentDTO
-        * @throws BusinessException if something's wrong
+        * @throws BusinessException
+        *             if something's wrong
         */
-       public static User getTestUser(final String userName) throws BusinessException {
+       public static User getTestUser(final String userName)
+                       throws BusinessException {
 
                User.Properties uprop = new User.Properties();
-               uprop.setUsername(userName)
-                               .setName("TST_Username")
-                               .setFirstName("TST_FirstName")
-                               .setDisplayName("TST_test.user")
-                               .setMailAddress("noreply@salome-platform.org")
-                               .addRole("TST-User");
+               uprop.setUsername(userName).setName("TST_Username").setFirstName(
+                               "TST_FirstName").setDisplayName("TST_test.user")
+                               .setMailAddress("noreply@salome-platform.org").addRole(
+                                               "TST-User");
                uprop.disableCheck();
                User user = new User(uprop);
                return user;
@@ -46,22 +50,73 @@ public class TestEntitiesGenerator {
 
        /**
         * Create a transient study.
-        *
-        * @param user the user that will be placed in 'manager' and 'actor' properties
+        * 
+        * @param user
+        *            the user that will be placed in 'manager' and 'actor' properties
         * @return the test study
-        * @throws BusinessException if something's wrong
+        * @throws BusinessException
+        *             if something's wrong
         */
-       public static Study getTestStudy(final User user) throws BusinessException{
+       public static Study getTestStudy(final User user) throws BusinessException {
                Study.Properties studyProps = new Study.Properties();
-               studyProps.setActor(user)
-                               .setManager(user)
+               studyProps.setActor(user).setManager(user)
                                .setTitle("a test study")
-                               //.setDescription("description")
-                               .setDate(new Date())
-                               .setReference("test reference")
+                               // .setDescription("description")
+                               .setDate(new Date()).setReference("test reference")
                                .setSimulationContexts(new ArrayList<SimulationContext>())
                                .setState(ProgressState.inWORK);
                Study study = new Study(studyProps);
                return study;
        }
+
+       /**
+        * Create a transient test scenario.
+        * 
+        * @param study
+        *            the owner study
+        * @return the created scenario
+        * @throws BusinessException
+        *             if creation is failed
+        */
+       public static Scenario getTestScenario(final Study study)
+                       throws BusinessException {
+               Scenario.Properties sprops = new Scenario.Properties().setTitle(
+                               "TST_Scenario").setManager(study.getAuthor()).setOwnerStudy(
+                               study);
+               Scenario aScenario = new Scenario(sprops);
+               study.getScenariiList().add(aScenario);
+               return aScenario;
+       }
+
+       /**
+        * Create a transient knowledge element.
+        * 
+        * @param scen
+        *            the owner scenario
+        * @param ktype
+        *            the knowledge type
+        * @param title
+        *            the knowledge title
+        * @return the created knowledge element
+        * @throws BusinessException
+        *             if creation is failed
+        */
+       public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
+                       final KnowledgeElementType ktype, final String title)
+                       throws BusinessException {
+
+               KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
+               Date aDate = new Date();
+
+               kprops
+                               .setTitle(title)
+                               .setAuthor(scen.getAuthor())
+                               .setOwnerScenario(scen)
+                               .setType(ktype)
+                               .setDate(aDate)
+                               .setValue(
+                                               "This is the test knowledge element.\nIt is created by the unit test.");
+
+               return new KnowledgeElement(kprops);
+       }
 }