From fd54b2df565e362d3e8a97920e2dfb5ceab0176f Mon Sep 17 00:00:00 2001 From: Svyatoslav Reyentenko Date: Thu, 2 Dec 2010 03:07:03 +0300 Subject: [PATCH 1/5] Test for creating revision on collection change --- .../CollectionChangeNoRevisionTest.java | 59 +++++++++++++++++++ .../collection/norevision/Name.java | 39 ++++++++++++ .../collection/norevision/Person.java | 36 +++++++++++ .../mappings/norevision/mappings.hbm.xml | 21 +++++++ 4 files changed, 155 insertions(+) create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java create mode 100644 hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java new file mode 100644 index 0000000000..329119761d --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -0,0 +1,59 @@ +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; + +public class CollectionChangeNoRevisionTest extends AbstractSessionTest { + + private Integer personId; + + @Override + protected void initMappings() throws MappingException, URISyntaxException { + URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/norevision/mappings.hbm.xml"); + config.addFile(new File(url.toURI())); + config.setProperty("org.hibernate.envers.revision_on_collection_change", "false"); + } + + @BeforeMethod(firstTimeOnly = true) + public void initData() { + newSessionFactory(); + Person p = new Person(); + Name n = new Name(); + n.setName("name1"); + p.getNames().add(n); + Transaction transaction = getSession().beginTransaction(); + getSession().saveOrUpdate(p); + transaction.commit(); + personId = p.getId(); + System.err.print(p); + + } + + @Test + 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(); + int size = getAuditReader().getRevisions(Person.class, personId).size(); + System.out.println(size); + Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), "false"); + Assert.assertEquals(size, 1); + } + + +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java new file mode 100644 index 0000000000..8d48fc1ee7 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java @@ -0,0 +1,39 @@ +package org.hibernate.envers.test.integration.collection.norevision; + +import org.hibernate.envers.Audited; + +import java.io.Serializable; + +@Audited +public class Name implements Serializable { + + private Integer id; + + private String name; + + private Person person; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Person getPerson() { + return person; + } + + public void setPerson(Person person) { + this.person = person; + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java new file mode 100644 index 0000000000..0d4c3817d7 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java @@ -0,0 +1,36 @@ +package org.hibernate.envers.test.integration.collection.norevision; + +import org.hibernate.envers.AuditMappedBy; +import org.hibernate.envers.Audited; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +@Audited +public class Person implements Serializable { + + private Integer id; + @AuditMappedBy(mappedBy = "person") + private Set names; + + public Person() { + names = new HashSet(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Set getNames() { + return names; + } + + public void setNames(Set names) { + this.names = names; + } +} diff --git a/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml new file mode 100644 index 0000000000..db1463c71c --- /dev/null +++ b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From e831e29435845c4511e10acb9b9bff22f98604d7 Mon Sep 17 00:00:00 2001 From: Svyatoslav Reyentenko Date: Thu, 2 Dec 2010 03:34:10 +0300 Subject: [PATCH 2/5] Ignore collection changes if no revision on collection change is set --- .../envers/event/AuditEventListener.java | 4 ++- .../CollectionChangRevisionTest.java | 27 ++++++++++++++++ .../CollectionChangeNoRevisionTest.java | 32 +++++++++++++++---- .../mappings/norevision/mappings.hbm.xml | 2 +- .../src/test/resources/testng.xml | 1 + 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java index 3cbfc70d4a..9beeb9e1e5 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java @@ -257,7 +257,9 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv private void onCollectionAction(AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl, CollectionEntry collectionEntry) { String entityName = event.getAffectedOwnerEntityName(); - + if (! verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) { + return; + } if (verCfg.getEntCfg().isVersioned(entityName)) { AuditProcess auditProcess = verCfg.getSyncManager().get(event.getSession()); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java new file mode 100644 index 0000000000..fb9bd8a7e5 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java @@ -0,0 +1,27 @@ +package org.hibernate.envers.test.integration.collection.norevision; + +import org.hibernate.MappingException; +import org.testng.annotations.BeforeMethod; + +import java.net.URISyntaxException; + +public class CollectionChangRevisionTest 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; + } + + @Override + protected String getCollectionChangeValue() { + return NEW_REVISION_ON_COLLECTION; + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java index 329119761d..3786856b8d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -13,16 +13,26 @@ import org.testng.annotations.Test; import java.io.File; import java.net.URISyntaxException; import java.net.URL; +import java.util.ArrayList; +import java.util.List; public class CollectionChangeNoRevisionTest extends AbstractSessionTest { - private Integer personId; + 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 Integer personId; + protected List namesId = new ArrayList(); @Override protected void initMappings() throws MappingException, URISyntaxException { URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/norevision/mappings.hbm.xml"); config.addFile(new File(url.toURI())); - config.setProperty("org.hibernate.envers.revision_on_collection_change", "false"); + config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue()); + } + + protected String getCollectionChangeValue() { + return CREATE_REVISION_ON_COLLECTION_CHANGE; } @BeforeMethod(firstTimeOnly = true) @@ -36,7 +46,7 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest { getSession().saveOrUpdate(p); transaction.commit(); personId = p.getId(); - System.err.print(p); + namesId.add(n.getId()); } @@ -49,10 +59,18 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest { Transaction transaction = getSession().beginTransaction(); getSession().saveOrUpdate(p); transaction.commit(); - int size = getAuditReader().getRevisions(Person.class, personId).size(); - System.out.println(size); - Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), "false"); - Assert.assertEquals(size, 1); + namesId.add(n2.getId()); + int sizePerson = getAuditReader().getRevisions(Person.class, personId).size(); + Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), getCollectionChangeValue()); + 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() { + return EXPECTED_PERSON_REVISION_COUNT; } diff --git a/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml index db1463c71c..dc3dd6b005 100644 --- a/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml +++ b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml @@ -16,6 +16,6 @@ + column="Person_Id" cascade="save-update" update="false" insert="false"/> \ No newline at end of file diff --git a/hibernate-envers/src/test/resources/testng.xml b/hibernate-envers/src/test/resources/testng.xml index da3f6768f6..905743a18a 100644 --- a/hibernate-envers/src/test/resources/testng.xml +++ b/hibernate-envers/src/test/resources/testng.xml @@ -6,6 +6,7 @@ + From c2ba8360c8d298d42233c3ee1db77b3d3a7517a4 Mon Sep 17 00:00:00 2001 From: Svyatoslav Reyentenko Date: Thu, 2 Dec 2010 23:58:58 +0300 Subject: [PATCH 3/5] Tests are slightly changed to do more work --- .../CollectionChangeNoRevisionTest.java | 34 +++++++------------ ...java => CollectionChangeRevisionTest.java} | 2 +- 2 files changed, 14 insertions(+), 22 deletions(-) rename hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/{CollectionChangRevisionTest.java => CollectionChangeRevisionTest.java} (89%) diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java index 3786856b8d..767920a817 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -19,10 +19,8 @@ import java.util.List; public class CollectionChangeNoRevisionTest extends AbstractSessionTest { 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 Integer personId; - protected List namesId = new ArrayList(); @Override protected void initMappings() throws MappingException, URISyntaxException { @@ -35,38 +33,32 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest { return CREATE_REVISION_ON_COLLECTION_CHANGE; } - @BeforeMethod(firstTimeOnly = true) + @BeforeClass(dependsOnMethods = "init") public void initData() { newSessionFactory(); Person p = new Person(); Name n = new Name(); n.setName("name1"); p.getNames().add(n); - Transaction transaction = getSession().beginTransaction(); + getSession().getTransaction().begin(); getSession().saveOrUpdate(p); - transaction.commit(); + getSession().getTransaction().commit(); 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 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(); - Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), getCollectionChangeValue()); - Assert.assertEquals(sizePerson, getExpectedPersonRevisionCount()); - for (Integer id : namesId) { - int sizeName = getAuditReader().getRevisions(Name.class, id).size(); - Assert.assertEquals(sizeName, EXPECTED_NAME_REVISION_COUNT); - } + assert sizePerson == getExpectedPersonRevisionCount(); } protected int getExpectedPersonRevisionCount() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java similarity index 89% rename from hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java rename to hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java index fb9bd8a7e5..d48fec6a8a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java @@ -5,7 +5,7 @@ import org.testng.annotations.BeforeMethod; 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 String NEW_REVISION_ON_COLLECTION = "true"; From 76b59a702c9740db07f917b006b2a69747992200 Mon Sep 17 00:00:00 2001 From: Svyatoslav Reyentenko Date: Mon, 6 Dec 2010 23:44:14 +0300 Subject: [PATCH 4/5] Moved hbm.xml -> annotations. --- .../CollectionChangeNoRevisionTest.java | 4 ++-- .../collection/norevision/Name.java | 8 +++++-- .../collection/norevision/Person.java | 6 +++++- .../mappings/norevision/mappings.hbm.xml | 21 ------------------- 4 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java index 767920a817..129406e164 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -24,8 +24,8 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest { @Override protected void initMappings() throws MappingException, URISyntaxException { - URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/norevision/mappings.hbm.xml"); - config.addFile(new File(url.toURI())); + config.addAnnotatedClass(Person.class); + config.addAnnotatedClass(Name.class); config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue()); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java index 8d48fc1ee7..0c03fe9643 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java @@ -2,15 +2,19 @@ package org.hibernate.envers.test.integration.collection.norevision; import org.hibernate.envers.Audited; +import javax.persistence.*; import java.io.Serializable; @Audited +@Entity public class Name implements Serializable { - + @Id + @GeneratedValue private Integer id; private String name; - + @ManyToOne + @JoinColumn(name = "person_id", insertable = false, updatable = false) private Person person; public Integer getId() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java index 0d4c3817d7..512b0a89e1 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java @@ -3,15 +3,19 @@ package org.hibernate.envers.test.integration.collection.norevision; import org.hibernate.envers.AuditMappedBy; import org.hibernate.envers.Audited; +import javax.persistence.*; import java.io.Serializable; import java.util.HashSet; import java.util.Set; @Audited +@Entity public class Person implements Serializable { - + @Id @GeneratedValue private Integer id; @AuditMappedBy(mappedBy = "person") + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "person_id") private Set names; public Person() { diff --git a/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml deleted file mode 100644 index dc3dd6b005..0000000000 --- a/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 4e102c68c1d7b377b06936d0221f0f331f63a515 Mon Sep 17 00:00:00 2001 From: adamw Date: Wed, 8 Dec 2010 19:56:04 +0100 Subject: [PATCH 5/5] Refactoring the norevision tests: checking explicitly the revision numbers, introducing an abstract common class --- .../AbstractCollectionChangeTest.java | 58 ++++++++++++++++ .../CollectionChangeNoRevisionTest.java | 68 ++----------------- .../CollectionChangeRevisionTest.java | 29 +++----- 3 files changed, 74 insertions(+), 81 deletions(-) create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java new file mode 100644 index 0000000000..19cd41a18e --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/AbstractCollectionChangeTest.java @@ -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 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()); + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java index 129406e164..b140ca5748 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -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 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; - } - - } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java index d48fec6a8a..ccb5568b6b 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeRevisionTest.java @@ -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 getExpectedPersonRevisions() { + return Arrays.asList(1, 3); } }