Search in sources :

Example 6 with AssertStatementBuilder

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

the class EntityViewUpdateMutableOnlyEntityTest method testSimpleUpdate.

@Test
public void testSimpleUpdate() {
    // Given & When
    final UpdatableDocumentEntityView docView = simpleUpdate();
    // Then
    // Assert that not only the document is loaded, but also always the responsiblePerson
    // This might be unexpected for partial strategies
    // but since we don't know if entities are dirty, we need to be conservative and load the object
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.assertSelect().fetching(Person.class).and();
    } else {
        fullFetch(builder);
    }
    builder.update(Document.class).validate();
    // Unfortunately, even after an update, we have to reload the entity to merge again
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isQueryStrategy()) {
        afterBuilder.assertSelect().fetching(Person.class).and();
        if (isFullMode()) {
            afterBuilder.update(Document.class);
        } else if (version) {
            versionUpdate(afterBuilder);
        }
    } else {
        afterBuilder.assertSelect().fetching(Document.class, Person.class).and();
        if (version) {
            afterBuilder.update(Document.class);
        }
    }
    afterBuilder.validate();
    assertEquals("newDoc", docView.getName());
    assertEquals(doc1.getName(), docView.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityView(com.blazebit.persistence.view.testsuite.update.entity.mutableonly.model.UpdatableDocumentEntityView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) AbstractEntityViewUpdateEntityTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityTest) Test(org.junit.Test)

Example 7 with AssertStatementBuilder

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

the class EntityViewUpdateMutableOnlyEntityTest method testUpdateWithModifyExisting.

@Test
public void testUpdateWithModifyExisting() {
    // Given & When
    final UpdatableDocumentEntityView docView = updateWithModifyExisting();
    // Then
    // Since we update the old responsiblePerson, load it along with the document for updating it later
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.assertSelect().fetching(Person.class).and();
        if (isFullMode()) {
            builder.update(Document.class);
        } else if (version) {
            versionUpdate(builder);
        }
    } else {
        fullFetch(builder);
        if (version) {
            versionUpdate(builder);
        }
    }
    builder.update(Person.class).validate();
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isQueryStrategy()) {
        afterBuilder.assertSelect().fetching(Person.class).and();
        if (isFullMode()) {
            afterBuilder.update(Document.class);
        } else if (version) {
            versionUpdate(afterBuilder);
        }
    } else {
        afterBuilder.assertSelect().fetching(Document.class, Person.class).and();
        if (version) {
            afterBuilder.update(Document.class);
        }
    }
    afterBuilder.validate();
    assertEquals(doc1.getResponsiblePerson().getId(), docView.getResponsiblePerson().getId());
    assertEquals("newOwner", doc1.getResponsiblePerson().getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityView(com.blazebit.persistence.view.testsuite.update.entity.mutableonly.model.UpdatableDocumentEntityView) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) AbstractEntityViewUpdateEntityTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityTest) Test(org.junit.Test)

Example 8 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityCollectionsTest 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 (isFullMode()) {
        if (isQueryStrategy()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        } else {
            fullFetch(builder);
        }
    } else if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    if (supportsNullCollectionElements()) {
        assertEquals(doc1.getPeople(), docView.getPeople());
    } else {
        assertEquals(doc1.getPeople().size() + 1, docView.getPeople().size());
    }
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.updatableonly.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 9 with AssertStatementBuilder

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

the class EntityViewUpdateUpdatableOnlyEntityCollectionsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Finally a single relation insert is done. In partial modes that don't do fetching, a collection recreation is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (isQueryStrategy()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        } else {
            fullFetch(builder);
        }
    } else if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.assertInsert().forRelation(Document.class, "people").and();
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.updatableonly.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 10 with AssertStatementBuilder

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

the class EntityViewUpdateNestedMutableFlatViewCollectionsTest method testUpdateCollectionElement.

@Test
public void testUpdateCollectionElement() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    clearQueries();
    // When
    docView.getNameContainers().get(0).getNameObject().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()) {
        builder.delete(Document.class, "nameContainers").insert(Document.class, "nameContainers");
    } else {
        builder.update(Document.class, "nameContainers");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNameContainers().get(0).getNameObject().getPrimaryName());
    assertSubviewEquals(doc1.getNameContainers(), docView.getNameContainers());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.flatview.nested.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)

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