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
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.ProgressState;
19 import org.splat.dal.bo.som.Scenario;
20 import org.splat.dal.bo.som.SimulationContext;
21 import org.splat.dal.bo.som.Study;
22 import org.splat.exception.BusinessException;
23
24 /**
25  * Utility class for creating test entities.
26  */
27 public class TestEntitiesGenerator {
28
29         /**
30          * Create a transient user.
31          * 
32          * @param userName
33          *            the userName
34          * @return a transient StepCommentDTO
35          * @throws BusinessException
36          *             if something's wrong
37          */
38         public static User getTestUser(final String userName)
39                         throws BusinessException {
40
41                 User.Properties uprop = new User.Properties();
42                 uprop.setUsername(userName).setName("TST_Username").setFirstName(
43                                 "TST_FirstName").setDisplayName("TST_test.user")
44                                 .setMailAddress("noreply@salome-platform.org").addRole(
45                                                 "TST-User");
46                 uprop.disableCheck();
47                 User user = new User(uprop);
48                 return user;
49         }
50
51         /**
52          * Create a transient study.
53          * 
54          * @param user
55          *            the user that will be placed in 'manager' and 'actor' properties
56          * @return the test study
57          * @throws BusinessException
58          *             if something's wrong
59          */
60         public static Study getTestStudy(final User user) throws BusinessException {
61                 Study.Properties studyProps = new Study.Properties();
62                 studyProps.setActor(user).setManager(user)
63                                 .setTitle("a test study")
64                                 // .setDescription("description")
65                                 .setDate(new Date()).setReference("test reference")
66                                 .setSimulationContexts(new ArrayList<SimulationContext>())
67                                 .setState(ProgressState.inWORK);
68                 Study study = new Study(studyProps);
69                 return study;
70         }
71
72         /**
73          * Create a transient test scenario.
74          * 
75          * @param study
76          *            the owner study
77          * @return the created scenario
78          * @throws BusinessException
79          *             if creation is failed
80          */
81         public static Scenario getTestScenario(final Study study)
82                         throws BusinessException {
83                 Scenario.Properties sprops = new Scenario.Properties().setTitle(
84                                 "TST_Scenario").setManager(study.getAuthor()).setOwnerStudy(
85                                 study);
86                 Scenario aScenario = new Scenario(sprops);
87                 study.getScenariiList().add(aScenario);
88                 return aScenario;
89         }
90
91         /**
92          * Create a transient knowledge element.
93          * 
94          * @param scen
95          *            the owner scenario
96          * @param ktype
97          *            the knowledge type
98          * @param title
99          *            the knowledge title
100          * @return the created knowledge element
101          * @throws BusinessException
102          *             if creation is failed
103          */
104         public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
105                         final KnowledgeElementType ktype, final String title)
106                         throws BusinessException {
107
108                 KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
109                 Date aDate = new Date();
110
111                 kprops
112                                 .setTitle(title)
113                                 .setAuthor(scen.getAuthor())
114                                 .setOwnerScenario(scen)
115                                 .setType(ktype)
116                                 .setDate(aDate)
117                                 .setValue(
118                                                 "This is the test knowledge element.\nIt is created by the unit test.");
119
120                 return new KnowledgeElement(kprops);
121         }
122 }