HHH-7800: added unit test to demonstrate broken behavior ("maximize"

does not work inside an AuditDisjunction)
This commit is contained in:
Csaba Varga 2012-11-21 13:38:32 +01:00 committed by Lukasz Antoniak
parent ff25434d1f
commit cd3363151b
1 changed files with 36 additions and 1 deletions

View File

@ -24,15 +24,20 @@
package org.hibernate.envers.test.integration.query; package org.hibernate.envers.test.integration.query;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.junit.Test; import junit.framework.Assert;
import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.query.AuditEntity;
import org.hibernate.envers.query.criteria.AuditDisjunction;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.entities.StrIntTestEntity;
import org.junit.Test;
/** /**
* @author Adam Warski (adam at warski dot org) * @author Adam Warski (adam at warski dot org)
@ -41,6 +46,7 @@ import org.hibernate.envers.test.entities.StrIntTestEntity;
public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase { public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
Integer id1; Integer id1;
Integer id2; Integer id2;
Integer id3;
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
@ -56,12 +62,15 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
StrIntTestEntity site1 = new StrIntTestEntity("a", 10); StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
StrIntTestEntity site2 = new StrIntTestEntity("b", 15); StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
StrIntTestEntity site3 = new StrIntTestEntity("c", 42);
em.persist(site1); em.persist(site1);
em.persist(site2); em.persist(site2);
em.persist(site3);
id1 = site1.getId(); id1 = site1.getId();
id2 = site2.getId(); id2 = site2.getId();
id3 = site3.getId();
em.getTransaction().commit(); em.getTransaction().commit();
@ -135,4 +144,30 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
System.out.println(result); System.out.println(result);
assert Arrays.asList(2).equals(result); assert Arrays.asList(2).equals(result);
} }
@Test
public void testMaximizeInDisjunction() {
List<Integer> idsToQuery = Arrays.asList(id1, id3);
AuditDisjunction disjunction = AuditEntity.disjunction();
for (Integer id : idsToQuery) {
disjunction.add(AuditEntity.revisionNumber().maximize()
.add(AuditEntity.id().eq(id)));
}
List result = getAuditReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, true, true)
.add(disjunction)
.getResultList();
Set<Integer> idsSeen = new HashSet<Integer>();
for (Object o : result) {
StrIntTestEntity entity = (StrIntTestEntity) o;
Integer id = entity.getId();
Assert.assertTrue("Entity with ID "+id+" returned but not queried for.", idsToQuery.contains(id));
if (!idsSeen.add(id)) {
Assert.fail("Multiple revisions returned with ID "+id+"; expected only one.");
}
}
}
} }