1 /*****************************************************************************
5 * Creation date 12 Oct 2012
8 *****************************************************************************/
9 package test.splat.util;
11 import java.util.Date;
13 import org.splat.dal.bo.kernel.User;
14 import org.splat.dal.bo.som.KnowledgeElement;
15 import org.splat.dal.bo.som.KnowledgeElementType;
16 import org.splat.dal.bo.som.Scenario;
17 import org.splat.dal.bo.som.Study;
18 import org.splat.kernel.InvalidPropertyException;
19 import org.splat.kernel.MissedPropertyException;
20 import org.splat.kernel.MultiplyDefinedException;
21 import org.splat.log.AppLogger;
22 import org.splat.service.dto.KnowledgeElementDTO;
23 import org.splat.util.BeanHelper;
24 import org.testng.Assert;
25 import org.testng.annotations.Test;
27 import test.splat.common.BaseTest;
30 * Test class for DTOTransformer. <BR/> DTOTransformer is intended to be used by BeanHelper for transforming DTO to appropriate BO and vice
33 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
36 @Test(groups = { "util" })
37 public class TestDTOTransformer extends BaseTest {
40 * Logger for the class.
42 private static final AppLogger LOG = AppLogger
43 .getLogger(TestDTOTransformer.class);
46 * Test transforming a knowledge element to a DTO.<BR>
47 * <B>Description :</B> <BR>
48 * <i>Create a knowledge element BO and transform it to a DTO.</i><BR>
50 * <B>Outcome results:</B><BR>
53 * <li>DTO should be filled correctly including date, knoledge type and author properties<BR>
58 * @throws InvalidPropertyException
59 * if an invalid property is used when creating objects
60 * @throws MultiplyDefinedException
61 * when trying to create an object with already existing id
62 * @throws MissedPropertyException
63 * if a mandatory property is not defined for an object to be created
67 public void testBOtoDTO() throws InvalidPropertyException,
68 MissedPropertyException, MultiplyDefinedException {
69 LOG.debug(">>>>> BEGIN testBOtoDTO()");
71 KnowledgeElement aKelm = getKnowledgeElement();
72 KnowledgeElementDTO aDTO = BeanHelper.copyBean(aKelm,
73 KnowledgeElementDTO.class);
74 Assert.assertEquals(aDTO.getTitle(),
75 aKelm.getTitle(), "Titles are not equal.");
76 Assert.assertEquals(aDTO.getValue(),
77 aKelm.getValue(), "Values are not equal.");
79 .assertNotNull(aDTO.getAuthor(),
80 "Author property is not copied.");
82 .assertNotNull(aDTO.getAuthor().getRole(),
83 "Author.role property is not copied.");
84 Assert.assertEquals(aDTO.getAuthor().getName(),
85 aKelm.getAuthor().getName(), "Author names are not equal.");
86 Assert.assertNotNull(aDTO.getProgressState(),
87 "ProgressState property is not copied.");
88 Assert.assertEquals(aDTO.getProgressState(),
89 aKelm.getProgressState(), "Progress states are not equal.");
90 Assert.assertNotNull(aDTO.getType(), "Type property is not copied.");
91 Assert.assertEquals(aDTO.getType().getName(),
92 aKelm.getType().getName(), "Type names are not equal.");
93 Assert.assertEquals(aDTO.getAuthor().getRoleNames(),
94 aKelm.getAuthor().getRoleNames(), "Author role names are not equal.");
95 LOG.debug(">>>>> END testBOtoDTO()");
99 * Create a transient KnowledgeElement for tests.
101 * @return a transient KnowledgeElement
102 * @throws InvalidPropertyException
103 * if an invalid property is used when creating objects
104 * @throws MultiplyDefinedException
105 * when trying to create an object with already existing id
106 * @throws MissedPropertyException
107 * if a mandatory property is not defined for an object to be created
109 private KnowledgeElement getKnowledgeElement()
110 throws InvalidPropertyException, MissedPropertyException,
111 MultiplyDefinedException {
112 // Create a test knowledge type
114 KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
115 KnowledgeElementType aKType = new KnowledgeElementType("TST_kelmtype");
116 // Create a test user
117 User.Properties uprop = new User.Properties();
118 uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
119 .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
120 .addRole("TST_user").setMailAddress(
121 "noreply@salome-platform.org");
122 uprop.disableCheck();
123 User anAuthor = new User(uprop);
124 // Create a test study
125 Study.Properties stprops = new Study.Properties().setReference(
126 "TST_SID_01").setTitle("TST_Study").setManager(anAuthor);
127 Study aStudy = new Study(stprops);
128 // Create a test scenario
129 Scenario.Properties sprops = new Scenario.Properties().setTitle(
130 "TST_Study").setManager(anAuthor).setOwnerStudy(aStudy);
131 Scenario aScenario = new Scenario(sprops);
132 aStudy.getScenariiList().add(aScenario);
134 Date aDate = new Date();
136 // Prepare a knowledge element transient object
138 .setTitle("Test knowledge element")
140 .setOwnerScenario(aScenario)
144 "This is the test knowledge element.\nIt is created by the unit test.");
146 return new KnowledgeElement(kprops);