use of com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateModifyCollectionElementAndModify.
@Test
public void testUpdateModifyCollectionElementAndModify() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatableFriendPersonView newFriend = getPersonView(p4.getId(), UpdatableFriendPersonView.class);
clearQueries();
// When
newFriend.setName("newFriend");
docView.getPeople().get(0).setFriend(newFriend);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
}
builder.update(Person.class).update(Person.class);
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.assertSelect().fetching(Document.class).fetching(Document.class, "people").fetching(Person.class).and();
}
builder.select(Person.class);
if (version) {
builder.update(Document.class);
}
builder.update(Person.class).update(Person.class);
}
builder.validate();
assertNoCollectionUpdateFullAndReload(docView);
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
assertEquals(p4.getId(), p1.getFriend().getId());
assertEquals("newFriend", p4.getName());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateAddToNewCollectionAndModify.
@Test
public void testUpdateAddToNewCollectionAndModify() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
clearQueries();
// When
newPerson.getFriend().setName("newPerson");
docView.setPeople(new ArrayList<>(docView.getPeople()));
docView.getPeople().add(newPerson);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
builder.update(Person.class);
builder.update(Person.class);
builder.update(Person.class);
}
builder.update(Person.class);
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
fullFetch(builder).assertSelect().fetching(Person.class).fetching(Person.class).and();
if (version) {
builder.update(Document.class);
}
builder.update(Person.class);
}
builder.assertInsert().forRelation(Document.class, "people").and().validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
assertEquals("newPerson", p4.getName());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
clearQueries();
// When
docView.getPeople().add(newPerson);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isFullMode()) {
if (isQueryStrategy()) {
fullUpdate(builder);
} else {
fullFetch(builder).select(Person.class);
if (version) {
builder.update(Document.class);
}
}
} else {
if (!isQueryStrategy()) {
builder.assertSelect().fetching(Document.class).fetching(Document.class, "people").fetching(Person.class).and();
}
if (version) {
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.nested.mutable.model.UpdatableDocumentWithCollectionsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateModifyCollectionElement.
@Test
public void testUpdateModifyCollectionElement() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatableFriendPersonView newFriend = getPersonView(p4.getId(), UpdatableFriendPersonView.class);
clearQueries();
// When
docView.getPeople().get(0).setFriend(newFriend);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder).update(Person.class);
}
builder.update(Person.class);
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(builder).select(Person.class);
} else {
builder.assertSelect().fetching(Document.class).fetching(Document.class, "people").fetching(Person.class).and();
}
if (version) {
builder.update(Document.class);
}
builder.update(Person.class);
}
builder.validate();
assertNoCollectionUpdateFullAndReload(docView);
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
assertEquals(p4.getId(), p1.getFriend().getId());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.mutable.model.UpdatableDocumentWithCollectionsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableSubviewCollectionsTest method testUpdateModifyCollectionElementCopy.
@Test
public void testUpdateModifyCollectionElementCopy() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
UpdatableFriendPersonView newFriend = getPersonView(p3.getId(), UpdatableFriendPersonView.class);
clearQueries();
// When
newFriend.setName("newFriend");
docView.getPeople().get(0).setFriend(newFriend);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
builder.update(Person.class);
}
builder.update(Person.class);
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
builder.update(Person.class);
}
builder.validate();
assertNoCollectionUpdateFullAndReload(docView);
assertEquals(p3.getId(), p1.getFriend().getId());
assertEquals("newFriend", p3.getName());
assertSubviewEquals(doc1.getPeople(), docView.getPeople());
}
Aggregations