Author: adamw
Date: 2008-09-03 03:50:01 -0400 (Wed, 03 Sep 2008)
New Revision: 142
Added:
trunk/src/test/org/jboss/envers/test/entities/reventity/
trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java
trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
Modified:
trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java
Log:
ENVERS-47: custom revision entity + rev-of-entities query test
Copied: trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java (from
rev 138, trunk/src/test/org/jboss/envers/test/integration/reventity/CustomRevEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java 2008-09-03
07:50:01 UTC (rev 142)
@@ -0,0 +1,59 @@
+package org.jboss.envers.test.entities.reventity;
+
+import org.jboss.envers.RevisionNumber;
+import org.jboss.envers.RevisionTimestamp;
+import org.jboss.envers.RevisionEntity;
+
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@RevisionEntity
+public class CustomRevEntity {
+ @Id
+ @GeneratedValue
+ @RevisionNumber
+ private int customId;
+
+ @RevisionTimestamp
+ private long customTimestamp;
+
+ public int getCustomId() {
+ return customId;
+ }
+
+ public void setCustomId(int customId) {
+ this.customId = customId;
+ }
+
+ public long getCustomTimestamp() {
+ return customTimestamp;
+ }
+
+ public void setCustomTimestamp(long customTimestamp) {
+ this.customTimestamp = customTimestamp;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CustomRevEntity)) return false;
+
+ CustomRevEntity that = (CustomRevEntity) o;
+
+ if (customId != that.customId) return false;
+ if (customTimestamp != that.customTimestamp) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = customId;
+ result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>>
32));
+ return result;
+ }
+}
Copied: trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
(from rev 138,
trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java 2008-09-03
07:50:01 UTC (rev 142)
@@ -0,0 +1,83 @@
+package org.jboss.envers.test.integration.query;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.StrIntTestEntity;
+import org.jboss.envers.test.entities.reventity.CustomRevEntity;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.query.RevisionProperty;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@SuppressWarnings({"unchecked"})
+public class CustomRevEntityQuery extends AbstractEntityTest {
+ private Integer id1;
+ private Integer id2;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(CustomRevEntity.class);
+ cfg.addAnnotatedClass(StrIntTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+
+ StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
+ StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
+
+ em.persist(site1);
+ em.persist(site2);
+
+ id1 = site1.getId();
+ id2 = site2.getId();
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ site1 = em.find(StrIntTestEntity.class, id1);
+
+ site1.setStr1("c");
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsOfId1Query() {
+ List<Object[]> result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(VersionsRestrictions.idEq(id1))
+ .getResultList();
+
+ assert result.get(0)[0].equals(new StrIntTestEntity("a", 10, id1));
+ assert result.get(0)[1] instanceof CustomRevEntity;
+ assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1;
+
+ assert result.get(1)[0].equals(new StrIntTestEntity("c", 10, id1));
+ assert result.get(1)[1] instanceof CustomRevEntity;
+ assert ((CustomRevEntity) result.get(1)[1]).getCustomId() == 2;
+ }
+
+ @Test
+ public void testRevisionsOfId2Query() {
+ List<Object[]> result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(VersionsRestrictions.idEq(id2))
+ .getResultList();
+
+ assert result.get(0)[0].equals(new StrIntTestEntity("b", 15, id2));
+ assert result.get(0)[1] instanceof CustomRevEntity;
+ assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java 2008-09-03
07:29:48 UTC (rev 141)
+++ trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java 2008-09-03
07:50:01 UTC (rev 142)
@@ -2,6 +2,7 @@
import org.jboss.envers.test.integration.AbstractEntityTest;
import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.entities.reventity.CustomRevEntity;
import org.jboss.envers.exception.RevisionDoesNotExistException;
import org.jboss.envers.VersionsReader;
import org.hibernate.ejb.Ejb3Configuration;
Show replies by date