Refactoring the norevision tests: checking explicitly the revision numbers, introducing an abstract common class
This commit is contained in:
parent
76b59a702c
commit
4e102c68c1
|
@ -0,0 +1,58 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.envers.test.AbstractSessionTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCollectionChangeTest extends AbstractSessionTest {
|
||||
protected Integer personId;
|
||||
|
||||
@Override
|
||||
protected void initMappings() throws MappingException, URISyntaxException {
|
||||
config.addAnnotatedClass(Person.class);
|
||||
config.addAnnotatedClass(Name.class);
|
||||
config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue());
|
||||
}
|
||||
|
||||
protected abstract String getCollectionChangeValue();
|
||||
|
||||
protected abstract List<Integer> getExpectedPersonRevisions();
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
newSessionFactory();
|
||||
|
||||
// Rev 1
|
||||
getSession().getTransaction().begin();
|
||||
Person p = new Person();
|
||||
Name n = new Name();
|
||||
n.setName("name1");
|
||||
p.getNames().add(n);
|
||||
getSession().saveOrUpdate(p);
|
||||
getSession().getTransaction().commit();
|
||||
|
||||
// Rev 2
|
||||
getSession().getTransaction().begin();
|
||||
n.setName("Changed name");
|
||||
getSession().saveOrUpdate(p);
|
||||
getSession().getTransaction().commit();
|
||||
|
||||
// Rev 3
|
||||
getSession().getTransaction().begin();
|
||||
Name n2 = new Name();
|
||||
n2.setName("name2");
|
||||
p.getNames().add(n2);
|
||||
getSession().getTransaction().commit();
|
||||
|
||||
personId = p.getId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersonRevisionCount() {
|
||||
assert getAuditReader().getRevisions(Person.class, personId).equals(getExpectedPersonRevisions());
|
||||
}
|
||||
}
|
|
@ -1,69 +1,15 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.envers.test.AbstractSessionTest;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
||||
|
||||
protected static final int EXPECTED_PERSON_REVISION_COUNT = 1;
|
||||
protected static final String CREATE_REVISION_ON_COLLECTION_CHANGE = "false";
|
||||
protected Integer personId;
|
||||
public class CollectionChangeNoRevisionTest extends AbstractCollectionChangeTest {
|
||||
protected String getCollectionChangeValue() {
|
||||
return "false";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initMappings() throws MappingException, URISyntaxException {
|
||||
config.addAnnotatedClass(Person.class);
|
||||
config.addAnnotatedClass(Name.class);
|
||||
config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue());
|
||||
protected List<Integer> getExpectedPersonRevisions() {
|
||||
return Arrays.asList(1);
|
||||
}
|
||||
|
||||
protected String getCollectionChangeValue() {
|
||||
return CREATE_REVISION_ON_COLLECTION_CHANGE;
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
newSessionFactory();
|
||||
Person p = new Person();
|
||||
Name n = new Name();
|
||||
n.setName("name1");
|
||||
p.getNames().add(n);
|
||||
getSession().getTransaction().begin();
|
||||
getSession().saveOrUpdate(p);
|
||||
getSession().getTransaction().commit();
|
||||
personId = p.getId();
|
||||
getSession().getTransaction().begin();
|
||||
n.setName("Changed name");
|
||||
getSession().saveOrUpdate(p);
|
||||
getSession().getTransaction().commit();
|
||||
getSession().getTransaction().begin();
|
||||
Name n2 = new Name();
|
||||
n2.setName("name2");
|
||||
p.getNames().add(n2);
|
||||
getSession().getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersonRevisionCount() {
|
||||
int sizePerson = getAuditReader().getRevisions(Person.class, personId).size();
|
||||
assert sizePerson == getExpectedPersonRevisionCount();
|
||||
}
|
||||
|
||||
protected int getExpectedPersonRevisionCount() {
|
||||
return EXPECTED_PERSON_REVISION_COUNT;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +1,16 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class CollectionChangeRevisionTest extends CollectionChangeNoRevisionTest {
|
||||
|
||||
protected static final int PERSON_COUNT_NEW_REVISION_ON_COLLECTION = 2;
|
||||
protected static final String NEW_REVISION_ON_COLLECTION = "true";
|
||||
|
||||
@Override
|
||||
protected void initMappings() throws MappingException, URISyntaxException {
|
||||
super.initMappings();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExpectedPersonRevisionCount() {
|
||||
return PERSON_COUNT_NEW_REVISION_ON_COLLECTION;
|
||||
}
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionChangeRevisionTest extends AbstractCollectionChangeTest {
|
||||
@Override
|
||||
protected String getCollectionChangeValue() {
|
||||
return NEW_REVISION_ON_COLLECTION;
|
||||
return "true";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Integer> getExpectedPersonRevisions() {
|
||||
return Arrays.asList(1, 3);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue