use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewCollectionsTest method testUpdateAddToNewCollectionAndModify.
@Test
public void testUpdateAddToNewCollectionAndModify() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
clearQueries();
// When
newPerson.setName("newPerson");
docView.setPeople(new ArrayList<>(docView.getPeople()));
docView.getPeople().add(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.delete(Document.class, "people").insert(Document.class, "people");
builder.update(Person.class);
}
builder.update(Person.class);
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
fullFetch(builder);
builder.select(Person.class);
if (version) {
builder.update(Document.class);
}
builder.update(Person.class);
}
builder.assertInsert().forRelation(Document.class, "people").validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
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 testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
clearQueries();
// When
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()) {
fullFetch(builder);
}
if (isFullMode()) {
if (isQueryStrategy()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
builder.update(Person.class).update(Person.class);
} else {
builder.select(Person.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.assertInsert().forRelation(Document.class, "people").validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewCollectionsTest method testUpdateAddToNewCollection.
@Test
public void testUpdateAddToNewCollection() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
clearQueries();
// When
docView.setPeople(new ArrayList<>(docView.getPeople()));
docView.getPeople().add(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()) {
fullFetch(builder);
}
if (isFullMode()) {
if (isQueryStrategy()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
builder.update(Person.class).update(Person.class);
} else {
builder.select(Person.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.assertInsert().forRelation(Document.class, "people").validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatablePersonView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewCollectionsTest method testUpdateAddToCollectionAndModify.
@Test
public void testUpdateAddToCollectionAndModify() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
clearQueries();
// When
newPerson.setName("newPerson");
docView.getPeople().add(newPerson);
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 assertSubviewEquals.
public static void assertSubviewEquals(Map<Integer, Person> persons, Map<Integer, ? extends UpdatablePersonView> personSubviews) {
if (persons == null) {
assertNull(personSubviews);
return;
}
assertNotNull(personSubviews);
assertEquals(persons.size(), personSubviews.size());
for (Map.Entry<Integer, Person> entry : persons.entrySet()) {
Person p = entry.getValue();
boolean found = false;
UpdatablePersonView pSub = personSubviews.get(entry.getKey());
if (pSub != null) {
if (p.getName().equals(pSub.getName())) {
found = true;
break;
}
}
if (!found) {
Assert.fail("Could not find a person subview instance with the name: " + p.getName());
}
}
}
Aggregations