Search in sources :

Example 6 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 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 7 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 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 8 with UpdatablePersonView

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

the class EntityViewUpdateSimpleMutableSubviewCollectionsTest method testUpdateReferenceAddToCollection.

@Test
public void testUpdateReferenceAddToCollection() {
    Assume.assumeFalse("Partial reference updates don't work in full mode", isFullMode());
    // Given
    final UpdatableDocumentWithCollectionsView docView = evm.getReference(viewType, doc1.getId());
    UpdatablePersonView newPerson = evm.getReference(UpdatablePersonView.class, p2.getId());
    clearQueries();
    // When
    newPerson.setNameObject(evm.create(UpdatableNameObjectView.class));
    newPerson.setName("new-p2");
    newPerson.getNameObject().setPrimaryName("p2-test");
    docView.getPeople().add(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()) {
        builder.select(Document.class).select(Person.class);
    }
    builder.update(Person.class).delete(Document.class, "people").insert(Document.class, "people").validate();
    assertNoUpdateAndReload(docView, false);
    assertSubviewEquals(doc1.getPeople(), getDoc1View().getPeople());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithCollectionsView) 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) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableNameObjectView) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 9 with UpdatablePersonView

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

the class EntityViewUpdateSimpleMutableSubviewCollectionsTest method testClearUpdateAddToCollectionAndModify.

@Test
public void testClearUpdateAddToCollectionAndModify() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
    clearQueries();
    // When
    newPerson.setName("newPerson");
    docView.getPeople().add(newPerson);
    List<UpdatablePersonView> copy = new ArrayList<>(docView.getPeople());
    docView.getPeople().clear();
    docView.getPeople().addAll(copy);
    verifyUpdateAddToCollectionAndModify(docView);
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentWithCollectionsView) UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView) ArrayList(java.util.ArrayList) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 10 with UpdatablePersonView

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

the class EntityViewUpdateSimpleMutableSubviewCollectionsTest method assertSubviewEquals.

public void assertSubviewEquals(Collection<Person> persons, Collection<UpdatablePersonView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (Person p : persons) {
        boolean found = false;
        for (UpdatablePersonView pSub : personSubviews) {
            if (p.getName().equals(pSub.getName())) {
                found = true;
                assertEquals(p.getNameObject().getPrimaryName(), pSub.getNameObject().getPrimaryName());
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a person subview instance with the name: " + p.getName());
        }
    }
}
Also used : UpdatablePersonView(com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView) Person(com.blazebit.persistence.testsuite.entity.Person)

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