Search in sources :

Example 1 with UpdatableDocumentWithCollectionsView

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

Example 2 with UpdatableDocumentWithCollectionsView

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

Example 3 with UpdatableDocumentWithCollectionsView

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

Example 4 with UpdatableDocumentWithCollectionsView

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

Example 5 with UpdatableDocumentWithCollectionsView

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

Aggregations

AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)6 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithCollectionsView)6 Test (org.junit.Test)6 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView)5 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)1 ArrayList (java.util.ArrayList)1