Search in sources :

Example 26 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityMapsTest 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 the collection is empty we don't have to care for collection element changes
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            afterBuilder.delete(Document.class, "contacts");
            versionUpdate(afterBuilder);
        } else {
            fullFetch(afterBuilder);
        }
    }
    afterBuilder.validate();
    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.updatableonly.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 27 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateReplaceCollection.

@Test
public void testUpdateReplaceCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = replaceCollection();
    // Then
    // Since entities are not mutable we can detect nothing changed
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (isQueryStrategy()) {
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
            versionUpdate(builder);
        } else {
            fullFetch(builder);
        }
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(doc1.getContacts(), docView.getContacts());
}
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)

Example 28 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateAddNullToCollection.

@Test
public void testUpdateAddNullToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView 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()) {
        if (isFullMode()) {
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    if (supportsNullCollectionElements()) {
        builder.insert(Document.class, "contacts");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    if (supportsNullCollectionElements()) {
        assertEquals(doc1.getContacts(), docView.getContacts());
    } else {
        assertEquals(doc1.getContacts().size() + 1, docView.getContacts().size());
    }
}
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)

Example 29 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateModifyEntityInCollection.

@Test
public void testUpdateModifyEntityInCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = modifyEntityInCollection();
    // Then
    // Assert that the document and the people are loaded in full mode i.e. a full fetch
    // Since no collection was changed, no insters or updates are done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (isQueryStrategy()) {
            if (isFullMode()) {
                builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
                versionUpdate(builder);
            }
        } else {
            fullFetch(builder);
        }
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("pers1", p1.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)

Example 30 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityTest method testUpdateToNewPerson.

@Test
public void testUpdateToNewPerson() {
    try {
        // Given & When
        final UpdatableDocumentEntityView docView = updateToNewPerson(true);
        fail("Expected a transient reference error for the new person!");
    } catch (PersistenceException | IllegalStateException ex) {
        // Then
        assertEquals(1L, updateCommitCount.get());
        assertTrue(ex.getMessage().contains("transient"));
        AssertStatementBuilder builder = assertUnorderedQuerySequence();
        if (!isQueryStrategy()) {
            if (isFullMode()) {
                fullFetch(builder);
            } else {
                builder.select(Document.class);
            }
        }
        // We need to load the rollback view
        builder.select(Document.class);
        builder.validate();
        clearPersistenceContextAndReload();
        assertEquals(p1.getId(), doc1.getResponsiblePerson().getId());
    }
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) PersistenceException(javax.persistence.PersistenceException) UpdatableDocumentEntityView(com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityView) Document(com.blazebit.persistence.testsuite.entity.Document) AbstractEntityViewUpdateEntityTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityTest) Test(org.junit.Test)

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