use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddNullToCollection.
@Test
public void testUpdateAddNullToCollection() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView 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()) {
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
if (supportsNullCollectionElements()) {
builder.insert(Document.class, "people");
}
builder.validate();
// Unfortunately, even after an update, we have to reload the entity to merge again
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(afterBuilder);
}
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
afterBuilder.validate();
if (supportsNullCollectionElements()) {
assertEquals(doc1.getPeople(), docView.getPeople());
}
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableFlatViewCollectionsTest method testUpdateCollectionElement.
@Test
public void testUpdateCollectionElement() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
clearQueries();
// When
docView.getNames().get(0).setPrimaryName("newPers");
update(docView);
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// Finally the person is updated because the primary name changed
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
fullFetch(builder);
}
if (version || isFullMode() && isQueryStrategy()) {
builder.update(Document.class);
}
if (isFullMode() || !isQueryStrategy() && !supportsIndexedInplaceUpdate()) {
builder.delete(Document.class, "names").insert(Document.class, "names");
} else {
builder.update(Document.class, "names");
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals("newPers", doc1.getNames().get(0).getPrimaryName());
assertSubviewEquals(doc1.getNames(), docView.getNames());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableFlatViewMapsTest method testUpdateCollectionElementClearAndReAdd.
@Test
public void testUpdateCollectionElementClearAndReAdd() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
clearQueries();
// When
Map<String, UpdatableNameObjectView> map = new HashMap<>(docView.getNameMap());
docView.getNameMap().get("doc1").setPrimaryName("newPers");
docView.getNameMap().clear();
docView.getNameMap().putAll(map);
update(docView);
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// Finally the person is updated because the primary name changed
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
if (supportsIndexedInplaceUpdate() && !isQueryStrategy() || isQueryStrategy() && !isFullMode()) {
builder.assertUpdate().forRelation(Document.class, "nameMap").and();
} else {
builder.delete(Document.class, "nameMap").insert(Document.class, "nameMap");
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals("newPers", doc1.getNameMap().get("doc1").getPrimaryName());
assertSubviewEquals(doc1.getNameMap(), docView.getNameMap());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableFlatViewTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
docView.getNameObject().setPrimaryName("newDoc");
update(docView);
// Then
// Since the only the documents primaryName changed we only need to load the document
// In full mode, the person also has to be loaded
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
}
builder.update(Document.class).validate();
assertNoUpdateAndReload(docView);
Assert.assertEquals("newDoc", docView.getNameObject().getPrimaryName());
Assert.assertEquals(doc1.getNameObject().getPrimaryName(), docView.getNameObject().getPrimaryName());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder 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());
}
Aggregations