use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView 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.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
// Given
final UpdatableDocumentView docView = getDoc1View();
// When
docView.setName("newDoc");
update(docView);
// Then
clearPersistenceContextAndReload();
assertEquals("newDocUpdated", docView.getName());
assertEquals(POST_UPDATE_DATE, docView.getLastModified());
assertEquals(doc1.getName(), docView.getName());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateListenerTest method testUpdateWithModifyExisting.
@Test
public void testUpdateWithModifyExisting() {
// Given
final UpdatableDocumentView docView = getDoc1View();
// When
docView.getOwner().setName("newPerson");
update(docView);
// Then
clearPersistenceContextAndReload();
assertEquals("doc1Updated", docView.getName());
assertEquals(POST_UPDATE_DATE, docView.getLastModified());
assertEquals(doc1.getName(), docView.getName());
assertEquals("newPerson", doc1.getOwner().getName());
}
use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView 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.UpdatableDocumentView 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