Search in sources :

Example 11 with UpdatablePersonView

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

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

Example 13 with UpdatablePersonView

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

the class EntityViewUpdateListenerMapsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    // When
    docView.setContacts(new HashMap<>(docView.getContacts()));
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    clearPersistenceContextAndReload();
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
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 14 with UpdatablePersonView

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

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

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