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());
}
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());
}
}
}
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());
}
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());
}
}
}
Aggregations