use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerCollectionsTest method testUpdateAddToCollectionCreate.
@Test
public void testUpdateAddToCollectionCreate() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = evm.create(UpdatablePersonView.class);
// When
newPerson.setName("newPerson");
docView.setPeople(new ArrayList<>(docView.getPeople()));
docView.getPeople().add(newPerson);
saveWith(docView, flusherBuilder -> {
flusherBuilder.onPrePersist(UpdatablePersonView.class, Person.class, (view, entity) -> {
entity.setAge(10L);
});
});
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
assertEquals("newPerson", doc1.getPeople().get(1).getName());
assertEquals(10L, doc1.getPeople().get(1).getAge());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerCollectionsTest method assertSubviewEquals.
public void assertSubviewEquals(Collection<Person> persons, Collection<UpdatablePersonView> personSubviews) {
if (persons == null) {
assertNull(personSubviews);
return;
}
assertNotNull(personSubviews);
assertEquals(persons.size(), personSubviews.size());
for (Person p : persons) {
boolean found = false;
for (UpdatablePersonView pSub : personSubviews) {
if (p.getName().equals(pSub.getName())) {
found = true;
break;
}
}
if (!found) {
Assert.fail("Could not find a person subview instance with the name: " + p.getName());
}
}
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerCollectionsTest method testUpdateAddToCollectionAndModify.
@Test
public void testUpdateAddToCollectionAndModify() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
newPerson.setName("newPerson");
docView.getPeople().add(newPerson);
update(docView);
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
assertEquals("newPerson", p2.getName());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
docView.getContacts().put(2, newPerson);
saveWith(docView, flushOperationBuilder -> {
flushOperationBuilder.onPreUpdate(UpdatableDocumentWithMapsView.class, view -> {
MapChangeModel<UpdatableDocumentWithMapsView, UpdatablePersonView> changeModel = (MapChangeModel<UpdatableDocumentWithMapsView, UpdatablePersonView>) (ChangeModel<?>) evm.getChangeModel(view).get("contacts");
assertEquals(newPerson, changeModel.getAddedElements().get(0).getCurrentState());
});
});
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method assertSubviewEquals.
public static void assertSubviewEquals(Map<Integer, Person> persons, Map<Integer, ? extends UpdatablePersonView> personSubviews) {
if (persons == null) {
assertNull(personSubviews);
return;
}
assertNotNull(personSubviews);
assertEquals(persons.size(), personSubviews.size());
for (Map.Entry<Integer, Person> entry : persons.entrySet()) {
Person p = entry.getValue();
boolean found = false;
UpdatablePersonView pSub = personSubviews.get(entry.getKey());
if (pSub != null) {
if (p.getName().equals(pSub.getName())) {
found = true;
break;
}
}
if (!found) {
Assert.fail("Could not find a person subview instance with the name: " + p.getName());
}
}
}
Aggregations