Search in sources :

Example 96 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleUpdatableOnlySubviewMapsTest method testUpdateAddToNewCollectionAndModifySubview.

@Test
public void testUpdateAddToNewCollectionAndModifySubview() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    PersonView newPerson = getP2View(PersonView.class);
    clearQueries();
    // When
    newPerson.setName("newPerson");
    docView.setContacts(new HashMap<>(docView.getContacts()));
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    // In partial mode, only the document is loaded. In full mode, the people are also loaded
    // Since we load the people in the full mode, we do a proper diff and can compute that only a single item was added
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            assertReplaceAnd(builder);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            if (preferLoadingAndDiffingOverRecreate()) {
                fullFetch(builder);
            } else {
                assertReplaceAnd(builder);
            }
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView);
    assertEquals(doc1.getContacts().size(), docView.getContacts().size());
    assertEquals("pers2", p2.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) PersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.updatableonly.model.PersonView) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.subview.simple.updatableonly.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 97 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableOnlySubviewTest method testSimpleUpdate.

@Test
public void testSimpleUpdate() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.setName("newDoc");
    update(docView);
    // Then
    // Since only the document changed we don't need to load the owner
    // Just assert the update is properly done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newDoc", docView.getName());
    assertEquals(doc1.getName(), docView.getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutableonly.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 98 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewMapsTest method testUpdateAddToNewCollectionAndModify.

@Test
public void testUpdateAddToNewCollectionAndModify() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    newPerson.setName("newPerson");
    docView.setContacts(new HashMap<>(docView.getContacts()));
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // In addition, the new person is loaded because it is dirty
    // Finally a single relation insert is done and an update to the person is done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
        }
        builder.update(Person.class);
    } else {
        fullFetch(builder);
        builder.select(Person.class);
        builder.update(Person.class);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
    assertEquals("newPerson", p2.getName());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 99 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testSimpleUpdate.

@Test
public void testSimpleUpdate() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.setName("newDoc");
    update(docView);
    // Then
    // Since only the document changed we don't need to load the owner
    // Just assert the update is properly done
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newDoc", docView.getName());
    assertEquals(doc1.getName(), docView.getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.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 100 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateToNull.

@Test
public void testUpdateToNull() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    clearQueries();
    // When
    docView.setResponsiblePerson(null);
    update(docView);
    // Then
    // Assert that only the document is loaded and finally also updated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
    if (isFullMode()) {
        if (isQueryStrategy()) {
            afterBuilder.update(Document.class);
        } else {
            fullFetch(afterBuilder);
        }
    }
    afterBuilder.validate();
    Assert.assertNull(doc1.getResponsiblePerson());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.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)

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