Permalink
Browse files

Added some test cases

  • Loading branch information...
1 parent 0b629ee commit ca95cc40e85f39076b92530726550807e04bffa0 @kkmishra kkmishra committed Dec 21, 2012
@@ -0,0 +1,63 @@
+package com.impetus.client.hbase.crud;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "Humans", schema = "KunderaExamples@ilpMainSchema")
+public class Human
+{
+ @Id
+ public String hId;
+
+ @Column(name = "humanAlive")
+ public Boolean humanAlive;
+
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @JoinColumn(name = "humanId")
+// @Column(name = "HumansPrivatePhoto")
+ public HumansPrivatePhoto humansPrivatePhoto;
+
+ public Human()
+ {
+
+ }
+
+ public Human(String humanId)
+ {
+ this.hId = humanId;
+ }
+
+ public Boolean getHumanAlive()
+ {
+ return humanAlive;
+ }
+
+ public void setHumanAlive(Boolean humanAlive)
+ {
+ this.humanAlive = humanAlive;
+ }
+
+ public HumansPrivatePhoto getHumansPrivatePhoto()
+ {
+ return humansPrivatePhoto;
+ }
+
+ public void setHumansPrivatePhoto(HumansPrivatePhoto humansPrivatePhoto)
+ {
+ this.humansPrivatePhoto = humansPrivatePhoto;
+ }
+
+ public String getHumanId()
+ {
+ return hId;
+ }
+
+
+}
@@ -0,0 +1,70 @@
+package com.impetus.client.hbase.crud;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.impetus.client.hbase.junits.HBaseCli;
+
+public class HumanTest
+{
+
+ /** The emf. */
+ private static EntityManagerFactory emf;
+
+ /** The em. */
+ private static EntityManager em;
+
+ private Map<Object, Object> col;
+
+ private HBaseCli cli;
+
+ @Before
+ public void setUp()
+ {
+ cli = new HBaseCli();
+ cli.startCluster();
+ emf = Persistence.createEntityManagerFactory("ilpMainSchema");
+ em = emf.createEntityManager();
+
+ }
+
+ @Test
+ public void testOps()
+ {
+ String humanId = "human1";
+ Human human = new Human(humanId);
+ human.setHumanAlive(true);
+ HumansPrivatePhoto photo = new HumansPrivatePhoto(humanId);
+ photo.setPhotoName("myPhoto");
+ human.setHumansPrivatePhoto(photo);
+ photo.setHuman(human);
+ em.persist(human);
+
+ em.clear(); // just to clear pc cache
+
+ Human result = em.find(Human.class, humanId);
+ System.out.println(result);
+
+ }
+
+ @After
+ public void tearDown()
+ {
+ em.close();
+ emf.close();
+ if (cli != null && cli.isStarted())
+ {
+ cli.dropTable("Humans");
+ cli.dropTable("HumansPrivatePhoto");
+ cli.stopCluster("Humans");
+ }
+
+ }
+}
@@ -0,0 +1,59 @@
+package com.impetus.client.hbase.crud;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "HumansPrivatePhoto", schema = "KunderaExamples@ilpMainSchema")
+public class HumansPrivatePhoto
+{
+
+ @Id
+ public String humanId;
+
+
+ @OneToOne(mappedBy = "humansPrivatePhoto", cascade = CascadeType.REFRESH)
+ //@PrimaryKeyJoinColumn
+ public Human human;
+
+ public String photoName;
+
+ public HumansPrivatePhoto()
+ {
+
+ }
+
+ public HumansPrivatePhoto(String humanId)
+ {
+ this.humanId = humanId;
+ }
+ public Human getHuman()
+ {
+ return human;
+ }
+
+ public void setHuman(Human human)
+ {
+ this.human = human;
+ }
+
+ public String getPhotoName()
+ {
+ return photoName;
+ }
+
+ public void setPhotoName(String photoName)
+ {
+ this.photoName = photoName;
+ }
+
+ public String getHumanId()
+ {
+ return humanId;
+ }
+
+
+}
@@ -0,0 +1,47 @@
+package com.impetus.client.hbase.crud.association;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+
+@Entity
+@Table(name="Address", schema="KunderaExamples@hbaseTest")
+public class AddressOTOHbase
+{
+
+ @Id
+ @Column(name="ADDRESS_ID")
+ private Double addressId;
+
+ public AddressOTOHbase()
+ {
+
+ }
+ public AddressOTOHbase(Double addressId)
+ {
+ this.addressId = addressId;
+ }
+
+ @Column(name="address")
+ private String address;
+
+ public String getAddress()
+ {
+ return address;
+ }
+
+ public void setAddress(String address)
+ {
+ this.address = address;
+ }
+
+
+ public Double getAddressId()
+ {
+ return addressId;
+ }
+
+
+}
@@ -0,0 +1,85 @@
+package com.impetus.client.hbase.crud.association;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.impetus.client.twitter.entities.PersonalDetailHbase;
+
+public class HbaseAssociationTest
+{
+
+ private static final String ROW_KEY = "1";
+
+ /** The Constant REDIS_PU. */
+ private static final String HBASE_PU = "hbaseTest";
+
+ /** The emf. */
+ private EntityManagerFactory emf;
+
+ /** The logger. */
+ private static Logger logger = LoggerFactory.getLogger(HbaseAssociationTest.class);
+
+ @Before
+ public void setUp()
+ {
+ emf = Persistence.createEntityManagerFactory(HBASE_PU);
+ }
+
+ @Test
+ public void testCrud()
+ {
+ EntityManager em = emf.createEntityManager();
+
+ PersonOTOHbase person = new PersonOTOHbase(ROW_KEY);
+ person.setAge(32);
+ person.setPersonName("vivek");
+ AddressOTOHbase address = new AddressOTOHbase(12.23);
+ address.setAddress("india");
+ person.setAddress(address);
+
+ PersonalDetailHbase detail = new PersonalDetailHbase();
+ detail.setName("KK");
+ detail.setPassword("xxxxxxx");
+ detail.setPersonalDetailId("xyz");
+ detail.setRelationshipStatus("single");
+
+ person.setPersonalDetail(detail);
+
+ em.persist(person);
+
+ em.clear();
+ PersonOTOHbase p = em.find(PersonOTOHbase.class, ROW_KEY);
+
+ // Assertions.
+ Assert.assertNotNull(p);
+ Assert.assertEquals(person.getPersonId(), p.getPersonId());
+ Assert.assertNotNull(p.getAddress());
+ Assert.assertEquals(person.getAddress().getAddress(), p.getAddress().getAddress());
+ Assert.assertNotNull(p.getPersonalDetail());
+ Assert.assertNotNull(p.getPersonalDetail().getName());
+ Assert.assertNotNull(p.getPersonalDetail().getPassword());
+ Assert.assertNotNull(p.getPersonalDetail().getPersonalDetailId());
+ Assert.assertNotNull(p.getPersonalDetail().getRelationshipStatus());
+
+ // Remove
+ em.remove(p);
+
+ em.clear(); // clear cache
+ Assert.assertNull(em.find(AddressOTOHbase.class, 12.23));
+ }
+
+ @After
+ public void tearDown()
+ {
+
+ }
+}
Oops, something went wrong.

0 comments on commit ca95cc4

Please sign in to comment.