Search in sources :

Example 1 with UpdatableNameObjectView

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

the class EntityViewUpdateSimpleMutableFlatViewMapsTest method testUpdateCollectionElementClearAndReAdd.

@Test
public void testUpdateCollectionElementClearAndReAdd() {
    // Given
    final UpdatableDocumentWithMapsView docView = getDoc1View();
    clearQueries();
    // When
    Map<String, UpdatableNameObjectView> map = new HashMap<>(docView.getNameMap());
    docView.getNameMap().get("doc1").setPrimaryName("newPers");
    docView.getNameMap().clear();
    docView.getNameMap().putAll(map);
    update(docView);
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Finally the person is updated because the primary name changed
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (isQueryStrategy()) {
    } else {
        fullFetch(builder);
    }
    if (version || isQueryStrategy() && isFullMode()) {
        builder.update(Document.class);
    }
    if (supportsIndexedInplaceUpdate() && !isQueryStrategy() || isQueryStrategy() && !isFullMode()) {
        builder.assertUpdate().forRelation(Document.class, "nameMap").and();
    } else {
        builder.delete(Document.class, "nameMap").insert(Document.class, "nameMap");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNameMap().get("doc1").getPrimaryName());
    assertSubviewEquals(doc1.getNameMap(), docView.getNameMap());
}
Also used : AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) HashMap(java.util.HashMap) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView) UpdatableDocumentWithMapsView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentWithMapsView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 2 with UpdatableNameObjectView

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

the class EntityViewUpdateSimpleMutableFlatViewMapsTest method assertSubviewEquals.

public static void assertSubviewEquals(Map<String, NameObject> persons, Map<String, ? extends UpdatableNameObjectView> personSubviews) {
    if (persons == null) {
        assertNull(personSubviews);
        return;
    }
    assertNotNull(personSubviews);
    assertEquals(persons.size(), personSubviews.size());
    for (Map.Entry<String, NameObject> entry : persons.entrySet()) {
        NameObject p = entry.getValue();
        boolean found = false;
        UpdatableNameObjectView pSub = personSubviews.get(entry.getKey());
        if (pSub != null) {
            if (p.getPrimaryName().equals(pSub.getPrimaryName())) {
                found = true;
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a UpdatableNameObjectView with the name: " + p.getPrimaryName());
        }
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) HashMap(java.util.HashMap) Map(java.util.Map) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)

Example 3 with UpdatableNameObjectView

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

the class EntityViewUpdateSimpleMutableFlatViewCollectionsTest method testUpdateCollectionElementClearAndReAdd.

@Test
public void testUpdateCollectionElementClearAndReAdd() {
    // Given
    final UpdatableDocumentWithCollectionsView docView = getDoc1View();
    clearQueries();
    // When
    List<UpdatableNameObjectView> list = new ArrayList<>(docView.getNames());
    docView.getNames().get(0).setPrimaryName("newPers");
    docView.getNames().clear();
    docView.getNames().addAll(list);
    update(docView);
    // Then
    // Assert that the document and the people are loaded i.e. a full fetch
    // Finally the person is updated because the primary name changed
    AssertStatementBuilder builder = assertUnorderedQuerySequence();
    if (!isQueryStrategy()) {
        fullFetch(builder);
    }
    if (version || isFullMode() && isQueryStrategy()) {
        builder.update(Document.class);
    }
    if (isFullMode() || !isQueryStrategy() && !supportsIndexedInplaceUpdate()) {
        builder.delete(Document.class, "names").insert(Document.class, "names");
    } else {
        builder.update(Document.class, "names");
    }
    builder.validate();
    assertNoUpdateAndReload(docView);
    assertEquals("newPers", doc1.getNames().get(0).getPrimaryName());
    assertSubviewEquals(doc1.getNames(), docView.getNames());
}
Also used : UpdatableDocumentWithCollectionsView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentWithCollectionsView) AssertStatementBuilder(com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder) ArrayList(java.util.ArrayList) Document(com.blazebit.persistence.testsuite.entity.Document) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView) Test(org.junit.Test) AbstractEntityViewUpdateDocumentTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)

Example 4 with UpdatableNameObjectView

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

the class EntityViewUpdateSimpleMutableFlatViewCollectionsTest method assertSubviewEquals.

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

Aggregations

UpdatableNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)4 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)2 Document (com.blazebit.persistence.testsuite.entity.Document)2 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)2 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentWithCollectionsView)1 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableDocumentWithMapsView)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1