Search in sources :

Example 1 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateSimpleMutableSubviewMapsTest method testClearUpdateAddToCollectionAndModify.

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

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithMapsView 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 3 with UpdatableDocumentWithMapsView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithMapsView 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 4 with UpdatableDocumentWithMapsView

use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithMapsView 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 5 with UpdatableDocumentWithMapsView

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

the class EntityViewUpdateSimpleMutableSubviewMapsTest method testUpdateReplaceCollection.

@Test
public void testUpdateReplaceCollection() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    clearQueries();
    // When
    docView.setContacts(new HashMap<>(docView.getContacts()));
    update(docView);
    // Then
    // Assert that the document and the people are loaded in full mode.
    // During dirty detection we should be able to figure out that nothing changed
    // So partial modes wouldn't load anything and both won't cause any updates
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isFullMode()) {
        if (isQueryStrategy()) {
            builder.update(Person.class);
            builder.update(Document.class);
            builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
        } else {
            fullFetch(builder);
        }
    }
    builder.validate();
    assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
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.subview.simple.mutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Aggregations

AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)6 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithMapsView)6 Test (org.junit.Test)6 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView)5 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)4 Document (com.blazebit.persistence.testsuite.entity.Document)4 Person (com.blazebit.persistence.testsuite.entity.Person)2 HashMap (java.util.HashMap)1