--- /dev/null
+/*
+ * (C) 2015 EDF
+ */
+package com.edf.gde.test.dao;
+
+import com.edf.gde.dao.ProfileDaoClient;
+import com.edf.gde.test.base.BaseTest;
+import com.edf.gde.transferables.ProfileAttributeTO;
+import com.edf.gde.transferables.ProfileTO;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.Assert;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author mordicus
+ */
+public class ProfileDaoTest extends BaseTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testCreateProfile() throws Exception {
+ testName("createProfile");
+ ProfileDaoClient daoClient = new ProfileDaoClient();
+ ProfileTO profileTO = new ProfileTO();
+ Assert.assertEquals(0, profileTO.getId());
+ profileTO.setName("ProfileTest1");
+ ProfileTO newProfileTO = daoClient.createProfile(profileTO);
+ Assert.assertNotNull(newProfileTO);
+ Assert.assertTrue(newProfileTO.getId() != 0);
+ Assert.assertEquals("ProfileTest1", newProfileTO.getName());
+ passed();
+ }
+
+ @Test
+ public void testDeleteProfile() throws Exception {
+ testName("deleteProfile");
+ ProfileDaoClient daoClient = new ProfileDaoClient();
+ ProfileTO profileTO = new ProfileTO();
+ Assert.assertEquals(0, profileTO.getId());
+ profileTO.setName("ProfileTest2");
+ ProfileTO newProfileTO = daoClient.createProfile(profileTO);
+ Assert.assertNotNull(newProfileTO);
+ Assert.assertTrue(newProfileTO.getId() != 0);
+ Assert.assertEquals("ProfileTest2", newProfileTO.getName());
+ daoClient.deleteProfile(newProfileTO.getId());
+ passed();
+ }
+
+ @Test
+ public void testReadProfile() throws Exception {
+ testName("readProfile");
+ ProfileDaoClient daoClient = new ProfileDaoClient();
+ ProfileTO profileTO = new ProfileTO();
+ Assert.assertEquals(0, profileTO.getId());
+ profileTO.setName("ProfileTest3");
+ ProfileTO newProfileTO = daoClient.createProfile(profileTO);
+ Assert.assertNotNull(newProfileTO);
+ Assert.assertTrue(newProfileTO.getId() != 0);
+ Assert.assertEquals("ProfileTest3", newProfileTO.getName());
+ ProfileTO testProfileTO = daoClient.readProfile(newProfileTO.getId());
+ Assert.assertNotNull(testProfileTO);
+ Assert.assertEquals(newProfileTO.getId(), testProfileTO.getId());
+ Assert.assertEquals(newProfileTO.getName(), testProfileTO.getName());
+ passed();
+ }
+
+ @Test
+ public void testUpdateProfile() throws Exception {
+ testName("updateProfile");
+ ProfileDaoClient daoClient = new ProfileDaoClient();
+ ProfileTO profileTO = new ProfileTO();
+ Assert.assertEquals(0, profileTO.getId());
+ profileTO.setName("ProfileTest4");
+ ProfileTO newProfileTO = daoClient.createProfile(profileTO);
+ Assert.assertNotNull(newProfileTO);
+ Assert.assertTrue(newProfileTO.getId() != 0);
+ Assert.assertEquals("ProfileTest4", newProfileTO.getName());
+ /* update */
+ newProfileTO.setName("ProfileTest4 - 1");
+ ProfileAttributeTO attributeTO = new ProfileAttributeTO();
+ attributeTO.setMandatory(true);
+ attributeTO.setName("attribute1");
+ //attributeTO.setProfileId(profileTO.getId());
+ attributeTO.setType("string");
+ List<ProfileAttributeTO> attributeTOs = new ArrayList<>();
+ attributeTOs.add(attributeTO);
+ newProfileTO.setAttributes(attributeTOs);
+ ProfileTO testProfileTO = daoClient.updateProfile(newProfileTO);
+ Assert.assertNotNull(testProfileTO);
+ // Read
+ testProfileTO = daoClient.readProfile(testProfileTO.getId());
+ Assert.assertEquals("ProfileTest4 - 1", testProfileTO.getName());
+ passed();
+ }
+
+ @Test
+ public void testCreateProfileAttribute() throws Exception {
+ testName("createProfileAttribute");
+ ProfileDaoClient daoClient = new ProfileDaoClient();
+ /* Create a new profile **/
+ ProfileTO profileTO = new ProfileTO();
+ Assert.assertEquals(0, profileTO.getId());
+ profileTO.setName("ProfileTest5");
+ ProfileTO newProfileTO = daoClient.createProfile(profileTO);
+ Assert.assertNotNull(newProfileTO);
+ Assert.assertTrue(newProfileTO.getId() != 0);
+ Assert.assertEquals("ProfileTest5", newProfileTO.getName());
+ /* Create a new ProfileAttribute */
+ ProfileAttributeTO attributeTO = new ProfileAttributeTO();
+ attributeTO.setMandatory(true);
+ attributeTO.setName("Attribute for test 5");
+ attributeTO.setType("string");
+ attributeTO.setProfileId(newProfileTO.getId());
+ ProfileAttributeTO newAttributeTO = daoClient.createProfileAttribute(attributeTO);
+ Assert.assertNotNull(newAttributeTO);
+ Assert.assertEquals(newProfileTO.getId(), newAttributeTO.getProfileId());
+ passed();
+ }
+}