use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView 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.UpdatableDocumentWithMapsView 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.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method testUpdateAddToCollectionCreate.
@Test
public void testUpdateAddToCollectionCreate() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatablePersonView newPerson = evm.create(UpdatablePersonView.class);
// When
newPerson.setName("newPerson");
docView.setContacts(new HashMap<>(docView.getContacts()));
docView.getContacts().put(2, newPerson);
saveWith(docView, flusherBuilder -> {
flusherBuilder.onPrePersist(UpdatablePersonView.class, Person.class, (view, entity) -> {
entity.setAge(10L);
});
});
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
assertEquals("newPerson", doc1.getContacts().get(2).getName());
assertEquals(10L, doc1.getContacts().get(2).getAge());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method testUpdateReplaceCollection.
@Test
public void testUpdateReplaceCollection() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
// When
docView.setContacts(new HashMap<>(docView.getContacts()));
update(docView);
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method testClearUpdateAddToCollectionAndModify.
@Test
public void testClearUpdateAddToCollectionAndModify() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
newPerson.setName("newPerson");
docView.getContacts().put(2, newPerson);
HashMap<Integer, UpdatablePersonView> copy = new HashMap<>(docView.getContacts());
docView.getContacts().clear();
docView.getContacts().putAll(copy);
update(docView);
// Then
clearPersistenceContextAndReload();
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
assertEquals("newPerson", p2.getName());
}
Aggregations