Author: adamw
Date: 2008-08-14 05:36:38 -0400 (Thu, 14 Aug 2008)
New Revision: 99
Added:
trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
Log:
ENVERS-35: test
Added: trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
(rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-14
09:36:38 UTC (rev 99)
@@ -0,0 +1,69 @@
+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.tools.TestTools;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.query.RevisionProperty;
+import org.jboss.envers.query.RevisionTypeProperty;
+import org.jboss.envers.RevisionType;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.criterion.Projections;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+import java.util.HashSet;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DeletedEntities extends AbstractEntityTest {
+ private Integer id1;
+ private Integer id2;
+
+ public void configure(Ejb3Configuration cfg) {
+ 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", 11);
+
+ em.persist(site1);
+ em.persist(site2);
+
+ id1 = site1.getId();
+ id2 = site2.getId();
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ site2 = em.find(StrIntTestEntity.class, id2);
+ em.remove(site2);
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testProjectionsInEntitiesAtRevision() {
+ assert
getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
+ .getResultList().size() == 2;
+ assert
getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
+ .getResultList().size() == 1;
+
+ assert (Integer)
getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
+
.setProjection(Projections.count("originalId.id")).getResultList().get(0) == 2;
+ assert (Integer)
getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
+
.setProjection(Projections.count("originalId.id")).getResultList().get(0) == 1;
+ }
+}
Show replies by date