]> SALOME platform Git repositories - modules/gde.git/commitdiff
Salome HOME
test_jpa branch
authorKavoos Bojnourdi <kavoos.bojnourdi@edf.fr>
Sat, 15 Aug 2015 14:13:42 +0000 (16:13 +0200)
committerKavoos Bojnourdi <kavoos.bojnourdi@edf.fr>
Sat, 15 Aug 2015 14:13:42 +0000 (16:13 +0200)
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/AttributeDaoImpl.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/ProfileDaoImpl.java
projects/GDE_App/GDE-war/test/com/edf/gde/dao/ProfileDaoClient.java
projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java
projects/GDE_App/GDE-war/test/com/edf/gde/dao/UserDaoClient.java
projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/ProfileDaoTest.java [new file with mode: 0644]

index c6351b13ec3159bbc9bfc4652b45c5425599858c..a0167eb41687cb7e999eb987a1d5522e5d004406 100644 (file)
@@ -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
index a527970eaf334ec2f46bb17b81326b9102e6f900..f32d3c59c25ba62b8d5b6f6cd309f3eb8114ad70 100644 (file)
@@ -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();
     }
 
index 071bbb6fb7aa43cf03c0182e1c0a931aa4ef470a..e137ba436d7ca94057438949bdbca29fde6bbd36 100644 (file)
@@ -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");
     }
index 83f7f125f30edc190c5a62c5cb86638fb2a1a355..182de8b19cd52e249f9f927b74510dabf962132b 100644 (file)
@@ -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");
index 71c2e1e4e3b5bbf59c527786190919076784e8a1..14bcae0944182c0a64c4765f5cb5cc5677bf6fcf 100644 (file)
@@ -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 (file)
index 0000000..fa53ca1
--- /dev/null
@@ -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<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();
+    }
+}