Search in sources :

Example 1 with StringMapEntity

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

the class StringMap method testHistoryOfSse1.

@Test
public void testHistoryOfSse1() {
    StringMapEntity rev1 = getAuditReader().find(StringMapEntity.class, sme1_id, 1);
    StringMapEntity rev2 = getAuditReader().find(StringMapEntity.class, sme1_id, 2);
    StringMapEntity rev3 = getAuditReader().find(StringMapEntity.class, sme1_id, 3);
    StringMapEntity rev4 = getAuditReader().find(StringMapEntity.class, sme1_id, 4);
    assert rev1.getStrings().equals(Collections.EMPTY_MAP);
    assert rev2.getStrings().equals(TestTools.makeMap("1", "a", "2", "b"));
    assert rev3.getStrings().equals(TestTools.makeMap("2", "b"));
    assert rev4.getStrings().equals(TestTools.makeMap("2", "b"));
}
Also used : StringMapEntity(org.hibernate.envers.test.entities.collection.StringMapEntity) Test(org.junit.Test)

Example 2 with StringMapEntity

use of org.hibernate.envers.test.entities.collection.StringMapEntity 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)

Example 3 with StringMapEntity

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

the class StringMap method testHistoryOfSse2.

@Test
public void testHistoryOfSse2() {
    StringMapEntity rev1 = getAuditReader().find(StringMapEntity.class, sme2_id, 1);
    StringMapEntity rev2 = getAuditReader().find(StringMapEntity.class, sme2_id, 2);
    StringMapEntity rev3 = getAuditReader().find(StringMapEntity.class, sme2_id, 3);
    StringMapEntity rev4 = getAuditReader().find(StringMapEntity.class, sme2_id, 4);
    assert rev1.getStrings().equals(TestTools.makeMap("1", "a"));
    assert rev2.getStrings().equals(TestTools.makeMap("1", "a"));
    assert rev3.getStrings().equals(TestTools.makeMap("1", "b"));
    assert rev4.getStrings().equals(TestTools.makeMap("1", "b"));
}
Also used : StringMapEntity(org.hibernate.envers.test.entities.collection.StringMapEntity) Test(org.junit.Test)

Example 4 with StringMapEntity

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

the class StringMap method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StringMapEntity sme1 = new StringMapEntity();
    StringMapEntity sme2 = new StringMapEntity();
    // Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping)
    em.getTransaction().begin();
    sme2.getStrings().put("1", "a");
    em.persist(sme1);
    em.persist(sme2);
    em.getTransaction().commit();
    // Revision 2 (sme1: adding 2 mappings, sme2: no changes)
    em.getTransaction().begin();
    sme1 = em.find(StringMapEntity.class, sme1.getId());
    sme2 = em.find(StringMapEntity.class, sme2.getId());
    sme1.getStrings().put("1", "a");
    sme1.getStrings().put("2", "b");
    em.getTransaction().commit();
    // Revision 3 (sme1: removing an existing mapping, sme2: replacing a value)
    em.getTransaction().begin();
    sme1 = em.find(StringMapEntity.class, sme1.getId());
    sme2 = em.find(StringMapEntity.class, sme2.getId());
    sme1.getStrings().remove("1");
    sme2.getStrings().put("1", "b");
    em.getTransaction().commit();
    // No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value)
    em.getTransaction().begin();
    sme1 = em.find(StringMapEntity.class, sme1.getId());
    sme2 = em.find(StringMapEntity.class, sme2.getId());
    sme1.getStrings().remove("3");
    sme2.getStrings().put("1", "b");
    em.getTransaction().commit();
    // 
    sme1_id = sme1.getId();
    sme2_id = sme2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) StringMapEntity(org.hibernate.envers.test.entities.collection.StringMapEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 5 with StringMapEntity

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

the class CollectionNullValueTest method testStringMapHistory.

@Test
public void testStringMapHistory() {
    final List<Number> revisions = getAuditReader().getRevisions(StringMapEntity.class, mapId);
    assertEquals(Arrays.asList(1, 2), revisions);
    final StringMapEntity rev1 = getAuditReader().find(StringMapEntity.class, mapId, 1);
    assertEquals(TestTools.makeMap("A", "B"), rev1.getStrings());
    final StringMapEntity rev2 = getAuditReader().find(StringMapEntity.class, mapId, 2);
    assertEquals(TestTools.makeMap("D", "E"), rev2.getStrings());
}
Also used : StringMapEntity(org.hibernate.envers.test.entities.collection.StringMapEntity) Test(org.junit.Test)

Aggregations

StringMapEntity (org.hibernate.envers.test.entities.collection.StringMapEntity)6 Test (org.junit.Test)6 Priority (org.hibernate.envers.test.Priority)3 EntityManager (javax.persistence.EntityManager)2 Arrays (java.util.Arrays)1 List (java.util.List)1 BaseEnversJPAFunctionalTestCase (org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase)1 StringListEntity (org.hibernate.envers.test.entities.collection.StringListEntity)1 StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)1 TestTools (org.hibernate.envers.test.tools.TestTools)1 TestForIssue (org.hibernate.testing.TestForIssue)1 TransactionUtil.doInJPA (org.hibernate.testing.transaction.TransactionUtil.doInJPA)1 Assert.assertEquals (org.junit.Assert.assertEquals)1