use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateAddToNewCollection.
@Test
public void testUpdateAddToNewCollection() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
clearQueries();
// When
docView.setContacts(new HashMap<>(docView.getContacts()));
docView.getContacts().put(2, newPerson);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class).update(Person.class);
assertReplaceAnd(builder);
}
} else {
fullFetch(builder);
if (isFullMode()) {
// In full mode we need to select the added element for cascading the update
builder.select(Person.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateAddToNewCollectionAndModify.
@Test
public void testUpdateAddToNewCollectionAndModify() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
clearQueries();
// When
newPerson.getFriend().setName("newPerson");
docView.setContacts(new HashMap<>(docView.getContacts()));
docView.getContacts().put(2, newPerson);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class).update(Person.class);
assertReplaceAnd(builder);
}
} else {
fullFetch(builder);
if (isFullMode()) {
// In full mode we need to select the added element for cascading the update
builder.select(Person.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertEquals("pers4", p4.getName());
docView.getContacts().get(2).getFriend().setName("pers4");
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateAddToCollectionAndModify.
@Test
public void testUpdateAddToCollectionAndModify() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
clearQueries();
// When
newPerson.getFriend().setName("newPerson");
docView.getContacts().put(2, newPerson);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class).update(Person.class);
assertReplaceAnd(builder);
}
} else {
fullFetch(builder);
if (isFullMode()) {
// In full mode we need to select the added element for cascading the update
builder.select(Person.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertEquals("pers4", p4.getName());
docView.getContacts().get(2).getFriend().setName("pers4");
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatableResponsiblePersonView newPerson = getP2View(UpdatableResponsiblePersonView.class);
clearQueries();
// When
docView.getContacts().put(2, newPerson);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class).update(Person.class);
assertReplaceAnd(builder);
}
} else {
fullFetch(builder);
if (isFullMode()) {
// In full mode we need to select the added element for cascading the update
builder.select(Person.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.subview.nested.immutable.model.UpdatableDocumentWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedImmutableSubviewMapsTest method testUpdateModifyCollectionElementCopy.
@Test
public void testUpdateModifyCollectionElementCopy() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
FriendPersonView newFriend = getPersonView(p3.getId(), FriendPersonView.class);
clearQueries();
// When
newFriend.setName("newFriend");
docView.getContacts().get(1).setFriend(newFriend);
update(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
builder.update(Person.class);
versionUpdate(builder);
}
} else {
if (isFullMode()) {
fullFetch(builder);
if (version) {
versionUpdate(builder);
}
}
}
builder.validate();
assertNoUpdateAndReload(docView, true);
assertEquals(p3.getId(), p1.getFriend().getId());
assertEquals("pers3", p3.getName());
docView.getContacts().get(1).getFriend().setName("pers3");
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
}
Aggregations