Search in sources :

Example 1 with EnumSetEntity

use of org.hibernate.envers.test.entities.collection.EnumSetEntity in project hibernate-orm by hibernate.

the class EnumSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    EnumSetEntity sse1 = new EnumSetEntity();
    // Revision 1 (sse1: initialy 1 element)
    em.getTransaction().begin();
    sse1.getEnums1().add(E1.X);
    sse1.getEnums2().add(E2.A);
    em.persist(sse1);
    em.getTransaction().commit();
    // Revision 2 (sse1: adding 1 element/removing a non-existing element)
    em.getTransaction().begin();
    sse1 = em.find(EnumSetEntity.class, sse1.getId());
    sse1.getEnums1().add(E1.Y);
    sse1.getEnums2().remove(E2.B);
    em.getTransaction().commit();
    // Revision 3 (sse1: removing 1 element/adding an exisiting element)
    em.getTransaction().begin();
    sse1 = em.find(EnumSetEntity.class, sse1.getId());
    sse1.getEnums1().remove(E1.X);
    sse1.getEnums2().add(E2.A);
    em.getTransaction().commit();
    //
    sse1_id = sse1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) EnumSetEntity(org.hibernate.envers.test.entities.collection.EnumSetEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 2 with EnumSetEntity

use of org.hibernate.envers.test.entities.collection.EnumSetEntity in project hibernate-orm by hibernate.

the class EnumSet method testHistoryOfSse1.

@Test
public void testHistoryOfSse1() {
    EnumSetEntity rev1 = getAuditReader().find(EnumSetEntity.class, sse1_id, 1);
    EnumSetEntity rev2 = getAuditReader().find(EnumSetEntity.class, sse1_id, 2);
    EnumSetEntity rev3 = getAuditReader().find(EnumSetEntity.class, sse1_id, 3);
    assert rev1.getEnums1().equals(TestTools.makeSet(E1.X));
    assert rev2.getEnums1().equals(TestTools.makeSet(E1.X, E1.Y));
    assert rev3.getEnums1().equals(TestTools.makeSet(E1.Y));
    assert rev1.getEnums2().equals(TestTools.makeSet(E2.A));
    assert rev2.getEnums2().equals(TestTools.makeSet(E2.A));
    assert rev3.getEnums2().equals(TestTools.makeSet(E2.A));
}
Also used : EnumSetEntity(org.hibernate.envers.test.entities.collection.EnumSetEntity) Test(org.junit.Test)

Example 3 with EnumSetEntity

use of org.hibernate.envers.test.entities.collection.EnumSetEntity in project hibernate-orm by hibernate.

the class HasChangedEnumSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    EnumSetEntity sse1 = new EnumSetEntity();
    // Revision 1 (sse1: initialy 1 element)
    em.getTransaction().begin();
    sse1.getEnums1().add(E1.X);
    sse1.getEnums2().add(E2.A);
    em.persist(sse1);
    em.getTransaction().commit();
    // Revision 2 (sse1: adding 1 element/removing a non-existing element)
    em.getTransaction().begin();
    sse1 = em.find(EnumSetEntity.class, sse1.getId());
    sse1.getEnums1().add(E1.Y);
    sse1.getEnums2().remove(E2.B);
    em.getTransaction().commit();
    // Revision 3 (sse1: removing 1 element/adding an exisiting element)
    em.getTransaction().begin();
    sse1 = em.find(EnumSetEntity.class, sse1.getId());
    sse1.getEnums1().remove(E1.X);
    sse1.getEnums2().add(E2.A);
    em.getTransaction().commit();
    //
    sse1_id = sse1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) EnumSetEntity(org.hibernate.envers.test.entities.collection.EnumSetEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

EnumSetEntity (org.hibernate.envers.test.entities.collection.EnumSetEntity)3 Test (org.junit.Test)3 EntityManager (javax.persistence.EntityManager)2 Priority (org.hibernate.envers.test.Priority)2