HHH-7800 - Tests cleanup
This commit is contained in:
parent
dadc43af23
commit
468c58358e
|
@ -30,13 +30,14 @@ import java.util.Set;
|
|||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
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.hibernate.testing.TestForIssue;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -141,19 +142,18 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
|
|||
.add(AuditEntity.property("number").eq(10)))
|
||||
.getResultList();
|
||||
|
||||
System.out.println(result);
|
||||
assert Arrays.asList(2).equals(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7800")
|
||||
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)));
|
||||
disjunction.add( AuditEntity.revisionNumber().maximize().add( AuditEntity.id().eq( id ) ) );
|
||||
}
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity( StrIntTestEntity.class, true, true )
|
||||
|
|
|
@ -34,11 +34,11 @@ import org.junit.Test;
|
|||
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
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.hibernate.envers.test.tools.TestTools;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
|
@ -328,6 +328,7 @@ public class SimpleQuery extends BaseEnversJPAFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7800")
|
||||
public void testBetweenInsideDisjunction() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity( StrIntTestEntity.class, true, true )
|
||||
|
@ -339,7 +340,7 @@ public class SimpleQuery extends BaseEnversJPAFunctionalTestCase {
|
|||
for ( Object o : result ) {
|
||||
StrIntTestEntity entity = (StrIntTestEntity) o;
|
||||
int number = entity.getNumber();
|
||||
assert ( number >= 0 && number <= 5) || ( number >= 20 && number <= 100);
|
||||
Assert.assertTrue( ( number >= 0 && number <= 5 ) || ( number >= 20 && number <= 100 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,16 +23,23 @@
|
|||
*/
|
||||
package org.hibernate.envers.test.integration.query;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
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.hibernate.testing.TestForIssue;
|
||||
|
||||
/**
|
||||
* A test which checks if the data of a deleted entity is stored when the setting is on.
|
||||
|
@ -41,6 +48,8 @@ import org.hibernate.envers.test.entities.StrIntTestEntity;
|
|||
@SuppressWarnings({ "unchecked" })
|
||||
public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
||||
private Integer id1;
|
||||
private Integer id2;
|
||||
private Integer id3;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
|
@ -56,24 +65,37 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
|||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
|
||||
// Revision 1
|
||||
em.getTransaction().begin();
|
||||
|
||||
StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 );
|
||||
|
||||
em.persist( site1 );
|
||||
|
||||
id1 = site1.getId();
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
|
||||
em.remove( site1 );
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 3
|
||||
em.getTransaction().begin();
|
||||
StrIntTestEntity site2 = new StrIntTestEntity( "b", 20 );
|
||||
em.persist( site2 );
|
||||
id2 = site2.getId();
|
||||
StrIntTestEntity site3 = new StrIntTestEntity( "c", 30 );
|
||||
em.persist( site3 );
|
||||
id3 = site3.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 4
|
||||
em.getTransaction().begin();
|
||||
em.remove( site2 );
|
||||
em.remove( site3 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,8 +105,44 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
|||
.add( AuditEntity.id().eq( id1 ) )
|
||||
.getResultList();
|
||||
|
||||
assert revs_id1.size() == 2;
|
||||
assert ((Object[]) revs_id1.get(0))[0].equals(new StrIntTestEntity("a", 10, id1));
|
||||
assert ((Object[]) revs_id1.get(1))[0].equals(new StrIntTestEntity("a", 10, id1));
|
||||
Assert.assertEquals( 2, revs_id1.size() );
|
||||
Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ( (Object[]) revs_id1.get( 0 ) )[0] );
|
||||
Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ( (Object[]) revs_id1.get( 1 ) )[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7800")
|
||||
public void testMaximizeInDisjunction() {
|
||||
List<Integer> queryIds = Arrays.asList( id2, id3 );
|
||||
|
||||
AuditDisjunction disjunction = AuditEntity.disjunction();
|
||||
for ( Integer id : queryIds ) {
|
||||
AuditCriterion crit = AuditEntity.revisionNumber().maximize()
|
||||
.add( AuditEntity.id().eq( id ) )
|
||||
.add( AuditEntity.revisionType().ne( RevisionType.DEL ) );
|
||||
disjunction.add( crit );
|
||||
// Workaround: using this line instead works correctly:
|
||||
// disjunction.add(AuditEntity.conjunction().add(crit));
|
||||
}
|
||||
|
||||
List<?> beforeDeletionRevisions = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity( StrIntTestEntity.class, false, false )
|
||||
.add( disjunction )
|
||||
.addOrder( AuditEntity.property( "id" ).asc() )
|
||||
.getResultList();
|
||||
|
||||
Assert.assertEquals( 2, beforeDeletionRevisions.size() );
|
||||
|
||||
Object[] result1 = (Object[]) beforeDeletionRevisions.get( 0 );
|
||||
Object[] result2 = (Object[]) beforeDeletionRevisions.get( 1 );
|
||||
|
||||
Assert.assertEquals( new StrIntTestEntity( "b", 20, id2 ), result1[0] );
|
||||
// Making sure that we have received an entity added at revision 3.
|
||||
Assert.assertEquals( 3, ( (SequenceIdRevisionEntity) result1[1] ).getId() );
|
||||
Assert.assertEquals( RevisionType.ADD, result1[2] );
|
||||
Assert.assertEquals( new StrIntTestEntity( "c", 30, id3 ), result2[0] );
|
||||
// Making sure that we have received an entity added at revision 3.
|
||||
Assert.assertEquals( 3, ( (SequenceIdRevisionEntity) result2[1] ).getId() );
|
||||
Assert.assertEquals( RevisionType.ADD, result2[2] );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue