From 0bfad7e1d26454c608b67644d880f0fbd2de3ce3 Mon Sep 17 00:00:00 2001 From: Kavoos Bojnourdi Date: Sat, 15 Aug 2015 16:13:42 +0200 Subject: [PATCH] test_jpa branch --- .../edf/gde/dao/impl/AttributeDaoImpl.java | 4 +- .../com/edf/gde/dao/impl/ProfileDaoImpl.java | 3 +- .../com/edf/gde/dao/ProfileDaoClient.java | 2 +- .../test/com/edf/gde/dao/StudyDaoClient.java | 2 - .../test/com/edf/gde/dao/UserDaoClient.java | 2 - .../com/edf/gde/test/dao/ProfileDaoTest.java | 140 ++++++++++++++++++ 6 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/ProfileDaoTest.java diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/AttributeDaoImpl.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/AttributeDaoImpl.java index c6351b1..a0167eb 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/AttributeDaoImpl.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/AttributeDaoImpl.java @@ -26,7 +26,7 @@ public class AttributeDaoImpl implements AttributeDao { @Override public AttributeTO createAttribute(AttributeTO ato) { Attribute a = Attribute.fromAttributeTO(em, ato); - em.persist(a); + a.getAttributeGroup().getAttributes().add(a); em.flush(); return a.toAttributeTO(); } @@ -34,7 +34,7 @@ public class AttributeDaoImpl implements AttributeDao { @Override public void deleteAttribute(long attributeId) { Attribute a = em.find(Attribute.class, attributeId); - em.remove(a); + a.getAttributeGroup().getAttributes().remove(a); } @Override diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/ProfileDaoImpl.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/ProfileDaoImpl.java index a527970..f32d3c5 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/ProfileDaoImpl.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/ProfileDaoImpl.java @@ -51,7 +51,8 @@ public class ProfileDaoImpl implements ProfileDao { @Override public ProfileAttributeTO createProfileAttribute(ProfileAttributeTO attributeTO) { ProfileAttribute attribute = ProfileAttribute.fromProfileAttributeTO(em, attributeTO); - em.persist(attribute); + Profile profile = attribute.getProfile(); + profile.addProfileAttribute(attribute); return attribute.toProfileAttributeTO(); } diff --git a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/ProfileDaoClient.java b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/ProfileDaoClient.java index 071bbb6..e137ba4 100644 --- a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/ProfileDaoClient.java +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/ProfileDaoClient.java @@ -26,7 +26,7 @@ public class ProfileDaoClient extends BaseDao { public static final int UPDATEPROFILEATTRIBUTE = 8; public ProfileDaoClient() { - getContext().setBaseResource("http://localhost:8080/GDE-war/ProfileService"); + getContext().setBaseResource("http://localhost:8080/GDE-war/ProfilesService"); getContext().setUserName("admin"); getContext().setPassword("edf123"); } diff --git a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java index 83f7f12..182de8b 100644 --- a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java @@ -21,8 +21,6 @@ public class StudyDaoClient extends BaseDao { public static final int READSTUDY = 3; public static final int DELETESTUDY = 4; - protected DaoResponseHandler daoResponseHandler; - public StudyDaoClient() { getContext().setBaseResource("http://localhost:8080/GDE-war/StudyService"); getContext().setUserName("admin"); diff --git a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/UserDaoClient.java b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/UserDaoClient.java index 71c2e1e..14bcae0 100644 --- a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/UserDaoClient.java +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/UserDaoClient.java @@ -25,8 +25,6 @@ public class UserDaoClient extends BaseDao { public static final int FINDUSER = 7; public static final int FINDGROUP = 8; - protected DaoResponseHandler daoResponseHandler; - public UserDaoClient() { getContext().setBaseResource("http://localhost:8080/GDE-war/UserService"); getContext().setUserName("admin"); diff --git a/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/ProfileDaoTest.java b/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/ProfileDaoTest.java new file mode 100644 index 0000000..fa53ca1 --- /dev/null +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/ProfileDaoTest.java @@ -0,0 +1,140 @@ +/* + * (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 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(); + } +} -- 2.39.2