From: Bojnourdi Date: Tue, 11 Aug 2015 10:50:20 +0000 (+0200) Subject: Working on tests for Study X-Git-Tag: gde-v0.1~8^2~68 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1411aaf232202785d3a57b49c2c5691dccfcb39b;p=modules%2Fgde.git Working on tests for Study * Fix null handling in Study (entity class) * StudyDaoTest : Implemented createStudy test --- diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java index 9eca10a..e03e385 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java @@ -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; } + } diff --git a/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/StudyDaoTest.java b/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/StudyDaoTest.java index 1c0c8eb..e9d0030 100644 --- a/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/StudyDaoTest.java +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/test/dao/StudyDaoTest.java @@ -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()); } } diff --git a/projects/GDE_App/src/GDE_DB_Init.sql b/projects/GDE_App/src/GDE_DB_Init.sql index 96c5cdd..71a8445 100644 --- a/projects/GDE_App/src/GDE_DB_Init.sql +++ b/projects/GDE_App/src/GDE_DB_Init.sql @@ -93,7 +93,6 @@ CREATE TABLE study ( profile_id bigint REFERENCES profile (id), locked boolean ); - /* PROFILES */ DROP TABLE IF EXISTS profile CASCADE;