Search in sources :

Example 1 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateListenerMapsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    // When
    docView.getContacts().put(2, newPerson);
    saveWith(docView, flushOperationBuilder -> {
        flushOperationBuilder.onPreUpdate(UpdatableDocumentWithMapsView.class, view -> {
            MapChangeModel<UpdatableDocumentWithMapsView, UpdatablePersonView> changeModel = (MapChangeModel<UpdatableDocumentWithMapsView, UpdatablePersonView>) (ChangeModel<?>) evm.getChangeModel(view).get("contacts");
            assertEquals(newPerson, changeModel.getAddedElements().get(0).getCurrentState());
        });
    });
    // Then
    clearPersistenceContextAndReload();
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : MapChangeModel(com.blazebit.persistence.view.change.MapChangeModel) 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 2 with UpdatableDocumentWithMapsView

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

use of com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView 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());
}
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 4 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateListenerMapsTest method testUpdateReplaceCollection.

@Test
public void testUpdateReplaceCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    // When
    docView.setContacts(new HashMap<>(docView.getContacts()));
    update(docView);
    // Then
    clearPersistenceContextAndReload();
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 5 with UpdatableDocumentWithMapsView

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

Aggregations

AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)6 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithMapsView)6 Test (org.junit.Test)6 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView)5 MapChangeModel (com.blazebit.persistence.view.change.MapChangeModel)1 HashMap (java.util.HashMap)1