Salome HOME
Working on tests for Study
authorBojnourdi <kavoos.bojnourdi@edf.fr>
Tue, 11 Aug 2015 10:50:20 +0000 (12:50 +0200)
committerBojnourdi <kavoos.bojnourdi@edf.fr>
Tue, 11 Aug 2015 10:50:20 +0000 (12:50 +0200)
* Fix null handling in Study (entity class)
* StudyDaoTest : Implemented createStudy test

projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java
projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/StudyDaoTest.java
projects/GDE_App/src/GDE_DB_Init.sql

index 9eca10a99282c7d313bae2e0af86bb237a915ecc..e03e385d35df2c25dcf6a675c2140d912d0a154e 100644 (file)
@@ -63,10 +63,10 @@ public class Study implements Serializable {
     @Column(name = "deletion_date")
     @Temporal(TemporalType.TIMESTAMP)
     private Date deletionDate;
-    @Column(name = "attribute_group_id")
-    private long attributeGroupId;
-    @Column(name = "profile_id")
-    private long profileId;
+    @Column(name = "attribute_group_id", nullable = true)
+    private Long attributeGroupId;
+    @Column(name = "profile_id", nullable = true)
+    private Long profileId;
     @Column(name ="locked")
     private boolean locked;
     public Study() {
@@ -161,12 +161,12 @@ public class Study implements Serializable {
         s.creationDate = sto.getCreationDate();
         s.deleted = sto.getDeleted();
         s.deletionDate = sto.getDeletionDate();
-        s.attributeGroupId = sto.getAttributeGroupId();
+        s.attributeGroupId = sto.getAttributeGroupId()==0?null:sto.getAttributeGroupId();
         s.id = sto.getId();
         s.name = sto.getName();
         s.updateDate = sto.getUpdateDate();
         s.valid = sto.getValid();
-        s.profileId = sto.getProfileId();
+        s.profileId = sto.getProfileId()==0?null:sto.getProfileId();
         s.locked = sto.isLocked();
         return s;
     }
@@ -176,12 +176,12 @@ public class Study implements Serializable {
         sto.setCreationDate(this.creationDate);
         sto.setDeleted(this.deleted);
         sto.setDeletionDate(this.deletionDate);
-        sto.setAttributeGroupId(this.attributeGroupId);
+        sto.setAttributeGroupId(this.attributeGroupId==null?0:this.attributeGroupId);
         sto.setId(this.id);
         sto.setName(this.name);
         sto.setUpdateDate(this.updateDate);
         sto.setValid(this.valid);
-        sto.setProfileId(this.profileId);
+        sto.setProfileId(this.profileId==null?0:this.profileId);
         sto.setLocked(this.locked);
         return sto;
     }
@@ -193,16 +193,17 @@ public class Study implements Serializable {
 
     @Override
     public int hashCode() {
-        int hash = 7;
-        hash = 11 * hash + (int) (this.id ^ (this.id >>> 32));
-        hash = 11 * hash + Objects.hashCode(this.name);
-        hash = 11 * hash + Objects.hashCode(this.creationDate);
-        hash = 11 * hash + Objects.hashCode(this.updateDate);
-        hash = 11 * hash + Objects.hashCode(this.valid);
-        hash = 11 * hash + Objects.hashCode(this.deleted);
-        hash = 11 * hash + Objects.hashCode(this.deletionDate);
-        hash = 11 * hash + (int) (this.attributeGroupId ^ (this.attributeGroupId >>> 32));
-        hash = 11 * hash + (int) (this.profileId ^ (this.profileId >>> 32));
+        int hash = 5;
+        hash = 67 * hash + (int) (this.id ^ (this.id >>> 32));
+        hash = 67 * hash + Objects.hashCode(this.name);
+        hash = 67 * hash + Objects.hashCode(this.creationDate);
+        hash = 67 * hash + Objects.hashCode(this.updateDate);
+        hash = 67 * hash + (this.valid ? 1 : 0);
+        hash = 67 * hash + (this.deleted ? 1 : 0);
+        hash = 67 * hash + Objects.hashCode(this.deletionDate);
+        hash = 67 * hash + Objects.hashCode(this.attributeGroupId);
+        hash = 67 * hash + Objects.hashCode(this.profileId);
+        hash = 67 * hash + (this.locked ? 1 : 0);
         return hash;
     }
 
@@ -221,4 +222,5 @@ public class Study implements Serializable {
         return true;
     }
 
+
 }
index 1c0c8eb604b77f304e8d33cfcca147d5f03c9ddc..e9d0030aee9c770d5b3ccdeb8127892163dbc2c4 100644 (file)
@@ -3,10 +3,16 @@
  */
 package com.edf.gde.test.dao;
 
+import com.edf.gde.dao.StudyDaoClient;
+import com.edf.gde.transferables.StudyTO;
+import java.util.Date;
 import org.junit.After;
 import org.junit.AfterClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  *
@@ -30,7 +36,16 @@ public class StudyDaoTest {
     public void tearDown() {
     }
 
+    @Test
     public void testCreateStudy() throws Exception {
-        
+        System.out.println("createStudy");
+        StudyDaoClient daoClient = new StudyDaoClient();
+        StudyTO studyTO = new StudyTO();
+        studyTO.setName("My study");
+        studyTO.setCreationDate(new Date(System.currentTimeMillis()));
+        studyTO.setValid(true);
+        StudyTO newStudyTO = daoClient.createStudy(studyTO);
+        assertNotNull(newStudyTO);
+        assertEquals(studyTO.getName(), newStudyTO.getName());
     }
 }
index 96c5cdd6317ec301d8eae4a655223027cf094287..71a844563a720a539118313ca293549a4c6657a8 100644 (file)
@@ -93,7 +93,6 @@ CREATE TABLE study (
     profile_id bigint REFERENCES profile (id),
     locked boolean
 );
-
 /* PROFILES */
 
 DROP TABLE IF EXISTS profile CASCADE;