Search in sources :

Example 1 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 testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    docView.setContacts(new HashMap<>(docView.getContacts()));
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class).update(Person.class);
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
        if (isFullMode()) {
            // In full mode we need to select the added element for cascading the update
            builder.select(Person.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableResponsiblePersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) 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 2 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 testUpdateAddToNewCollectionAndModify.

@Test
public void testUpdateAddToNewCollectionAndModify() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    newPerson.getFriend().setName("newPerson");
    docView.setContacts(new HashMap<>(docView.getContacts()));
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class).update(Person.class);
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
        if (isFullMode()) {
            // In full mode we need to select the added element for cascading the update
            builder.select(Person.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals("pers4", p4.getName());
    docView.getContacts().get(2).getFriend().setName("pers4");
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableResponsiblePersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) 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 3 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 testUpdateAddToCollectionAndModify.

@Test
public void testUpdateAddToCollectionAndModify() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    newPerson.getFriend().setName("newPerson");
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class).update(Person.class);
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
        if (isFullMode()) {
            // In full mode we need to select the added element for cascading the update
            builder.select(Person.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals("pers4", p4.getName());
    docView.getContacts().get(2).getFriend().setName("pers4");
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableResponsiblePersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) 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 4 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 testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class).update(Person.class);
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
        if (isFullMode()) {
            // In full mode we need to select the added element for cascading the update
            builder.select(Person.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableResponsiblePersonView(com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) 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 5 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 testUpdateModifyCollectionElementCopy.

@Test
public void testUpdateModifyCollectionElementCopy() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    FriendPersonView newFriend = getPersonView(p3.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);
            versionUpdate(builder);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
            if (version) {
                versionUpdate(builder);
            }
        }
    }
    builder.validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(p3.getId(), p1.getFriend().getId());
    assertEquals("pers3", p3.getName());
    docView.getContacts().get(1).getFriend().setName("pers3");
    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