use of com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateAddToNewCollectionAndModifyEntity.
@Test
public void testUpdateAddToNewCollectionAndModifyEntity() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = addToNewCollectionAndModifyEntity();
// Then
// Assert that the document and the people are loaded in full mode i.e. a full fetch
// When fetching like in full mode, we can do a proper diff and see that a single insert is enough
// But partial strategies currently favor not fetching, but collection recreations instead
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
}
} else {
if (preferLoadingAndDiffingOverRecreate()) {
fullFetch(builder);
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class).delete(Document.class, "contacts").insert(Document.class, "contacts");
}
}
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
builder.insert(Document.class, "contacts");
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals(doc1.getContacts(), docView.getContacts());
assertEquals("pers2", p2.getName());
}
use of com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateSetCollectionToNull.
@Test
public void testUpdateSetCollectionToNull() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = setCollectionToNull();
// Then
// Assert that only the document is loaded
// Since only an existing person was update, only a single update is generated
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
builder.delete(Document.class, "contacts").validate();
// Since the collection is empty we don't have to care for collection element changes
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isFullMode()) {
if (isQueryStrategy()) {
afterBuilder.delete(Document.class, "contacts");
versionUpdate(afterBuilder);
} else {
fullFetch(afterBuilder);
}
}
afterBuilder.validate();
assertNullMap(docView.getContacts());
assertEquals(0, doc1.getContacts().size());
}
use of com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateReplaceCollection.
@Test
public void testUpdateReplaceCollection() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = replaceCollection();
// Then
// Since entities are not mutable we can detect nothing changed
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isFullMode()) {
if (isQueryStrategy()) {
builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
versionUpdate(builder);
} else {
fullFetch(builder);
}
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateAddNullToCollection.
@Test
public void testUpdateAddNullToCollection() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = addNullToCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// Finally a single relation insert is done for the null element if supported
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
if (supportsNullCollectionElements()) {
builder.insert(Document.class, "contacts");
}
builder.validate();
assertNoUpdateAndReload(docView);
if (supportsNullCollectionElements()) {
assertEquals(doc1.getContacts(), docView.getContacts());
} else {
assertEquals(doc1.getContacts().size() + 1, docView.getContacts().size());
}
}
use of com.blazebit.persistence.view.testsuite.update.entity.updatableonly.model.UpdatableDocumentEntityWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityMapsTest method testUpdateModifyEntityInCollection.
@Test
public void testUpdateModifyEntityInCollection() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = modifyEntityInCollection();
// Then
// Assert that the document and the people are loaded in full mode i.e. a full fetch
// Since no collection was changed, no insters or updates are done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isFullMode()) {
if (isQueryStrategy()) {
if (isFullMode()) {
builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
versionUpdate(builder);
}
} else {
fullFetch(builder);
}
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals("pers1", p1.getName());
}
Aggregations