Search in sources :

Example 1 with UpdatableFriendPersonView

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

the class EntityViewUpdateNestedMutableSubviewMapsTest method testUpdateModifyCollectionElement.

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

Example 2 with UpdatableFriendPersonView

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

the class EntityViewUpdateNestedMutableSubviewMapsTest method testUpdateModifyCollectionElementAndModify.

@Test
public void testUpdateModifyCollectionElementAndModify() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatableFriendPersonView newFriend = getPersonView(p4.getId(), UpdatableFriendPersonView.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);
        builder.update(Person.class);
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.assertSelect().fetching(Document.class).fetching(Document.class, "contacts").fetching(Person.class).and();
        }
        builder.assertSelect().fetching(Person.class).and();
        builder.update(Person.class);
        builder.update(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
    assertEquals(p4.getId(), p1.getFriend().getId());
    assertEquals("newFriend", p4.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithMapsView) UpdatableFriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 3 with UpdatableFriendPersonView

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

the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateModifyCollectionElementAndModify.

@Test
public void testUpdateModifyCollectionElementAndModify() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatableFriendPersonView newFriend = getPersonView(p4.getId(), UpdatableFriendPersonView.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).update(Person.class);
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.assertSelect().fetching(Document.class).fetching(Document.class, "people").fetching(Person.class).and();
        }
        builder.select(Person.class);
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class).update(Person.class);
    }
    builder.validate();
    assertNoCollectionUpdateFullAndReload(docView);
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
    assertEquals(p4.getId(), p1.getFriend().getId());
    assertEquals("newFriend", p4.getName());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) UpdatableFriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 4 with UpdatableFriendPersonView

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

the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateModifyCollectionElement.

@Test
public void testUpdateModifyCollectionElement() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatableFriendPersonView newFriend = getPersonView(p4.getId(), UpdatableFriendPersonView.class);
    clearQueries();
    // When
    docView.getPeople().get(0).setFriend(newFriend);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder).update(Person.class);
        }
        builder.update(Person.class);
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder).select(Person.class);
        } else {
            builder.assertSelect().fetching(Document.class).fetching(Document.class, "people").fetching(Person.class).and();
        }
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class);
    }
    builder.validate();
    assertNoCollectionUpdateFullAndReload(docView);
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
    assertEquals(p4.getId(), p1.getFriend().getId());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) UpdatableFriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 5 with UpdatableFriendPersonView

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

the class EntityViewUpdateNestedMutableSubviewMapsTest method testUpdateModifyCollectionElementCopy.

@Test
public void testUpdateModifyCollectionElementCopy() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatableFriendPersonView newFriend = getPersonView(p3.getId(), UpdatableFriendPersonView.class);
    clearQueries();
    // When
    newFriend.setName("newFriend");
    docView.getContacts().get(1).setFriend(newFriend);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
            assertReplaceAnd(builder);
        }
        builder.update(Person.class);
    } else {
        fullFetch(builder);
        builder.update(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(p3.getId(), p1.getFriend().getId());
    assertEquals("newFriend", p3.getName());
    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.mutable.model.UpdatableDocumentWithMapsView) UpdatableFriendPersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView) 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 UpdatableFriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView)8 Test (org.junit.Test)8 Person (com.blazebit.persistence.testsuite.entity.Person)6 Document (com.blazebit.persistence.testsuite.entity.Document)4 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView)3 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithMapsView)3 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentView)2