1 /*****************************************************************************
5 * Creation date Feb 12, 2013
8 *****************************************************************************/
10 package test.splat.util;
12 import java.util.ArrayList;
13 import java.util.Date;
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;
24 * Utility class for creating test entities.
26 public class TestEntitiesGenerator {
29 * Create a transient user.
33 * @return a transient StepCommentDTO
34 * @throws BusinessException
35 * if something's wrong
37 public static User getTestUser(final String userName)
38 throws BusinessException {
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(
46 User user = new User(uprop);
51 * Create a transient study.
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
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);
70 * Create a transient test scenario.
74 * @return the created scenario
75 * @throws BusinessException
76 * if creation is failed
78 public static Scenario getTestScenario(final Study study)
79 throws BusinessException {
80 return getTestScenario(study, "TST_Scenario");
84 * Create a transient test scenario.
90 * @return the created scenario
91 * @throws BusinessException
92 * if creation is failed
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);
104 * Create a transient knowledge element.
111 * the knowledge title
112 * @return the created knowledge element
113 * @throws BusinessException
114 * if creation is failed
116 public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
117 final KnowledgeElementType ktype, final String title)
118 throws BusinessException {
120 KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
121 Date aDate = new Date();
125 .setAuthor(scen.getAuthor())
126 .setOwnerScenario(scen)
130 "This is the test knowledge element.\nIt is created by the unit test.");
132 return new KnowledgeElement(kprops);