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