added class documentation to new test

This commit is contained in:
Oliver Lorenz 2011-05-25 19:20:01 +02:00 committed by adamw
parent 51df2f78e4
commit c173762e59
1 changed files with 26 additions and 24 deletions

View File

@ -12,11 +12,13 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
* Tests whether the mapping of many-to-many Sets is * Tests the ValidityAuditStrategy on many-to-many Sets.
* It was first introduced because of a bug when adding and removing the same element
* from the set multiple times between database persists.
* Created on: 24.05.11 * Created on: 24.05.11
* *
* @author Oliver Lorenz * @author Oliver Lorenz
* @since 0.0 * @since 3.6.5
*/ */
public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest { public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest {
@ -29,33 +31,33 @@ public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest {
cfg.addAnnotatedClass(SetOwningEntity.class); cfg.addAnnotatedClass(SetOwningEntity.class);
cfg.addAnnotatedClass(SetOwnedEntity.class); cfg.addAnnotatedClass(SetOwnedEntity.class);
cfg.setProperty("org.hibernate.envers.audit_strategy", cfg.setProperty("org.hibernate.envers.audit_strategy",
"org.hibernate.envers.strategy.ValidityAuditStrategy"); "org.hibernate.envers.strategy.ValidityAuditStrategy");
} }
@BeforeClass(enabled = true, dependsOnMethods = "init") @BeforeClass(enabled = true, dependsOnMethods = "init")
public void initData() { public void initData() {
final EntityManager em = getEntityManager(); final EntityManager em = getEntityManager();
final SetOwningEntity setOwningEntity = new SetOwningEntity(1, "parent"); final SetOwningEntity setOwningEntity = new SetOwningEntity(1, "parent");
final SetOwnedEntity setOwnedEntity = new SetOwnedEntity(2, "child"); final SetOwnedEntity setOwnedEntity = new SetOwnedEntity(2, "child");
// Initial persist // Initial persist
em.getTransaction().begin(); em.getTransaction().begin();
em.persist(setOwningEntity); em.persist(setOwningEntity);
em.persist(setOwnedEntity); em.persist(setOwnedEntity);
em.getTransaction().commit(); em.getTransaction().commit();
em.clear(); em.clear();
ing_id = setOwningEntity.getId(); ing_id = setOwningEntity.getId();
ed_id = setOwnedEntity.getId(); ed_id = setOwnedEntity.getId();
} }
@Test(enabled = true) @Test(enabled = true)
public void testMultipleAddAndRemove() { public void testMultipleAddAndRemove() {
final EntityManager em = getEntityManager(); final EntityManager em = getEntityManager();
// add child for first time // add child for first time
em.getTransaction().begin(); em.getTransaction().begin();
@ -66,8 +68,8 @@ public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest {
owningEntity.setReferences(new HashSet<SetOwnedEntity>()); owningEntity.setReferences(new HashSet<SetOwnedEntity>());
owningEntity.getReferences().add(ownedEntity); owningEntity.getReferences().add(ownedEntity);
em.getTransaction().commit(); em.getTransaction().commit();
em.clear(); em.clear();
// remove child // remove child
em.getTransaction().begin(); em.getTransaction().begin();
@ -77,8 +79,8 @@ public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest {
owningEntity.getReferences().remove(ownedEntity); owningEntity.getReferences().remove(ownedEntity);
em.getTransaction().commit(); em.getTransaction().commit();
em.clear(); em.clear();
// add child again // add child again
em.getTransaction().begin(); em.getTransaction().begin();
@ -88,8 +90,8 @@ public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest {
owningEntity.getReferences().add(ownedEntity); owningEntity.getReferences().add(ownedEntity);
em.getTransaction().commit(); em.getTransaction().commit();
em.clear(); em.clear();
// remove child again // remove child again
em.getTransaction().begin(); em.getTransaction().begin();
@ -99,8 +101,8 @@ public class ValidityAuditStrategyManyToManyTest extends AbstractEntityTest {
owningEntity.getReferences().remove(ownedEntity); owningEntity.getReferences().remove(ownedEntity);
em.getTransaction().commit(); em.getTransaction().commit();
em.clear(); em.clear();
// now the set owning entity list should be empty again // now the set owning entity list should be empty again
owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id); owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);