Search in sources :

Example 1 with AssertStatementBuilder

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

the class EntityViewUpdateCreatableEntityCollectionsTest 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
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.assertInsert().forRelation(Document.class, "people").validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.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 2 with AssertStatementBuilder

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

the class EntityViewUpdateCreatableEntityCollectionsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given & When
    final UpdatableDocumentEntityWithCollectionsView docView = addToNewCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.delete(Document.class, "people").insert(Document.class, "people");
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.assertInsert().forRelation(Document.class, "people").validate();
    // No need for an update since it isn't dirty
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getPeople(), docView.getPeople());
}
Also used : UpdatableDocumentEntityWithCollectionsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.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 3 with AssertStatementBuilder

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

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToCollectionAndModifyEntity.

@Test
public void testUpdateAddToCollectionAndModifyEntity() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = addToCollectionAndModifyEntity();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getContacts(), docView.getContacts());
    assertEquals("pers2", p2.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 4 with AssertStatementBuilder

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

the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given & When
    final UpdatableDocumentEntityWithMapsView docView = addToCollection();
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // The added person is not loaded, only a single relation insert is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        versionUpdate(builder);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertEquals(doc1.getContacts(), docView.getContacts());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatableDocumentEntityWithMapsView(com.blazebit.persistence.view.testsuite.update.entity.creatable.model.UpdatableDocumentEntityWithMapsView) Document(com.blazebit.persistence.testsuite.entity.Document) Test(org.junit.Test) AbstractEntityViewUpdateEntityMapsTest(com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)

Example 5 with AssertStatementBuilder

use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder 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)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