Search in sources :

Example 1 with UpdatableDocumentEntityWithMapsView

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

the class EntityViewUpdateMutableOnlyEntityMapsTest method testUpdateModifyEntityInCollection.

@Test
public void testUpdateModifyEntityInCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = modifyEntityInCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Since only an existing person was update, only a single update is generated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.select(Person.class);
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.update(Person.class).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);
    } else {
        fullFetch(afterBuilder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(afterBuilder);
    }
    afterBuilder.validate();
    assertEquals(doc1.getContacts(), docView.getContacts());
    assertEquals("newPerson", p1.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.mutableonly.model.UpdatableDocumentEntityWithMapsView) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Aggregations

AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)1 Person (com.blazebit.persistence.testsuite.entity.Person)1 AbstractEntityViewUpdateEntityMapsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)1 UpdatableDocumentEntityWithMapsView (com.blazebit.persistence.view.testsuite.update.entity.mutableonly.model.UpdatableDocumentEntityWithMapsView)1 Test (org.junit.Test)1