Search in sources :

Example 1 with StrIntTestEntity

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

the class TotalAuditParentsTest method testCompleteAuditParents.

@Test
public void testCompleteAuditParents() {
    // expectedBaby.notAudited shall be null, because it is not audited.
    BabyCompleteEntity expectedBaby = new BabyCompleteEntity(babyCompleteId, "grandparent 1", null, "parent 1", "child 1", new StrIntTestEntity("data 1", 1, siteCompleteId), "baby 1");
    BabyCompleteEntity baby = getAuditReader().find(BabyCompleteEntity.class, babyCompleteId, 1);
    Assert.assertEquals(expectedBaby, baby);
    Assert.assertEquals(expectedBaby.getRelation().getId(), baby.getRelation().getId());
}
Also used : StrIntTestEntity(org.hibernate.orm.test.envers.entities.StrIntTestEntity) Test(org.junit.Test)

Example 2 with StrIntTestEntity

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

the class SingleAuditParentsTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    StrIntTestEntity siteSingle = new StrIntTestEntity("data 1", 1);
    em.persist(siteSingle);
    em.persist(new ChildSingleParentEntity(childSingleId, "grandparent 1", "notAudited 1", "parent 1", "child 1", siteSingle));
    em.getTransaction().commit();
    siteSingleId = siteSingle.getId();
    em.close();
}
Also used : StrIntTestEntity(org.hibernate.orm.test.envers.entities.StrIntTestEntity) EntityManager(jakarta.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.orm.test.envers.Priority)

Example 3 with StrIntTestEntity

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

the class RevisionConstraintQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
    StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
    em.persist(site1);
    em.persist(site2);
    id1 = site1.getId();
    Integer id2 = site2.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setStr1("d");
    site2.setNumber(20);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setNumber(1);
    site2.setStr1("z");
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setNumber(5);
    site2.setStr1("a");
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.orm.test.envers.entities.StrIntTestEntity) EntityManager(jakarta.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.orm.test.envers.Priority)

Example 4 with StrIntTestEntity

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

the class RevisionConstraintQuery method testRevisionTypeEqQuery.

@Test
public void testRevisionTypeEqQuery() {
    // The query shouldn't be ordered as always, otherwise - we get an exception.
    List results = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, true, true).add(AuditEntity.id().eq(id1)).add(AuditEntity.revisionType().eq(RevisionType.MOD)).getResultList();
    Assert.assertEquals(3, results.size());
    Assert.assertEquals(new StrIntTestEntity("d", 10, id1), results.get(0));
    Assert.assertEquals(new StrIntTestEntity("d", 1, id1), results.get(1));
    Assert.assertEquals(new StrIntTestEntity("d", 5, id1), results.get(2));
}
Also used : StrIntTestEntity(org.hibernate.orm.test.envers.entities.StrIntTestEntity) List(java.util.List) Test(org.junit.Test)

Example 5 with StrIntTestEntity

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

the class StoreDeletedData method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
    em.persist(site1);
    id1 = site1.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    em.remove(site1);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    StrIntTestEntity site2 = new StrIntTestEntity("b", 20);
    em.persist(site2);
    id2 = site2.getId();
    StrIntTestEntity site3 = new StrIntTestEntity("c", 30);
    em.persist(site3);
    id3 = site3.getId();
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    em.remove(site2);
    em.remove(site3);
    em.getTransaction().commit();
    em.close();
}
Also used : StrIntTestEntity(org.hibernate.orm.test.envers.entities.StrIntTestEntity) EntityManager(jakarta.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.orm.test.envers.Priority)

Aggregations

StrIntTestEntity (org.hibernate.orm.test.envers.entities.StrIntTestEntity)37 Test (org.junit.Test)37 List (java.util.List)15 Priority (org.hibernate.orm.test.envers.Priority)13 EntityManager (jakarta.persistence.EntityManager)12 StrTestEntity (org.hibernate.orm.test.envers.entities.StrTestEntity)8 TestForIssue (org.hibernate.testing.TestForIssue)8 RevisionType (org.hibernate.envers.RevisionType)6 HashSet (java.util.HashSet)3 AuditDisjunction (org.hibernate.envers.query.criteria.AuditDisjunction)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 AuditEntity (org.hibernate.envers.query.AuditEntity)1 AuditCriterion (org.hibernate.envers.query.criteria.AuditCriterion)1 NullPrecedence (org.hibernate.envers.query.order.NullPrecedence)1 BaseEnversJPAFunctionalTestCase (org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase)1 EmbId (org.hibernate.orm.test.envers.entities.ids.EmbId)1 EmbIdTestEntity (org.hibernate.orm.test.envers.entities.ids.EmbIdTestEntity)1 MulId (org.hibernate.orm.test.envers.entities.ids.MulId)1 MulIdTestEntity (org.hibernate.orm.test.envers.entities.ids.MulIdTestEntity)1