Search in sources :

Example 36 with StrTestEntity

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

the class DataChangesDetachedSet method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1);
    SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2);
    assert rev1.getCollection().equals(TestTools.makeSet());
    assert rev2.getCollection().equals(TestTools.makeSet(str1));
    assert "coll1".equals(rev1.getData());
    assert "coll2".equals(rev2.getData());
}
Also used : SetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 37 with StrTestEntity

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

the class DoubleDetachedSet method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
    DoubleSetRefCollEntity rev1 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 1);
    DoubleSetRefCollEntity rev2 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 2);
    DoubleSetRefCollEntity rev3 = getAuditReader().find(DoubleSetRefCollEntity.class, coll1_id, 3);
    assert rev1.getCollection().equals(TestTools.makeSet(str1));
    assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
    assert rev3.getCollection().equals(TestTools.makeSet(str2));
    assert rev1.getCollection2().equals(TestTools.makeSet(str2));
    assert rev2.getCollection2().equals(TestTools.makeSet(str2));
    assert rev3.getCollection2().equals(TestTools.makeSet(str1, str2));
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) DoubleSetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.DoubleSetRefCollEntity) Test(org.junit.Test)

Example 38 with StrTestEntity

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

the class BasicUniList method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    StrTestEntity ed1 = getEntityManager().find(StrTestEntity.class, ed1_id);
    StrTestEntity ed2 = getEntityManager().find(StrTestEntity.class, ed2_id);
    ListUniEntity rev1 = getAuditReader().find(ListUniEntity.class, ing1_id, 1);
    ListUniEntity rev2 = getAuditReader().find(ListUniEntity.class, ing1_id, 2);
    ListUniEntity rev3 = getAuditReader().find(ListUniEntity.class, ing1_id, 3);
    ListUniEntity rev4 = getAuditReader().find(ListUniEntity.class, ing1_id, 4);
    ListUniEntity rev5 = getAuditReader().find(ListUniEntity.class, ing1_id, 5);
    assert rev1.getReferences().equals(Collections.EMPTY_LIST);
    assert TestTools.checkCollection(rev2.getReferences(), ed1);
    assert TestTools.checkCollection(rev3.getReferences(), ed1, ed2);
    assert TestTools.checkCollection(rev4.getReferences(), ed2);
    assert rev5.getReferences().equals(Collections.EMPTY_LIST);
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) ListUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity) Test(org.junit.Test)

Example 39 with StrTestEntity

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

the class BasicUniMap method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StrTestEntity str1 = new StrTestEntity("str1");
    StrTestEntity str2 = new StrTestEntity("str2");
    MapUniEntity coll1 = new MapUniEntity(3, "coll1");
    // Revision 1 (coll1: initialy one mapping)
    em.getTransaction().begin();
    em.persist(str1);
    em.persist(str2);
    coll1.setMap(new HashMap<String, StrTestEntity>());
    coll1.getMap().put("1", str1);
    em.persist(coll1);
    em.getTransaction().commit();
    // Revision 2 (coll1: adding one mapping)
    em.getTransaction().begin();
    str2 = em.find(StrTestEntity.class, str2.getId());
    coll1 = em.find(MapUniEntity.class, coll1.getId());
    coll1.getMap().put("2", str2);
    em.getTransaction().commit();
    // Revision 3 (coll1: replacing one mapping)
    em.getTransaction().begin();
    str1 = em.find(StrTestEntity.class, str1.getId());
    coll1 = em.find(MapUniEntity.class, coll1.getId());
    coll1.getMap().put("2", str1);
    em.getTransaction().commit();
    // Revision 4 (coll1: removing one mapping)
    em.getTransaction().begin();
    coll1 = em.find(MapUniEntity.class, coll1.getId());
    coll1.getMap().remove("1");
    em.getTransaction().commit();
    //
    str1_id = str1.getId();
    str2_id = str2.getId();
    coll1_id = coll1.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) MapUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 40 with StrTestEntity

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

the class BasicUniMap method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
    MapUniEntity rev1 = getAuditReader().find(MapUniEntity.class, coll1_id, 1);
    MapUniEntity rev2 = getAuditReader().find(MapUniEntity.class, coll1_id, 2);
    MapUniEntity rev3 = getAuditReader().find(MapUniEntity.class, coll1_id, 3);
    MapUniEntity rev4 = getAuditReader().find(MapUniEntity.class, coll1_id, 4);
    assert rev1.getMap().equals(TestTools.makeMap("1", str1));
    assert rev2.getMap().equals(TestTools.makeMap("1", str1, "2", str2));
    assert rev3.getMap().equals(TestTools.makeMap("1", str1, "2", str1));
    assert rev4.getMap().equals(TestTools.makeMap("2", str1));
    assert "coll1".equals(rev1.getData());
    assert "coll1".equals(rev2.getData());
    assert "coll1".equals(rev3.getData());
    assert "coll1".equals(rev4.getData());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) MapUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity) Test(org.junit.Test)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)102 Test (org.junit.Test)98 EntityManager (javax.persistence.EntityManager)50 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)4 TestForIssue (org.hibernate.testing.TestForIssue)4 ManyToOneComponent (org.hibernate.envers.test.entities.components.relations.ManyToOneComponent)3 ManyToOneComponentTestEntity (org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity)3 OneToManyComponent (org.hibernate.envers.test.entities.components.relations.OneToManyComponent)3 OneToManyComponentTestEntity (org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity)3 SortedSetEntity (org.hibernate.envers.test.entities.manytomany.SortedSetEntity)3 ListUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity)3 SetUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity)3 List (java.util.List)2 RevisionType (org.hibernate.envers.RevisionType)2 JoinTableEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity)2 MapUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity)2