Search in sources :

Example 1 with UpdatableDocumentEmbeddableWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableCollectionsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given
    final UpdatableDocumentEmbeddableWithCollectionsView docView = updateAddToNewCollection();
    Long oldVersion = docView.getVersion();
    assertChangesUpdateAndFlush(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (!isQueryStrategy()) {
            fullFetch(builder);
        }
        if (version || isQueryStrategy()) {
            builder.update(Document.class);
        }
        if (!registerType || isQueryStrategy()) {
            assertReplaceAnd(builder);
        }
    } else {
        if (registerType && preferLoadingAndDiffingOverRecreate()) {
            if (!isQueryStrategy()) {
                fullFetch(builder);
            }
            if (version) {
                builder.update(Document.class);
            }
        } else {
            if (!isQueryStrategy()) {
                builder.select(Document.class);
            }
            if (version) {
                builder.update(Document.class);
            }
            assertReplaceAnd(builder);
        }
    }
    builder.assertInsert().forRelation(Document.class, "names").validate();
    assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            assertReplaceAnd(afterBuilder);
        } else {
            fullFetch(afterBuilder);
            if (!registerType) {
                assertReplaceAnd(afterBuilder);
            }
        }
        if (version && !registerType || isQueryStrategy()) {
            afterBuilder.update(Document.class);
        }
    } else {
        if (!registerType) {
            if (!isQueryStrategy()) {
                afterBuilder.select(Document.class);
            }
            if (version) {
                afterBuilder.update(Document.class);
            }
            assertReplaceAnd(afterBuilder);
        }
    }
    if (!registerType || isQueryStrategy() && isFullMode()) {
        afterBuilder.insert(Document.class, "names");
        assertVersionDiff(oldVersion, docView.getVersion(), 2, 2);
    } else {
        assertVersionDiff(oldVersion, docView.getVersion(), 1, isQueryStrategy() ? 2 : 1);
    }
    afterBuilder.validate();
    assertEquals(doc1.getNames(), docView.getNames());
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEmbeddableCollectionsTest(com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableCollectionsTest)

Example 2 with UpdatableDocumentEmbeddableWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableCollectionsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given
    final UpdatableDocumentEmbeddableWithCollectionsView docView = updateAddToCollection();
    Long oldVersion = docView.getVersion();
    assertChangesUpdateAndFlush(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (!isQueryStrategy()) {
            fullFetch(builder);
        }
        if (version || isQueryStrategy()) {
            builder.update(Document.class);
        }
        if (!registerType || isQueryStrategy()) {
            assertReplaceAnd(builder);
        }
    } else {
        if (registerType && preferLoadingAndDiffingOverRecreate()) {
            if (!isQueryStrategy()) {
                fullFetch(builder);
            }
            if (version) {
                builder.update(Document.class);
            }
        } else {
            if (!isQueryStrategy()) {
                builder.select(Document.class);
            }
            if (version) {
                builder.update(Document.class);
            }
            assertReplaceAnd(builder);
        }
    }
    builder.assertInsert().forRelation(Document.class, "names").validate();
    assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            assertReplaceAnd(afterBuilder);
        } else {
            fullFetch(afterBuilder);
            if (!registerType) {
                assertReplaceAnd(afterBuilder);
            }
        }
        if (version && !registerType || isQueryStrategy()) {
            afterBuilder.update(Document.class);
        }
    } else {
        if (!registerType) {
            if (!isQueryStrategy()) {
                afterBuilder.select(Document.class);
            }
            if (version) {
                afterBuilder.update(Document.class);
            }
            assertReplaceAnd(afterBuilder);
        }
    }
    if (!registerType || isQueryStrategy() && isFullMode()) {
        afterBuilder.insert(Document.class, "names");
        assertVersionDiff(oldVersion, docView.getVersion(), 2, 2);
    } else {
        assertVersionDiff(oldVersion, docView.getVersion(), 1, isQueryStrategy() ? 2 : 1);
    }
    afterBuilder.validate();
    assertEquals(doc1.getNames(), docView.getNames());
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEmbeddableCollectionsTest(com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableCollectionsTest)

Example 3 with UpdatableDocumentEmbeddableWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableCollectionsTest method testUpdateReplaceCollection.

@Test
public void testUpdateReplaceCollection() {
    // Given
    final UpdatableDocumentEmbeddableWithCollectionsView docView = updateReplaceCollection();
    Long oldVersion = docView.getVersion();
    assertMutableChangeModel(docView);
    update(docView);
    assertMutableChangeModel(docView);
    // Then
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (!isQueryStrategy()) {
            fullFetch(builder);
        }
        if (!registerType && version || isQueryStrategy()) {
            builder.update(Document.class);
        }
        if (!registerType || isQueryStrategy()) {
            assertReplaceAnd(builder);
        }
    } else {
        if (!registerType) {
            if (!isQueryStrategy()) {
                builder.select(Document.class);
            }
            if (version) {
                builder.update(Document.class);
            }
            assertReplaceAnd(builder);
        }
    }
    builder.validate();
    if (registerType) {
        assertVersionDiff(oldVersion, docView.getVersion(), 0, isQueryStrategy() ? 1 : 0);
    } else {
        assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
    }
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            assertReplaceAnd(afterBuilder);
        } else {
            fullFetch(afterBuilder);
            if (!registerType) {
                assertReplaceAnd(afterBuilder);
            }
        }
        if (version && !registerType || isQueryStrategy()) {
            afterBuilder.update(Document.class);
        }
    } else {
        if (!registerType) {
            if (!isQueryStrategy()) {
                afterBuilder.select(Document.class);
            }
            if (version) {
                afterBuilder.update(Document.class);
            }
            assertReplaceAnd(afterBuilder);
        }
    }
    afterBuilder.validate();
    if (registerType) {
        assertVersionDiff(oldVersion, docView.getVersion(), 0, isQueryStrategy() ? 2 : 0);
    } else {
        assertVersionDiff(oldVersion, docView.getVersion(), 2, 2);
    }
    assertEquals(doc1.getNames(), docView.getNames());
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Test(org.junit.Test) AbstractEntityViewUpdateEmbeddableCollectionsTest(com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableCollectionsTest)

Example 4 with UpdatableDocumentEmbeddableWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableCollectionsTest method assertChangesUpdateAndFlush.

protected void assertChangesUpdateAndFlush(UpdatableDocumentEmbeddableWithCollectionsView docView) {
    if (!isFullMode()) {
        SingularChangeModel<UpdatableDocumentEmbeddableWithCollectionsView> changeModel = evm.getChangeModel(docView);
        PluralChangeModel<?, ?> namesChange = (PluralChangeModel<?, ?>) changeModel.get("names");
        assertTrue(changeModel.isDirty());
        assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
        assertTrue(namesChange.isDirty());
        assertEquals(ChangeModel.ChangeKind.MUTATED, namesChange.getKind());
        if (registerType) {
            assertEquals(1, namesChange.getAddedElements().size());
            assertEquals(0, namesChange.getRemovedElements().size());
            assertEquals(0, namesChange.getMutatedElements().size());
            assertUnorderedEquals(Arrays.asList(namesChange.getAddedElements().get(0)), namesChange.getElementChanges());
        } else {
            assertEquals(2, namesChange.getAddedElements().size());
            assertEquals(1, namesChange.getRemovedElements().size());
            assertEquals(0, namesChange.getMutatedElements().size());
            assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(0).getKind());
            assertEquals(new NameObject("doc1", "doc1"), namesChange.getAddedElements().get(0).getCurrentState());
            assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(1).getKind());
            assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), namesChange.getAddedElements().get(1).getCurrentState());
            assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getRemovedElements().get(0).getKind());
            assertEquals(new NameObject("doc1", "doc1"), namesChange.getRemovedElements().get(0).getInitialState());
            assertUnorderedEquals(Arrays.asList(namesChange.getAddedElements().get(0), namesChange.getAddedElements().get(1), namesChange.getRemovedElements().get(0)), namesChange.getElementChanges());
        }
        assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(namesChange.getAddedElements().size() - 1).getKind());
        assertNull(namesChange.getAddedElements().get(namesChange.getAddedElements().size() - 1).getInitialState());
        assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), namesChange.getAddedElements().get(namesChange.getAddedElements().size() - 1).getCurrentState());
        assertEquals(Arrays.asList(namesChange), changeModel.getDirtyChanges());
    }
    update(docView);
    if (!isFullMode()) {
        SingularChangeModel<UpdatableDocumentEmbeddableWithCollectionsView> changeModel = evm.getChangeModel(docView);
        PluralChangeModel<?, ?> namesChange = (PluralChangeModel<?, ?>) changeModel.get("names");
        if (registerType) {
            assertFalse(changeModel.isDirty());
            assertEquals(ChangeModel.ChangeKind.NONE, changeModel.getKind());
            assertFalse(namesChange.isDirty());
            assertEquals(ChangeModel.ChangeKind.NONE, namesChange.getKind());
            assertEquals(0, namesChange.getAddedElements().size());
            assertEquals(0, namesChange.getRemovedElements().size());
            assertEquals(0, namesChange.getMutatedElements().size());
            assertEquals(0, namesChange.getElementChanges().size());
            assertEquals(0, changeModel.getDirtyChanges().size());
        } else {
            assertTrue(changeModel.isDirty());
            assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
            assertTrue(namesChange.isDirty());
            assertEquals(ChangeModel.ChangeKind.MUTATED, namesChange.getKind());
            assertEquals(2, namesChange.getAddedElements().size());
            assertEquals(2, namesChange.getRemovedElements().size());
            assertEquals(0, namesChange.getMutatedElements().size());
            assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(0).getKind());
            assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(1).getKind());
            assertUnorderedEquals(Arrays.asList(namesChange.getAddedElements().get(0), namesChange.getAddedElements().get(1), namesChange.getRemovedElements().get(0), namesChange.getRemovedElements().get(1)), namesChange.getElementChanges());
            assertEquals(new NameObject("doc1", "doc1"), namesChange.getAddedElements().get(0).getCurrentState());
            assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), namesChange.getAddedElements().get(1).getCurrentState());
            assertEquals(new NameObject("doc1", "doc1"), namesChange.getRemovedElements().get(0).getInitialState());
            assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), namesChange.getRemovedElements().get(1).getInitialState());
            assertEquals(Arrays.asList(namesChange), changeModel.getDirtyChanges());
        }
    }
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) PluralChangeModel(com.blazebit.persistence.view.change.PluralChangeModel)

Example 5 with UpdatableDocumentEmbeddableWithCollectionsView

use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateMutableEmbeddableCollectionsTest method testUpdateRemoveNonExisting.

@Test
public void testUpdateRemoveNonExisting() {
    // Given
    final UpdatableDocumentEmbeddableWithCollectionsView docView = updateRemoveNonExisting();
    // When
    update(docView);
    // Then
    clearPersistenceContextAndReload();
    assertEquals(doc1.getNames(), docView.getNames());
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) Test(org.junit.Test) AbstractEntityViewUpdateEmbeddableCollectionsTest(com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableCollectionsTest)

Aggregations

UpdatableDocumentEmbeddableWithCollectionsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView)6 AbstractEntityViewUpdateEmbeddableCollectionsTest (com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableCollectionsTest)4 Test (org.junit.Test)4 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)3 Document (com.blazebit.persistence.testsuite.entity.Document)2 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)2 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)2