]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/test/splat/util/TestEntitiesGenerator.java
Salome HOME
The draft of the "Copy from existing study" action is added. The YACS step is introdu...
[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).setTitle("a test study")
62                                 // .setDescription("description")
63                                 .setDate(new Date()).setReference("test reference")
64                                 .setSimulationContexts(new ArrayList<SimulationContext>());
65                 Study study = new Study(studyProps);
66                 return study;
67         }
68
69         /**
70          * Create a transient test scenario.
71          * 
72          * @param study
73          *            the owner study
74          * @return the created scenario
75          * @throws BusinessException
76          *             if creation is failed
77          */
78         public static Scenario getTestScenario(final Study study)
79                         throws BusinessException {
80                 return getTestScenario(study, "TST_Scenario");
81         }
82
83         /**
84          * Create a transient test scenario.
85          * 
86          * @param title
87          *            the scenario title
88          * @param study
89          *            the owner study
90          * @return the created scenario
91          * @throws BusinessException
92          *             if creation is failed
93          */
94         public static Scenario getTestScenario(final Study study, final String title)
95                         throws BusinessException {
96                 Scenario.Properties sprops = new Scenario.Properties().setTitle(title)
97                                 .setManager(study.getAuthor()).setOwnerStudy(study);
98                 Scenario aScenario = new Scenario(sprops);
99                 study.getScenariiList().add(aScenario);
100                 return aScenario;
101         }
102
103         /**
104          * Create a transient knowledge element.
105          * 
106          * @param scen
107          *            the owner scenario
108          * @param ktype
109          *            the knowledge type
110          * @param title
111          *            the knowledge title
112          * @return the created knowledge element
113          * @throws BusinessException
114          *             if creation is failed
115          */
116         public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
117                         final KnowledgeElementType ktype, final String title)
118                         throws BusinessException {
119
120                 KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
121                 Date aDate = new Date();
122
123                 kprops
124                                 .setTitle(title)
125                                 .setAuthor(scen.getAuthor())
126                                 .setOwnerScenario(scen)
127                                 .setType(ktype)
128                                 .setDate(aDate)
129                                 .setValue(
130                                                 "This is the test knowledge element.\nIt is created by the unit test.");
131
132                 return new KnowledgeElement(kprops);
133         }
134 }