Search in sources :

Example 1 with UpdatableDocumentView

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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 2 with UpdatableDocumentView

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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 3 with UpdatableDocumentView

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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 4 with UpdatableDocumentView

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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 5 with UpdatableDocumentView

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());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Aggregations

AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)5 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView)5 Test (org.junit.Test)5 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView)3