]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/test/splat/util/TestEntitiesGenerator.java
Salome HOME
Fix for scenario label when creating a new study from Python.
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / util / TestEntitiesGenerator.java
1 /*****************************************************************************
2  * Company         EURIWARE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   Feb 12, 2013
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9
10 package test.splat.util;
11
12 import java.util.ArrayList;
13 import java.util.Date;
14
15 import org.splat.dal.bo.kernel.User;
16 import org.splat.dal.bo.som.KnowledgeElement;
17 import org.splat.dal.bo.som.KnowledgeElementType;
18 import org.splat.dal.bo.som.Scenario;
19 import org.splat.dal.bo.som.SimulationContext;
20 import org.splat.dal.bo.som.Study;
21 import org.splat.exception.BusinessException;
22
23 /**
24  * Utility class for creating test entities.
25  */
26 public class TestEntitiesGenerator {
27
28         /**
29          * Create a transient user.
30          * 
31          * @param userName
32          *            the userName
33          * @return a transient StepCommentDTO
34          * @throws BusinessException
35          *             if something's wrong
36          */
37         public static User getTestUser(final String userName)
38                         throws BusinessException {
39
40                 User.Properties uprop = new User.Properties();
41                 uprop.setUsername(userName).setName("TST_Username").setFirstName(
42                                 "TST_FirstName").setDisplayName("TST_test.user")
43                                 .setMailAddress("noreply@salome-platform.org").addRole(
44                                                 "TST-User");
45                 uprop.disableCheck();
46                 User user = new User(uprop);
47                 return user;
48         }
49
50         /**
51          * Create a transient study.
52          * 
53          * @param user
54          *            the user that will be placed in 'manager' and 'actor' properties
55          * @return the test study
56          * @throws BusinessException
57          *             if something's wrong
58          */
59         public static Study getTestStudy(final User user) throws BusinessException {
60                 Study.Properties studyProps = new Study.Properties();
61                 studyProps.setActor(user).setManager(user)
62                                 .setTitle("a test study")
63                                 // .setDescription("description")
64                                 .setDate(new Date()).setReference("test reference")
65                                 .setSimulationContexts(new ArrayList<SimulationContext>());
66                 Study study = new Study(studyProps);
67                 return study;
68         }
69
70         /**
71          * Create a transient test scenario.
72          * 
73          * @param study
74          *            the owner study
75          * @return the created scenario
76          * @throws BusinessException
77          *             if creation is failed
78          */
79         public static Scenario getTestScenario(final Study study)
80                         throws BusinessException {
81                 Scenario.Properties sprops = new Scenario.Properties().setTitle(
82                                 "TST_Scenario").setManager(study.getAuthor()).setOwnerStudy(
83                                 study);
84                 Scenario aScenario = new Scenario(sprops);
85                 study.getScenariiList().add(aScenario);
86                 return aScenario;
87         }
88
89         /**
90          * Create a transient knowledge element.
91          * 
92          * @param scen
93          *            the owner scenario
94          * @param ktype
95          *            the knowledge type
96          * @param title
97          *            the knowledge title
98          * @return the created knowledge element
99          * @throws BusinessException
100          *             if creation is failed
101          */
102         public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
103                         final KnowledgeElementType ktype, final String title)
104                         throws BusinessException {
105
106                 KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
107                 Date aDate = new Date();
108
109                 kprops
110                                 .setTitle(title)
111                                 .setAuthor(scen.getAuthor())
112                                 .setOwnerScenario(scen)
113                                 .setType(ktype)
114                                 .setDate(aDate)
115                                 .setValue(
116                                                 "This is the test knowledge element.\nIt is created by the unit test.");
117
118                 return new KnowledgeElement(kprops);
119         }
120 }