Search in sources :

Example 1 with UpdatableResponsiblePersonView

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

the class EntityViewUpdateNestedImmutableSubviewCollectionsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
    clearQueries();
    // When
    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).update(Person.class);
        }
    } 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 || isFullMode() && isQueryStrategy()) {
        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.immutable.model.UpdatableDocumentWithCollectionsView) 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) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 2 with UpdatableResponsiblePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView 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 3 with UpdatableResponsiblePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView 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 4 with UpdatableResponsiblePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView 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 5 with UpdatableResponsiblePersonView

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

Aggregations

Person (com.blazebit.persistence.testsuite.entity.Person)10 UpdatableResponsiblePersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableResponsiblePersonView)10 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)8 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)8 Test (org.junit.Test)8 Document (com.blazebit.persistence.testsuite.entity.Document)6 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithCollectionsView)4 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1