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.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;
25 * Utility class for creating test entities.
27 public class TestEntitiesGenerator {
30 * Create a transient user.
34 * @return a transient StepCommentDTO
35 * @throws BusinessException
36 * if something's wrong
38 public static User getTestUser(final String userName)
39 throws BusinessException {
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(
47 User user = new User(uprop);
52 * Create a transient study.
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
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);
73 * Create a transient test scenario.
77 * @return the created scenario
78 * @throws BusinessException
79 * if creation is failed
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(
86 Scenario aScenario = new Scenario(sprops);
87 study.getScenariiList().add(aScenario);
92 * Create a transient knowledge element.
100 * @return the created knowledge element
101 * @throws BusinessException
102 * if creation is failed
104 public static KnowledgeElement getTestKnowledgeElement(final Scenario scen,
105 final KnowledgeElementType ktype, final String title)
106 throws BusinessException {
108 KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
109 Date aDate = new Date();
113 .setAuthor(scen.getAuthor())
114 .setOwnerScenario(scen)
118 "This is the test knowledge element.\nIt is created by the unit test.");
120 return new KnowledgeElement(kprops);