use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithCollectionsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerCollectionsTest method testUpdateReplaceCollection.
@Test
public void testUpdateReplaceCollection() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
// When
docView.setPeople(new ArrayList<>(docView.getPeople()));
update(docView);
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithCollectionsView 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.UpdatableDocumentWithCollectionsView 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.UpdatableDocumentWithCollectionsView 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.UpdatableDocumentWithCollectionsView 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());
}
Aggregations