Search in sources :

Example 11 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewMapsTest method testUpdateAddToCollection.

@Test
public void testUpdateAddToCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    docView.getContacts().put(2, newPerson);
    update(docView);
    // Then
    // Assert that the document and the people are loaded, but only a relation insert is done
    // The full mode also has to load the person that is added and apply the changes
    // But since nothing is changed, no update is subsequently generated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class).update(Person.class);
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
        }
    } else {
        fullFetch(builder);
        if (isFullMode()) {
            builder.select(Person.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
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) Person(com.blazebit.persistence.testsuite.entity.Person) 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 12 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewMapsTest method testUpdateAddToNewCollection.

@Test
public void testUpdateAddToNewCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    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
    // The full mode also has to load the person that is added and apply the changes
    // But since nothing is changed, no update is subsequently generated
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class).update(Person.class);
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
        }
    } else {
        fullFetch(builder);
        if (isFullMode()) {
            builder.select(Person.class);
        }
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    builder.insert(Document.class, "contacts").validate();
    assertNoUpdateAndReload(docView, true);
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
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) Person(com.blazebit.persistence.testsuite.entity.Person) 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 13 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewMapsTest method testUpdateAddToCollectionAndModify.

@Test
public void testUpdateAddToCollectionAndModify() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    newPerson.setName("newPerson");
    docView.getContacts().put(2, newPerson);
    verifyUpdateAddToCollectionAndModify(docView);
}
Also used : UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView) 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 14 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithModifySubview.

@Test
public void testUpdateWithModifySubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    newOwner.setName("newPerson");
    docView.setResponsiblePerson(newOwner);
    update(docView);
    // Then
    // Since the owner changed we don't need to load the old owner
    // Now the new owner has to be loaded as it is updated as well
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
        builder.update(Person.class).update(Document.class);
    } else {
        if (isFullMode()) {
            fullFetch(builder);
        } else {
            builder.select(Document.class);
        }
        builder.select(Person.class).update(Document.class).update(Person.class);
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals(p2.getId(), doc1.getResponsiblePerson().getId());
    assertEquals("newPerson", doc1.getResponsiblePerson().getName());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) 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) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 15 with UpdatablePersonView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithSubview.

@Test
public void testUpdateWithSubview() {
    // Given
    final UpdatableDocumentView docView = getDoc1View();
    UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    docView.setResponsiblePerson(newOwner);
    update(docView);
    // Then
    // Since the owner changed we don't need to load the old owner
    // The new owner also doesn't have to be loaded, except in full mode
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    ;
    if (isQueryStrategy()) {
        if (isFullMode()) {
            builder.update(Person.class);
        }
    } else {
        if (isFullMode()) {
            fullFetch(builder).select(Person.class);
        } else {
            builder.select(Document.class);
        }
    }
    builder.update(Document.class).validate();
    assertNoUpdateAndReload(docView);
    assertEquals(p2.getId(), doc1.getResponsiblePerson().getId());
}
Also used : UpdatableDocumentView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView) 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) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Aggregations

UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView)15 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)13 Test (org.junit.Test)13 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)9 Document (com.blazebit.persistence.testsuite.entity.Document)9 Person (com.blazebit.persistence.testsuite.entity.Person)8 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithCollectionsView)6 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithMapsView)5 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView)2 HashMap (java.util.HashMap)2 UpdatableNameObjectView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableNameObjectView)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1