From 3336ba5ae26521c01d726b91bb7f5651dad681cb Mon Sep 17 00:00:00 2001 From: Kavoos Bojnourdi Date: Sat, 15 Aug 2015 17:18:04 +0200 Subject: [PATCH] Profile management Dao implementation + service + tests --- .../com/edf/gde/dao/impl/ProfileDaoImpl.java | 1 + .../gde/transferables/ProfileAttributeTO.java | 6 +- .../com/edf/gde/test/dao/ProfileDaoTest.java | 91 +++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) 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 27790fb..6bc9d59 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 @@ -58,6 +58,7 @@ public class ProfileDaoImpl implements ProfileDao { ProfileAttribute attribute = ProfileAttribute.fromProfileAttributeTO(em, attributeTO); Profile profile = attribute.getProfile(); profile.addProfileAttribute(attribute); + em.flush(); return attribute.toProfileAttributeTO(); } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java index c23d497..b8f46e7 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java @@ -11,7 +11,7 @@ import java.io.Serializable; */ public class ProfileAttributeTO implements Serializable { - private Long id; + private long id; private String name; private String type; private boolean mandatory; @@ -20,11 +20,11 @@ public class ProfileAttributeTO implements Serializable { public ProfileAttributeTO() { } - public Long getId() { + public long getId() { return id; } - public void setId(Long id) { + public void setId(long id) { this.id = id; } 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 index 69090ff..0ae96bc 100644 --- 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 @@ -134,7 +134,98 @@ public class ProfileDaoTest extends BaseTest { attributeTO.setProfileId(newProfileTO.getId()); ProfileAttributeTO newAttributeTO = daoClient.createProfileAttribute(attributeTO); Assert.assertNotNull(newAttributeTO); + Assert.assertTrue(newAttributeTO.getId() != 0); Assert.assertEquals(newProfileTO.getId(), newAttributeTO.getProfileId()); passed(); } + + @Test + public void testDeleteProfileAttribute() throws Exception { + testName("deleteProfileattribute"); + ProfileDaoClient daoClient = new ProfileDaoClient(); + /* Create a new profile **/ + ProfileTO profileTO = new ProfileTO(); + Assert.assertEquals(0, profileTO.getId()); + profileTO.setName("ProfileTest6"); + ProfileTO newProfileTO = daoClient.createProfile(profileTO); + Assert.assertNotNull(newProfileTO); + Assert.assertTrue(newProfileTO.getId() != 0); + Assert.assertEquals("ProfileTest6", newProfileTO.getName()); + + /* Create a new ProfileAttribute */ + ProfileAttributeTO attributeTO = new ProfileAttributeTO(); + attributeTO.setMandatory(true); + attributeTO.setName("Attribute for test 6"); + attributeTO.setType("string"); + attributeTO.setProfileId(newProfileTO.getId()); + ProfileAttributeTO newAttributeTO = daoClient.createProfileAttribute(attributeTO); + Assert.assertNotNull(newAttributeTO); + Assert.assertTrue(newAttributeTO.getId() != 0); + daoClient.deleteProfileAttribute(newAttributeTO.getId()); + passed(); + } + + @Test + public void testReadProfileAttribute() throws Exception { + testName("readProfileAttribute"); + ProfileDaoClient daoClient = new ProfileDaoClient(); + /* Create a new profile **/ + ProfileTO profileTO = new ProfileTO(); + Assert.assertEquals(0, profileTO.getId()); + profileTO.setName("ProfileTest7"); + ProfileTO newProfileTO = daoClient.createProfile(profileTO); + Assert.assertNotNull(newProfileTO); + Assert.assertTrue(newProfileTO.getId() != 0); + Assert.assertEquals("ProfileTest7", newProfileTO.getName()); + /* Create a new ProfileAttribute */ + ProfileAttributeTO attributeTO = new ProfileAttributeTO(); + attributeTO.setMandatory(true); + attributeTO.setName("Attribute for test 7"); + attributeTO.setType("string"); + attributeTO.setProfileId(newProfileTO.getId()); + ProfileAttributeTO newAttributeTO = daoClient.createProfileAttribute(attributeTO); + Assert.assertNotNull(newAttributeTO); + Assert.assertTrue(newAttributeTO.getId() != 0); + Assert.assertEquals(newProfileTO.getId(), newAttributeTO.getProfileId()); + /* Read */ + ProfileAttributeTO testAttributeTO = daoClient.readProfileAttribute(newAttributeTO.getId()); + Assert.assertNotNull(testAttributeTO); + Assert.assertEquals(newAttributeTO.getId(), testAttributeTO.getId()); + Assert.assertEquals(newAttributeTO.getName(), testAttributeTO.getName()); + passed(); + } + + @Test + public void testUpdateProfileAttribute() throws Exception { + testName("updateProfileAttribute"); + ProfileDaoClient daoClient = new ProfileDaoClient(); + /* Create a new profile **/ + ProfileTO profileTO = new ProfileTO(); + Assert.assertEquals(0, profileTO.getId()); + profileTO.setName("ProfileTest8"); + ProfileTO newProfileTO = daoClient.createProfile(profileTO); + Assert.assertNotNull(newProfileTO); + Assert.assertTrue(newProfileTO.getId() != 0); + Assert.assertEquals("ProfileTest8", newProfileTO.getName()); + /* Create a new ProfileAttribute */ + ProfileAttributeTO attributeTO = new ProfileAttributeTO(); + attributeTO.setMandatory(true); + attributeTO.setName("Attribute for test 8"); + attributeTO.setType("string"); + attributeTO.setProfileId(newProfileTO.getId()); + ProfileAttributeTO newAttributeTO = daoClient.createProfileAttribute(attributeTO); + Assert.assertNotNull(newAttributeTO); + Assert.assertTrue(newAttributeTO.getId() != 0); + Assert.assertEquals(newProfileTO.getId(), newAttributeTO.getProfileId()); + /* Update */ + newAttributeTO.setName("Attribute for test 8 update"); + newAttributeTO = daoClient.updateProfileAttribute(newAttributeTO); + /* Read */ + ProfileAttributeTO testAttributeTO = daoClient.readProfileAttribute(newAttributeTO.getId()); + Assert.assertNotNull(testAttributeTO); + Assert.assertEquals(newAttributeTO.getId(), testAttributeTO.getId()); + Assert.assertEquals(newAttributeTO.getName(), testAttributeTO.getName()); + passed(); + } + } -- 2.39.2