Search in sources :

Example 6 with UpdatablePersonView

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

Example 7 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView 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 8 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView 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 9 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView 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)

Example 10 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView in project blaze-persistence by Blazebit.

the class EntityViewUpdateListenerCollectionsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    // When
    docView.setPeople(new ArrayList<>(docView.getPeople()));
    docView.getPeople().add(newPerson);
    update(docView);
    // 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) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Aggregations

UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView)15 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)13 Test (org.junit.Test)13 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithCollectionsView)5 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView)5 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentView)3 Person (com.blazebit.persistence.testsuite.entity.Person)2 HashMap (java.util.HashMap)2 MapChangeModel (com.blazebit.persistence.view.change.MapChangeModel)1 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1