Tests are slightly changed to do more work

This commit is contained in:
Svyatoslav Reyentenko 2010-12-02 23:58:58 +03:00 committed by adamw
parent e831e29435
commit c2ba8360c8
2 changed files with 14 additions and 22 deletions

View File

@ -19,10 +19,8 @@ import java.util.List;
public class CollectionChangeNoRevisionTest extends AbstractSessionTest { public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
protected static final int EXPECTED_PERSON_REVISION_COUNT = 1; protected static final int EXPECTED_PERSON_REVISION_COUNT = 1;
protected static final int EXPECTED_NAME_REVISION_COUNT = 1;
protected static final String CREATE_REVISION_ON_COLLECTION_CHANGE = "false"; protected static final String CREATE_REVISION_ON_COLLECTION_CHANGE = "false";
protected Integer personId; protected Integer personId;
protected List<Integer> namesId = new ArrayList<Integer>();
@Override @Override
protected void initMappings() throws MappingException, URISyntaxException { protected void initMappings() throws MappingException, URISyntaxException {
@ -35,38 +33,32 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
return CREATE_REVISION_ON_COLLECTION_CHANGE; return CREATE_REVISION_ON_COLLECTION_CHANGE;
} }
@BeforeMethod(firstTimeOnly = true) @BeforeClass(dependsOnMethods = "init")
public void initData() { public void initData() {
newSessionFactory(); newSessionFactory();
Person p = new Person(); Person p = new Person();
Name n = new Name(); Name n = new Name();
n.setName("name1"); n.setName("name1");
p.getNames().add(n); p.getNames().add(n);
Transaction transaction = getSession().beginTransaction(); getSession().getTransaction().begin();
getSession().saveOrUpdate(p); getSession().saveOrUpdate(p);
transaction.commit(); getSession().getTransaction().commit();
personId = p.getId(); personId = p.getId();
namesId.add(n.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 @Test
public void testPersonRevisionCount() { public void testPersonRevisionCount() {
Person p = (Person) getSession().createCriteria(Person.class).add(Restrictions.idEq(personId)).uniqueResult();
Name n2 = new Name();
n2.setName("name2");
p.getNames().add(n2);
Transaction transaction = getSession().beginTransaction();
getSession().saveOrUpdate(p);
transaction.commit();
namesId.add(n2.getId());
int sizePerson = getAuditReader().getRevisions(Person.class, personId).size(); int sizePerson = getAuditReader().getRevisions(Person.class, personId).size();
Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), getCollectionChangeValue()); assert sizePerson == getExpectedPersonRevisionCount();
Assert.assertEquals(sizePerson, getExpectedPersonRevisionCount());
for (Integer id : namesId) {
int sizeName = getAuditReader().getRevisions(Name.class, id).size();
Assert.assertEquals(sizeName, EXPECTED_NAME_REVISION_COUNT);
}
} }
protected int getExpectedPersonRevisionCount() { protected int getExpectedPersonRevisionCount() {

View File

@ -5,7 +5,7 @@ import org.testng.annotations.BeforeMethod;
import java.net.URISyntaxException; import java.net.URISyntaxException;
public class CollectionChangRevisionTest extends CollectionChangeNoRevisionTest { public class CollectionChangeRevisionTest extends CollectionChangeNoRevisionTest {
protected static final int PERSON_COUNT_NEW_REVISION_ON_COLLECTION = 2; protected static final int PERSON_COUNT_NEW_REVISION_ON_COLLECTION = 2;
protected static final String NEW_REVISION_ON_COLLECTION = "true"; protected static final String NEW_REVISION_ON_COLLECTION = "true";