Search in sources :

Example 51 with StrTestEntity

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

the class BasicUniSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StrTestEntity ed1 = new StrTestEntity("data_ed_1");
    StrTestEntity ed2 = new StrTestEntity("data_ed_2");
    SetUniEntity ing1 = new SetUniEntity(3, "data_ing_1");
    SetUniEntity ing2 = new SetUniEntity(4, "data_ing_2");
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ing2 = em.find(SetUniEntity.class, ing2.getId());
    ed1 = em.find(StrTestEntity.class, ed1.getId());
    ed2 = em.find(StrTestEntity.class, ed2.getId());
    ing1.setReferences(new HashSet<StrTestEntity>());
    ing1.getReferences().add(ed1);
    ing2.setReferences(new HashSet<StrTestEntity>());
    ing2.getReferences().add(ed1);
    ing2.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ed2 = em.find(StrTestEntity.class, ed2.getId());
    ed1 = em.find(StrTestEntity.class, ed1.getId());
    ing1.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ed2 = em.find(StrTestEntity.class, ed2.getId());
    ed1 = em.find(StrTestEntity.class, ed1.getId());
    ing1.getReferences().remove(ed1);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ing1.setReferences(null);
    em.getTransaction().commit();
    // 
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) SetUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 52 with StrTestEntity

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

the class CustomComparatorEntityTest method testCurrentStateOfEntity1.

@Test
public void testCurrentStateOfEntity1() {
    final SortedSetEntity entity1 = getEntityManager().find(SortedSetEntity.class, 1);
    assertEquals("sortedEntity1", entity1.getData());
    assertEquals(Integer.valueOf(1), entity1.getId());
    final SortedSet<StrTestEntity> sortedSet = entity1.getSortedSet();
    assertEquals(StrTestEntityComparator.class, sortedSet.comparator().getClass());
    assertEquals(4, sortedSet.size());
    final Iterator<StrTestEntity> iterator = sortedSet.iterator();
    checkStrTestEntity(iterator.next(), id2, "aaa");
    checkStrTestEntity(iterator.next(), id4, "aac");
    checkStrTestEntity(iterator.next(), id3, "aba");
    checkStrTestEntity(iterator.next(), id1, "abc");
    final SortedMap<StrTestEntity, String> sortedMap = entity1.getSortedMap();
    assertEquals(StrTestEntityComparator.class, sortedMap.comparator().getClass());
    assertEquals(4, sortedMap.size());
    Iterator<Map.Entry<StrTestEntity, String>> mapIterator = sortedMap.entrySet().iterator();
    checkStrTestEntity(mapIterator.next().getKey(), id2, "aaa");
    checkStrTestEntity(mapIterator.next().getKey(), id4, "aac");
    checkStrTestEntity(mapIterator.next().getKey(), id3, "aba");
    checkStrTestEntity(mapIterator.next().getKey(), id1, "abc");
    mapIterator = sortedMap.entrySet().iterator();
    assertEquals(mapIterator.next().getValue(), "aaa");
    assertEquals(mapIterator.next().getValue(), "aac");
    assertEquals(mapIterator.next().getValue(), "aba");
    assertEquals(mapIterator.next().getValue(), "abc");
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) SortedSetEntity(org.hibernate.envers.test.entities.manytomany.SortedSetEntity) Test(org.junit.Test)

Example 53 with StrTestEntity

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

the class BasicUniList method testHistoryOfEdIng2.

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

Example 54 with StrTestEntity

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

the class BasicUniSet method testHistoryOfEdIng1.

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

Example 55 with StrTestEntity

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

the class LongRevNumber method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity te = new StrTestEntity("x");
    em.persist(te);
    id = te.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    te = em.find(StrTestEntity.class, id);
    te.setStr("y");
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)103 Test (org.junit.Test)99 EntityManager (javax.persistence.EntityManager)51 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 TestForIssue (org.hibernate.testing.TestForIssue)5 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)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