Search in sources :

Example 16 with AssertStatementBuilder

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

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToCollectionAndModifyEntity.

@Test
public void testUpdateAddToCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToCollectionAndModifyEntity();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // In addition, the new person is loaded because of the merge invocation
    // Finally a single relation insert is done and an update to the person is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder).select(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.update(Person.class).insert(Document.class, "people").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);
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    assertEquals(doc1.getPeople(), docView.getPeople());
    assertEquals("newPerson", p2.getName());
}
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 17 with AssertStatementBuilder

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

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateSetCollectionToNull.

@Test
public void testUpdateSetCollectionToNull() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView 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()) {
        if (version || isFullMode()) {
            builder.update(Document.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
        if (version) {
            builder.update(Document.class);
        }
    }
    builder.delete(Document.class, "people").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, "people");
        } else {
            fullFetch(afterBuilder);
        }
        if (version || isQueryStrategy()) {
            afterBuilder.update(Document.class);
        }
    }
    afterBuilder.validate();
    assertNullCollection(docView.getPeople());
    assertEquals(0, doc1.getPeople().size());
}
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 18 with AssertStatementBuilder

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

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddNewEntityToCollection.

@Test
public void testUpdateAddNewEntityToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addNewEntityToCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // In addition, the new person is loaded because of the merge invocation
    // Finally the person is persisted and a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder);
    }
    builder.insert(Person.class);
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "people").validate();
    // Unfortunately, even after an update, we have to reload the entity to merge again
    // This time we even have to re-load owned associations because they aren't lazy and could be dirty
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isQueryStrategy()) {
        afterBuilder.select(Person.class);
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    afterBuilder.assertSelect().fetching(Person.class, "favoriteDocuments").fetching(Document.class).and().assertSelect().fetching(Person.class, "localized").and().select(Document.class);
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    if (doesJpaMergeOfRecentlyPersistedEntityForceUpdate()) {
        afterBuilder.update(Person.class);
    }
    afterBuilder.validate();
    assertEquals(doc1.getPeople(), docView.getPeople());
    Iterator<Person> iter = doc1.getPeople().iterator();
    Person nextPerson = iter.next();
    if (nextPerson.getId().equals(p1.getId())) {
        assertEquals("pers1", nextPerson.getName());
        assertEquals("newPerson", iter.next().getName());
    } else {
        assertEquals("newPerson", nextPerson.getName());
        assertEquals("pers1", iter.next().getName());
    }
}
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) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateEntityCollectionsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)

Example 19 with AssertStatementBuilder

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

the class EntityViewUpdateMutableEntityCollectionsTest 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
    // In addition, the new person is loaded because of the merge invocation, but only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder).select(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "people").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);
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    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 20 with AssertStatementBuilder

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

the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToNewCollectionAndModifyEntity.

@Test
public void testUpdateAddToNewCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToNewCollectionAndModifyEntity();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // In addition, the new person is loaded because of the merge invocation
    // Finally a single relation insert is done and an update to the person is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
        builder.select(Person.class);
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder).select(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.update(Person.class).insert(Document.class, "people").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);
        afterBuilder.select(Person.class);
        if (isFullMode()) {
            afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        afterBuilder.update(Document.class);
    }
    afterBuilder.validate();
    assertEquals(doc1.getPeople(), docView.getPeople());
    assertEquals("newPerson", p2.getName());
}
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)

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