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"));
}
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"));
}
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());
}
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();
}
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);
});
}
Aggregations