Search in sources :

Example 16 with Document

use of com.blazebit.persistence.testsuite.entity.Document 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 17 with Document

use of com.blazebit.persistence.testsuite.entity.Document 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 18 with Document

use of com.blazebit.persistence.testsuite.entity.Document 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 19 with Document

use of com.blazebit.persistence.testsuite.entity.Document 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 20 with Document

use of com.blazebit.persistence.testsuite.entity.Document 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)

Aggregations

Document (com.blazebit.persistence.testsuite.entity.Document)283 Test (org.junit.Test)206 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)114 Person (com.blazebit.persistence.testsuite.entity.Person)99 EntityManager (javax.persistence.EntityManager)70 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)69 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)54 Category (org.junit.experimental.categories.Category)44 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)43 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)31 AbstractEntityViewUpdateEntityCollectionsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)24 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)21 AbstractEntityViewUpdateEntityMapsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)21 Version (com.blazebit.persistence.testsuite.entity.Version)20 PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)16 AbstractCoreTest (com.blazebit.persistence.testsuite.AbstractCoreTest)16 Before (org.junit.Before)16 Tuple (javax.persistence.Tuple)14 QDocument (com.blazebit.persistence.testsuite.entity.QDocument)11 UpdatableDocumentEntityWithCollectionsView (com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView)9