Search in sources :

Example 6 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateModifyCollectionElementSetToNull.

@Test
public void testUpdateModifyCollectionElementSetToNull() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    clearQueries();
    // When
    docView.getContacts().get(1).setFriend(null);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
        builder.update(Person.class);
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        fullFetch(builder);
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView, true);
    assertNull(p1.getFriend());
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 7 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateModifyCollectionElementAndModify.

@Test
public void testUpdateModifyCollectionElementAndModify() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    FriendPersonView newFriend = getPersonView(p4.getId(), FriendPersonView.class);
    clearQueries();
    // When
    newFriend.setName("newFriend");
    docView.getContacts().get(1).setFriend(newFriend);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
        builder.update(Person.class);
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        fullFetch(builder);
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(p4.getId(), p1.getFriend().getId());
    assertEquals("pers4", p4.getName());
    docView.getContacts().get(1).getFriend().setName("pers4");
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) FriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 8 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateModifyCollectionElement.

@Test
public void testUpdateModifyCollectionElement() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    FriendPersonView newFriend = getPersonView(p4.getId(), FriendPersonView.class);
    clearQueries();
    // When
    docView.getContacts().get(1).setFriend(newFriend);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
        builder.update(Person.class);
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        fullFetch(builder);
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(p4.getId(), p1.getFriend().getId());
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) FriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Aggregations

AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)8 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)8 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView)8 Test (org.junit.Test)8 Document (com.blazebit.persistence.testsuite.entity.Document)4 Person (com.blazebit.persistence.testsuite.entity.Person)4 UpdatableResponsiblePersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView)4 FriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView)3