HHH-7800 - Tests cleanup
This commit is contained in:
parent
ca44ff7949
commit
6498ca969c
|
@ -30,14 +30,14 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
import org.hibernate.envers.query.criteria.AuditDisjunction;
|
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.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,8 +49,8 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
|
||||||
Integer id2;
|
Integer id2;
|
||||||
Integer id3;
|
Integer id3;
|
||||||
|
|
||||||
public void configure(Ejb3Configuration cfg) {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
cfg.addAnnotatedClass(StrIntTestEntity.class);
|
return new Class[] { StrIntTestEntity.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -141,19 +141,18 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase {
|
||||||
.add(AuditEntity.property("number").eq(10)))
|
.add(AuditEntity.property("number").eq(10)))
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
|
||||||
System.out.println(result);
|
|
||||||
assert Arrays.asList(2).equals(result);
|
assert Arrays.asList(2).equals(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-7800")
|
||||||
public void testMaximizeInDisjunction() {
|
public void testMaximizeInDisjunction() {
|
||||||
List<Integer> idsToQuery = Arrays.asList( id1, id3 );
|
List<Integer> idsToQuery = Arrays.asList( id1, id3 );
|
||||||
|
|
||||||
AuditDisjunction disjunction = AuditEntity.disjunction();
|
AuditDisjunction disjunction = AuditEntity.disjunction();
|
||||||
|
|
||||||
for ( Integer id : idsToQuery ) {
|
for ( Integer id : idsToQuery ) {
|
||||||
disjunction.add(AuditEntity.revisionNumber().maximize()
|
disjunction.add( AuditEntity.revisionNumber().maximize().add( AuditEntity.id().eq( id ) ) );
|
||||||
.add(AuditEntity.id().eq(id)));
|
|
||||||
}
|
}
|
||||||
List result = getAuditReader().createQuery()
|
List result = getAuditReader().createQuery()
|
||||||
.forRevisionsOfEntity( StrIntTestEntity.class, true, true )
|
.forRevisionsOfEntity( StrIntTestEntity.class, true, true )
|
||||||
|
|
|
@ -39,6 +39,7 @@ 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.hibernate.envers.test.tools.TestTools;
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -325,4 +326,21 @@ public class SimpleQuery extends BaseEnversJPAFunctionalTestCase {
|
||||||
List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 5).getResultList();
|
List result = getAuditReader().createQuery().forEntitiesModifiedAtRevision(StrIntTestEntity.class, 5).getResultList();
|
||||||
Assert.assertTrue(result.isEmpty());
|
Assert.assertTrue(result.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-7800")
|
||||||
|
public void testBetweenInsideDisjunction() {
|
||||||
|
List result = getAuditReader().createQuery()
|
||||||
|
.forRevisionsOfEntity( StrIntTestEntity.class, true, true )
|
||||||
|
.add( AuditEntity.disjunction()
|
||||||
|
.add( AuditEntity.property( "number" ).between( 0, 5 ) )
|
||||||
|
.add( AuditEntity.property( "number" ).between( 20, 100 ) ) )
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
for ( Object o : result ) {
|
||||||
|
StrIntTestEntity entity = (StrIntTestEntity) o;
|
||||||
|
int number = entity.getNumber();
|
||||||
|
Assert.assertTrue( ( number >= 0 && number <= 5 ) || ( number >= 20 && number <= 100 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,23 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.test.integration.query;
|
package org.hibernate.envers.test.integration.query;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.envers.RevisionType;
|
||||||
|
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
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.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.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test which checks if the data of a deleted entity is stored when the setting is on.
|
* A test which checks if the data of a deleted entity is stored when the setting is on.
|
||||||
|
@ -42,9 +48,12 @@ import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
||||||
private Integer id1;
|
private Integer id1;
|
||||||
|
private Integer id2;
|
||||||
|
private Integer id3;
|
||||||
|
|
||||||
public void configure(Ejb3Configuration cfg) {
|
@Override
|
||||||
cfg.addAnnotatedClass(StrIntTestEntity.class);
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
return new Class[] { StrIntTestEntity.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,24 +65,37 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
||||||
@Test
|
@Test
|
||||||
@Priority(10)
|
@Priority(10)
|
||||||
public void initData() {
|
public void initData() {
|
||||||
// Revision 1
|
|
||||||
EntityManager em = getEntityManager();
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
// Revision 1
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 );
|
StrIntTestEntity site1 = new StrIntTestEntity( "a", 10 );
|
||||||
|
|
||||||
em.persist( site1 );
|
em.persist( site1 );
|
||||||
|
|
||||||
id1 = site1.getId();
|
id1 = site1.getId();
|
||||||
|
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
|
||||||
// Revision 2
|
// Revision 2
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
em.remove( site1 );
|
em.remove( site1 );
|
||||||
|
|
||||||
em.getTransaction().commit();
|
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
|
@Test
|
||||||
|
@ -83,8 +105,44 @@ public class StoreDeletedData extends BaseEnversJPAFunctionalTestCase {
|
||||||
.add( AuditEntity.id().eq( id1 ) )
|
.add( AuditEntity.id().eq( id1 ) )
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
|
||||||
assert revs_id1.size() == 2;
|
Assert.assertEquals( 2, revs_id1.size() );
|
||||||
assert ((Object[]) revs_id1.get(0))[0].equals(new StrIntTestEntity("a", 10, id1));
|
Assert.assertEquals( new StrIntTestEntity( "a", 10, id1 ), ( (Object[]) revs_id1.get( 0 ) )[0] );
|
||||||
assert ((Object[]) revs_id1.get(1))[0].equals(new StrIntTestEntity("a", 10, id1));
|
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