Search in sources :

Example 11 with AssertStatementBuilder

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

the class EntityViewUpdateNestedMutableFlatViewMapsTest method testUpdateCollectionElement.

@Test
public void testUpdateCollectionElement() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    clearQueries();
    // When
    docView.getNameContainerMap().get("doc1").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();
    fullFetch(builder);
    if (version) {
        builder.update(Document.class);
    }
    if (supportsIndexedInplaceUpdate() && (!isQueryStrategy() || isQueryStrategy() && !isFullMode())) {
        builder.update(Document.class, "nameContainerMap");
    } else {
        builder.delete(Document.class, "nameContainerMap").insert(Document.class, "nameContainerMap");
    }
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNameContainerMap().get("doc1").getNameObject().getPrimaryName());
    assertSubviewEquals(doc1.getNameContainerMap(), docView.getNameContainerMap());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.flatview.nested.mutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 12 with AssertStatementBuilder

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

the class EntityViewUpdateNestedMutableFlatViewTest method testUpdateWithSubview.

@Test
public void testUpdateWithSubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.getNameContainer().getNameObject().setPrimaryName("newPers");
    update(docView);
    // Then
    // Since the owner's name changed we, have to load the document and the owner
    // We apply the change which results in an update
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    Assert.assertEquals("newPers", docView.getNameContainer().getNameObject().getPrimaryName());
    Assert.assertEquals(doc1.getNameContainer().getNameObject().getPrimaryName(), docView.getNameContainer().getNameObject().getPrimaryName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.flatview.nested.mutable.model.UpdatableDocumentView) 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)

Example 13 with AssertStatementBuilder

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

the class EntityViewUpdateSimpleMutableSubtypeFlatViewMapsTest method testUpdateCollectionElement.

@Test
public void testUpdateCollectionElement() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    clearQueries();
    // When
    UpdatableNameObjectView updatableNameObjectView = evm.convert(docView.getNameMap().get("doc1"), UpdatableNameObjectView.class);
    updatableNameObjectView.setPrimaryName("newPers");
    docView.getNameMap().put("doc1", updatableNameObjectView);
    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()) {
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    if (supportsIndexedInplaceUpdate() && !isQueryStrategy() || isQueryStrategy() && !isFullMode()) {
        builder.assertUpdate().forRelation(Document.class, "nameMap").and();
    } else {
        builder.delete(Document.class, "nameMap").insert(Document.class, "nameMap");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNameMap().get("doc1").getPrimaryName());
    assertSubviewEquals(doc1.getNameMap(), docView.getNameMap());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.UpdatableNameObjectView) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 14 with AssertStatementBuilder

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

the class EntityViewUpdateSimpleMutableSubtypeFlatViewTest method testSimpleUpdate.

@Test
public void testSimpleUpdate() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    UpdatableNameObjectView updatableNameObjectView = evm.convert(docView.getNameObject(), UpdatableNameObjectView.class);
    updatableNameObjectView.setPrimaryName("newDoc");
    docView.setNameObject(updatableNameObjectView);
    update(docView);
    // Then
    // Since the only the documents primaryName changed we only need to load the document
    // In full mode, the person also has to be loaded
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    Assert.assertEquals("newDoc", docView.getNameObject().getPrimaryName());
    Assert.assertEquals(doc1.getNameObject().getPrimaryName(), docView.getNameObject().getPrimaryName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.UpdatableNameObjectView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 15 with AssertStatementBuilder

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

the class EntityViewUpdateSimpleMutableSubtypeFlatViewTest method testUpdateWithSubview.

@Test
public void testUpdateWithSubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    UpdatableNameObjectView updatableNameObjectView = evm.convert(docView.getNameObject(), UpdatableNameObjectView.class);
    updatableNameObjectView.setPrimaryName("newPers");
    docView.setNameObject(updatableNameObjectView);
    update(docView);
    // Then
    // Since the owner's name changed we, have to load the document and the owner
    // We apply the change which results in an update
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    Assert.assertEquals("newPers", docView.getNameObject().getPrimaryName());
    Assert.assertEquals(doc1.getNameObject().getPrimaryName(), docView.getNameObject().getPrimaryName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.UpdatableDocumentView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.UpdatableNameObjectView) 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