use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableFlatViewMapsTest method testUpdateCollectionElement.
@Test
public void testUpdateCollectionElement() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
clearQueries();
// When
docView.getNameContainerMap().get("doc1").getNameObject().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();
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
if (supportsIndexedInplaceUpdate() && (!isQueryStrategy() || isQueryStrategy() && !isFullMode())) {
builder.update(Document.class, "nameContainerMap");
} else {
builder.delete(Document.class, "nameContainerMap").insert(Document.class, "nameContainerMap");
}
assertNoUpdateAndReload(docView);
assertEquals("newPers", doc1.getNameContainerMap().get("doc1").getNameObject().getPrimaryName());
assertSubviewEquals(doc1.getNameContainerMap(), docView.getNameContainerMap());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableFlatViewTest method testUpdateWithSubview.
@Test
public void testUpdateWithSubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
docView.getNameContainer().getNameObject().setPrimaryName("newPers");
update(docView);
// Then
// Since the owner's name changed we, have to load the document and the owner
// We apply the change which results in an update
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
fullFetch(builder);
}
builder.update(Document.class).validate();
assertNoUpdateAndReload(docView);
Assert.assertEquals("newPers", docView.getNameContainer().getNameObject().getPrimaryName());
Assert.assertEquals(doc1.getNameContainer().getNameObject().getPrimaryName(), docView.getNameContainer().getNameObject().getPrimaryName());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubtypeFlatViewMapsTest method testUpdateCollectionElement.
@Test
public void testUpdateCollectionElement() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
clearQueries();
// When
UpdatableNameObjectView updatableNameObjectView = evm.convert(docView.getNameMap().get("doc1"), UpdatableNameObjectView.class);
updatableNameObjectView.setPrimaryName("newPers");
docView.getNameMap().put("doc1", updatableNameObjectView);
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 EntityViewUpdateSimpleMutableSubtypeFlatViewTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
UpdatableNameObjectView updatableNameObjectView = evm.convert(docView.getNameObject(), UpdatableNameObjectView.class);
updatableNameObjectView.setPrimaryName("newDoc");
docView.setNameObject(updatableNameObjectView);
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 EntityViewUpdateSimpleMutableSubtypeFlatViewTest method testUpdateWithSubview.
@Test
public void testUpdateWithSubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
UpdatableNameObjectView updatableNameObjectView = evm.convert(docView.getNameObject(), UpdatableNameObjectView.class);
updatableNameObjectView.setPrimaryName("newPers");
docView.setNameObject(updatableNameObjectView);
update(docView);
// Then
// Since the owner's name changed we, have to load the document and the owner
// We apply the change which results in an update
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
fullFetch(builder);
}
builder.update(Document.class).validate();
assertNoUpdateAndReload(docView);
Assert.assertEquals("newPers", docView.getNameObject().getPrimaryName());
Assert.assertEquals(doc1.getNameObject().getPrimaryName(), docView.getNameObject().getPrimaryName());
}
Aggregations