Search in sources :

Example 1 with UpdatableDocumentEntityWithMapsView

use of com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToCollectionAndModifyEntity.

@Test
public void testUpdateAddToCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = addToCollectionAndModifyEntity();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    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.creatable.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 2 with UpdatableDocumentEntityWithMapsView

use of com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = addToCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 3 with UpdatableDocumentEntityWithMapsView

use of com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateReplaceCollection.

@Test
public void testUpdateReplaceCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = replaceCollection();
    // Then
    // We only fetch the document and the collection in full mode
    // During dirty detection we can figure out that effectively nothing changed
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (isQueryStrategy()) {
            assertReplaceAnd(builder);
        } else {
            fullFetch(builder);
        }
        if (version || isQueryStrategy()) {
            versionUpdate(builder);
        }
    }
    builder.validate();
    // No need for an update since it isn't dirty
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 4 with UpdatableDocumentEntityWithMapsView

use of com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateSetCollectionToNull.

@Test
public void testUpdateSetCollectionToNull() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = setCollectionToNull();
    // Then
    // Assert that only the document is loaded
    // Since only an existing person was update, only a single update is generated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.delete(Document.class, "contacts").validate();
    // Since we don't need to merge elements, no need reload the collection
    assertNoUpdateAndReload(docView, true);
    assertNullMap(docView.getContacts());
    assertEquals(0, doc1.getContacts().size());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 5 with UpdatableDocumentEntityWithMapsView

use of com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = addToNewCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.insert(Document.class, "contacts").validate();
    // No need for an update since it isn't dirty
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Aggregations

AbstractEntityViewUpdateEntityMapsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)9 UpdatableDocumentEntityWithMapsView (com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView)9 Test (org.junit.Test)9 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)8 Document (com.blazebit.persistence.testsuite.entity.Document)5 Person (com.blazebit.persistence.testsuite.entity.Person)1