Search in sources :

Example 1 with UpdatableDocumentWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView 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 2 with UpdatableDocumentWithCollectionsView

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

the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateAddToNewCollectionAndModify.

@Test
public void testUpdateAddToNewCollectionAndModify() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    newPerson.getFriend().setName("newPerson");
    docView.setPeople(new ArrayList<>(docView.getPeople()));
    docView.getPeople().add(newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
            builder.update(Person.class);
            builder.update(Person.class);
            builder.update(Person.class);
        }
        builder.update(Person.class);
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        fullFetch(builder).assertSelect().fetching(Person.class).fetching(Person.class).and();
        if (version) {
            builder.update(Document.class);
        }
        builder.update(Person.class);
    }
    builder.assertInsert().forRelation(Document.class, "people").and().validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
    assertEquals("newPerson", 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) UpdatableResponsiblePersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableResponsiblePersonView) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 3 with UpdatableDocumentWithCollectionsView

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

the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    docView.getPeople().add(newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (isQueryStrategy()) {
            fullUpdate(builder);
        } else {
            fullFetch(builder).select(Person.class);
            if (version) {
                builder.update(Document.class);
            }
        }
    } else {
        if (!isQueryStrategy()) {
            builder.assertSelect().fetching(Document.class).fetching(Document.class, "people").fetching(Person.class).and();
        }
        if (version) {
            builder.update(Document.class);
        }
    }
    builder.assertInsert().forRelation(Document.class, "people").validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableResponsiblePersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableResponsiblePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 4 with UpdatableDocumentWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView 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 UpdatableDocumentWithCollectionsView

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

the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateModifyCollectionElementCopy.

@Test
public void testUpdateModifyCollectionElementCopy() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatableFriendPersonView newFriend = getPersonView(p3.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);
        }
        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();
    assertNoCollectionUpdateFullAndReload(docView);
    assertEquals(p3.getId(), p1.getFriend().getId());
    assertEquals("newFriend", p3.getName());
    assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) 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 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView)8 Test (org.junit.Test)8 Person (com.blazebit.persistence.testsuite.entity.Person)7 Document (com.blazebit.persistence.testsuite.entity.Document)5 UpdatableResponsiblePersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableResponsiblePersonView)4 UpdatableFriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView)3