HHH-7800: added unit test to demonstrate broken behavior ("maximize"
does not work inside an AuditDisjunction)
This commit is contained in:
parent
ac95b64aad
commit
d5a40bbd1f
|
@ -24,16 +24,21 @@
|
|||
package org.hibernate.envers.test.integration.query;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.junit.Test;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.query.criteria.AuditDisjunction;
|
||||
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
|
@ -42,6 +47,7 @@ import org.hibernate.envers.test.entities.StrIntTestEntity;
|
|||
public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
|
||||
Integer id1;
|
||||
Integer id2;
|
||||
Integer id3;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrIntTestEntity.class);
|
||||
|
@ -56,12 +62,15 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
|
|||
|
||||
StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
|
||||
StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
|
||||
StrIntTestEntity site3 = new StrIntTestEntity("c", 42);
|
||||
|
||||
em.persist(site1);
|
||||
em.persist(site2);
|
||||
em.persist(site3);
|
||||
|
||||
id1 = site1.getId();
|
||||
id2 = site2.getId();
|
||||
id3 = site3.getId();
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
|
@ -135,4 +144,30 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
|
|||
System.out.println(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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue