Search in sources :

Example 1 with FriendPersonView

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

the class EntityViewUpdateNestedImmutableSubviewCollectionsTest method testUpdateModifyCollectionElement.

@Test
public void testUpdateModifyCollectionElement() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    FriendPersonView newFriend = getPersonView(p4.getId(), FriendPersonView.class);
    clearQueries();
    // When
    docView.getPeople().get(0).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();
    assertNoCollectionUpdateAndReload(docView);
    assertEquals(p4.getId(), p1.getFriend().getId());
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) FriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 2 with FriendPersonView

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

the class EntityViewUpdateNestedImmutableSubviewCollectionsTest method testUpdateModifyCollectionElementCopy.

@Test
public void testUpdateModifyCollectionElementCopy() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    FriendPersonView newFriend = getPersonView(p3.getId(), FriendPersonView.class);
    clearQueries();
    // When
    newFriend.setName("newFriend");
    docView.getPeople().get(0).setFriend(newFriend);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder).update(Person.class);
            versionUpdate(builder);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
            if (version) {
                versionUpdate(builder);
            }
        }
    }
    builder.validate();
    assertNoCollectionUpdateAndReload(docView);
    assertEquals(p3.getId(), p1.getFriend().getId());
    assertEquals("pers3", p3.getName());
    docView.getPeople().get(0).getFriend().setName("pers3");
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) FriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 3 with FriendPersonView

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

the class EntityViewUpdateNestedImmutableSubviewTest method testUpdateWithModifySubview.

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

Example 4 with FriendPersonView

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

the class EntityViewUpdateNestedImmutableSubviewTest method testUpdateWithSubview.

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

Example 5 with FriendPersonView

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

the class EntityViewUpdateNestedImmutableSubviewCollectionsTest method testUpdateModifyCollectionElementAndModify.

@Test
public void testUpdateModifyCollectionElementAndModify() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    FriendPersonView newFriend = getPersonView(p4.getId(), FriendPersonView.class);
    clearQueries();
    // When
    newFriend.setName("newFriend");
    docView.getPeople().get(0).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();
    assertNoCollectionUpdateAndReload(docView);
    assertEquals(p4.getId(), p1.getFriend().getId());
    assertEquals("pers4", p4.getName());
    docView.getPeople().get(0).getFriend().setName("pers4");
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) FriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView) 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 FriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView)8 Test (org.junit.Test)8 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithCollectionsView)3 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView)3 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentView)2