use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView 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.UpdatablePersonView 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());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerMapsTest method testUpdateAddToNewCollection.
@Test
public void testUpdateAddToNewCollection() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
// When
docView.setContacts(new HashMap<>(docView.getContacts()));
docView.getContacts().put(2, newPerson);
update(docView);
// 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 EntityViewUpdateListenerTest method testUpdateWithSubview.
@Test
public void testUpdateWithSubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
// When
docView.setOwner(newOwner);
update(docView);
// Then
clearPersistenceContextAndReload();
assertEquals("doc1Updated", docView.getName());
assertEquals(POST_UPDATE_DATE, docView.getLastModified());
assertEquals(doc1.getName(), docView.getName());
assertEquals(p2.getId(), doc1.getOwner().getId());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerTest method testUpdateWithModifySubview.
@Test
public void testUpdateWithModifySubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
// When
newOwner.setName("newPerson");
docView.setOwner(newOwner);
saveWith(docView, flusherBuilder -> {
flusherBuilder.onPreUpdate(UpdatablePersonView.class, view -> {
view.setName(view.getName() + "Updated");
});
});
// Then
clearPersistenceContextAndReload();
assertEquals("doc1Updated", docView.getName());
assertEquals(POST_UPDATE_DATE, docView.getLastModified());
assertEquals(p2.getId(), doc1.getOwner().getId());
assertEquals("newPersonUpdated", doc1.getOwner().getName());
}
Aggregations