use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method testUpdateAddToCollectionAndModify.
@Test
public void testUpdateAddToCollectionAndModify() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
newPerson.setName("newPerson");
docView.getContacts().put(2, newPerson);
update(docView);
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
assertEquals("newPerson", p2.getName());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerTest method testUpdateWithCreatedSubview.
@Test
public void testUpdateWithCreatedSubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
UpdatablePersonView newOwner = evm.create(UpdatablePersonView.class);
// When
newOwner.setName("newPerson");
docView.setOwner(newOwner);
saveWith(docView, flusherBuilder -> {
flusherBuilder.onPrePersist(UpdatablePersonView.class, Person.class, (view, entity) -> {
entity.setAge(10L);
});
});
// Then
clearPersistenceContextAndReload();
assertEquals("doc1Updated", docView.getName());
assertEquals(POST_UPDATE_DATE, docView.getLastModified());
assertEquals(doc1.getName(), docView.getName());
assertEquals(newOwner.getId(), doc1.getOwner().getId());
assertEquals("newPerson", doc1.getOwner().getName());
assertEquals(10L, doc1.getOwner().getAge());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerCollectionsTest method testClearUpdateAddToCollectionAndModify.
@Test
public void testClearUpdateAddToCollectionAndModify() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
newPerson.setName("newPerson");
docView.getPeople().add(newPerson);
List<UpdatablePersonView> copy = new ArrayList<>(docView.getPeople());
docView.getPeople().clear();
docView.getPeople().addAll(copy);
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 EntityViewUpdateListenerCollectionsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
docView.getPeople().add(newPerson);
saveWith(docView, flushOperationBuilder -> {
flushOperationBuilder.onPreUpdate(UpdatableDocumentWithCollectionsView.class, view -> {
PluralChangeModel<UpdatableDocumentWithCollectionsView, UpdatablePersonView> changeModel = (PluralChangeModel<UpdatableDocumentWithCollectionsView, UpdatablePersonView>) (ChangeModel<?>) evm.getChangeModel(view).get("people");
assertEquals(newPerson, changeModel.getAddedElements().get(0).getCurrentState());
});
});
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerCollectionsTest method testUpdateAddToNewCollection.
@Test
public void testUpdateAddToNewCollection() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
docView.setPeople(new ArrayList<>(docView.getPeople()));
docView.getPeople().add(newPerson);
update(docView);
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Aggregations