Search in sources :

Example 21 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddNullToCollection.

@Test
public void testUpdateAddNullToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addNullToCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Finally a single relation insert is done for the null element if supported
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    if (supportsNullCollectionElements()) {
        builder.insert(Document.class, "people");
    }
    builder.validate();
    // Unfortunately, even after an update, we have to reload the entity to merge again
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isQueryStrategy()) {
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    if (supportsNullCollectionElements()) {
        assertEquals(doc1.getPeople(), docView.getPeople());
    }
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Example 22 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableFlatViewCollectionsTest method testUpdateCollectionElement.

@Test
public void testUpdateCollectionElement() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    clearQueries();
    // When
    docView.getNames().get(0).setPrimaryName("newPers");
    update(docView);
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Finally the person is updated because the primary name changed
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    if (version || isFullMode() && isQueryStrategy()) {
        builder.update(Document.class);
    }
    if (isFullMode() || !isQueryStrategy() && !supportsIndexedInplaceUpdate()) {
        builder.delete(Document.class, "names").insert(Document.class, "names");
    } else {
        builder.update(Document.class, "names");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNames().get(0).getPrimaryName());
    assertSubviewEquals(doc1.getNames(), docView.getNames());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 23 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableFlatViewMapsTest method testUpdateCollectionElementClearAndReAdd.

@Test
public void testUpdateCollectionElementClearAndReAdd() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    clearQueries();
    // When
    Map<String, UpdatableNameObjectView> map = new HashMap<>(docView.getNameMap());
    docView.getNameMap().get("doc1").setPrimaryName("newPers");
    docView.getNameMap().clear();
    docView.getNameMap().putAll(map);
    update(docView);
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Finally the person is updated because the primary name changed
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    if (supportsIndexedInplaceUpdate() && !isQueryStrategy() || isQueryStrategy() && !isFullMode()) {
        builder.assertUpdate().forRelation(Document.class, "nameMap").and();
    } else {
        builder.delete(Document.class, "nameMap").insert(Document.class, "nameMap");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNameMap().get("doc1").getPrimaryName());
    assertSubviewEquals(doc1.getNameMap(), docView.getNameMap());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) HashMap(java.util.HashMap) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 24 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableFlatViewTest method testSimpleUpdate.

@Test
public void testSimpleUpdate() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.getNameObject().setPrimaryName("newDoc");
    update(docView);
    // Then
    // Since the only the documents primaryName changed we only need to load the document
    // In full mode, the person also has to be loaded
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    Assert.assertEquals("newDoc", docView.getNameObject().getPrimaryName());
    Assert.assertEquals(doc1.getNameObject().getPrimaryName(), docView.getNameObject().getPrimaryName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 25 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.

the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateAddToNewCollectionAndModifyEntity.

@Test
public void testUpdateAddToNewCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = addToNewCollectionAndModifyEntity();
    // Then
    // Assert that the document and the people are loaded in full mode i.e. a full fetch
    // When fetching like in full mode, we can do a proper diff and see that a single insert is enough
    // But partial strategies currently favor not fetching, but collection recreations instead
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
        }
    } else {
        if (preferLoadingAndDiffingOverRecreate()) {
            fullFetch(builder);
        } else {
            if (isFullMode()) {
                fullFetch(builder);
            } else {
                builder.select(Document.class).delete(Document.class, "contacts").insert(Document.class, "contacts");
            }
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.insert(Document.class, "contacts");
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(doc1.getContacts(), docView.getContacts());
    assertEquals("pers2", p2.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Aggregations

AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)330 Test (org.junit.Test)304 Document (com.blazebit.persistence.testsuite.entity.Document)193 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)180 Person (com.blazebit.persistence.testsuite.entity.Person)86 AbstractEntityViewUpdateEntityCollectionsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)26 AbstractEntityViewUpdateEntityMapsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)26 AbstractEntityViewUpdateEntityTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityTest)20 AbstractEntityViewOrphanRemoveDocumentTest (com.blazebit.persistence.view.testsuite.update.remove.orphan.AbstractEntityViewOrphanRemoveDocumentTest)12 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView)10 UpdatableDocumentEntityWithCollectionsView (com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView)9 UpdatableDocumentEntityWithMapsView (com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView)8 UpdatableDocumentEntityWithMapsView (com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView)8 FriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.FriendPersonView)8 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView)8 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView)8 UpdatableFriendPersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableFriendPersonView)8 UpdatableResponsiblePersonView (com.blazebit.persistence.view.testsuite.update.subview.nested.updatableonly.model.UpdatableResponsiblePersonView)8 NaturalIdJoinTableEntity (com.blazebit.persistence.testsuite.entity.NaturalIdJoinTableEntity)6 Version (com.blazebit.persistence.testsuite.entity.Version)6