Search in sources :

Example 1 with StringSetEntity

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

the class StringSet method testHistoryOfSse1.

@Test
public void testHistoryOfSse1() {
    StringSetEntity rev1 = getAuditReader().find(StringSetEntity.class, sse1_id, 1);
    StringSetEntity rev2 = getAuditReader().find(StringSetEntity.class, sse1_id, 2);
    StringSetEntity rev3 = getAuditReader().find(StringSetEntity.class, sse1_id, 3);
    assert rev1.getStrings().equals(Collections.EMPTY_SET);
    assert rev2.getStrings().equals(TestTools.makeSet("sse1_string1", "sse1_string2"));
    assert rev3.getStrings().equals(TestTools.makeSet("sse1_string1", "sse1_string2"));
}
Also used : StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) Test(org.junit.Test)

Example 2 with StringSetEntity

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

the class StringSet method testHistoryOfSse2.

@Test
public void testHistoryOfSse2() {
    StringSetEntity rev1 = getAuditReader().find(StringSetEntity.class, sse2_id, 1);
    StringSetEntity rev2 = getAuditReader().find(StringSetEntity.class, sse2_id, 2);
    StringSetEntity rev3 = getAuditReader().find(StringSetEntity.class, sse2_id, 3);
    assert rev1.getStrings().equals(TestTools.makeSet("sse2_string1", "sse2_string2"));
    assert rev2.getStrings().equals(TestTools.makeSet("sse2_string1", "sse2_string2"));
    assert rev3.getStrings().equals(TestTools.makeSet("sse2_string2"));
}
Also used : StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) Test(org.junit.Test)

Example 3 with StringSetEntity

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

the class RemovedObjectQueryTest method testElementCollection.

@Test
public void testElementCollection() {
    List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(StringSetEntity.class, false, true).add(AuditEntity.id().eq(stringSetId)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
    Object[] objArray = (Object[]) queryResult.get(0);
    Assert.assertEquals(12, getRevisionNumber(objArray[1]));
    StringSetEntity stringSetEntity = (StringSetEntity) objArray[0];
    Assert.assertEquals(TestTools.makeSet("string 1", "string 2"), stringSetEntity.getStrings());
}
Also used : StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with StringSetEntity

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

the class StringSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StringSetEntity sse1 = new StringSetEntity();
    StringSetEntity sse2 = new StringSetEntity();
    // Revision 1 (sse1: initialy empty, sse2: initialy 2 elements)
    em.getTransaction().begin();
    sse2.getStrings().add("sse2_string1");
    sse2.getStrings().add("sse2_string2");
    em.persist(sse1);
    em.persist(sse2);
    em.getTransaction().commit();
    // Revision 2 (sse1: adding 2 elements, sse2: adding an existing element)
    em.getTransaction().begin();
    sse1 = em.find(StringSetEntity.class, sse1.getId());
    sse2 = em.find(StringSetEntity.class, sse2.getId());
    sse1.getStrings().add("sse1_string1");
    sse1.getStrings().add("sse1_string2");
    sse2.getStrings().add("sse2_string1");
    em.getTransaction().commit();
    // Revision 3 (sse1: removing a non-existing element, sse2: removing one element)
    em.getTransaction().begin();
    sse1 = em.find(StringSetEntity.class, sse1.getId());
    sse2 = em.find(StringSetEntity.class, sse2.getId());
    sse1.getStrings().remove("sse1_string3");
    sse2.getStrings().remove("sse2_string1");
    em.getTransaction().commit();
    // 
    sse1_id = sse1.getId();
    sse2_id = sse2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 5 with StringSetEntity

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

the class CollectionNullValueTest method initData.

@Test
@Priority(10)
public void initData() {
    // Persist map with null values
    mapId = doInJPA(this::entityManagerFactory, entityManager -> {
        final StringMapEntity sme = new StringMapEntity();
        sme.getStrings().put("A", "B");
        sme.getStrings().put("B", null);
        entityManager.persist(sme);
        return sme.getId();
    });
    // Update map with null values
    doInJPA(this::entityManagerFactory, entityManager -> {
        final StringMapEntity sme = entityManager.find(StringMapEntity.class, mapId);
        sme.getStrings().put("C", null);
        sme.getStrings().put("D", "E");
        sme.getStrings().remove("A");
        entityManager.merge(sme);
    });
    // Persist list with null values
    listId = doInJPA(this::entityManagerFactory, entityManager -> {
        final StringListEntity sle = new StringListEntity();
        sle.getStrings().add("A");
        sle.getStrings().add(null);
        entityManager.persist(sle);
        return sle.getId();
    });
    // Update list with null values
    doInJPA(this::entityManagerFactory, entityManager -> {
        final StringListEntity sle = entityManager.find(StringListEntity.class, listId);
        sle.getStrings().add(null);
        sle.getStrings().add("D");
        sle.getStrings().remove("A");
        entityManager.merge(sle);
    });
    // Persist set with null values
    setId = doInJPA(this::entityManagerFactory, entityManager -> {
        final StringSetEntity sse = new StringSetEntity();
        sse.getStrings().add("A");
        sse.getStrings().add(null);
        entityManager.persist(sse);
        return sse.getId();
    });
    // Update set with null values
    doInJPA(this::entityManagerFactory, entityManager -> {
        final StringSetEntity sse = entityManager.find(StringSetEntity.class, setId);
        sse.getStrings().add(null);
        sse.getStrings().add("D");
        sse.getStrings().remove("A");
        entityManager.merge(sse);
    });
}
Also used : Priority(org.hibernate.envers.test.Priority) TestForIssue(org.hibernate.testing.TestForIssue) Arrays(java.util.Arrays) List(java.util.List) TransactionUtil.doInJPA(org.hibernate.testing.transaction.TransactionUtil.doInJPA) BaseEnversJPAFunctionalTestCase(org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase) TestTools(org.hibernate.envers.test.tools.TestTools) StringMapEntity(org.hibernate.envers.test.entities.collection.StringMapEntity) Test(org.junit.Test) StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) Assert.assertEquals(org.junit.Assert.assertEquals) StringListEntity(org.hibernate.envers.test.entities.collection.StringListEntity) StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) StringMapEntity(org.hibernate.envers.test.entities.collection.StringMapEntity) StringListEntity(org.hibernate.envers.test.entities.collection.StringListEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)8 Test (org.junit.Test)8 Priority (org.hibernate.envers.test.Priority)4 EntityManager (javax.persistence.EntityManager)3 List (java.util.List)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 BaseEnversJPAFunctionalTestCase (org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)1 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)1 StringListEntity (org.hibernate.envers.test.entities.collection.StringListEntity)1 StringMapEntity (org.hibernate.envers.test.entities.collection.StringMapEntity)1 ListOwnedEntity (org.hibernate.envers.test.entities.manytomany.ListOwnedEntity)1 ListOwningEntity (org.hibernate.envers.test.entities.manytomany.ListOwningEntity)1 SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)1 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)1 M2MIndexedListTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1