use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableOnlyEntityTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
// Given & When
final UpdatableDocumentEntityView docView = simpleUpdate();
// Then
// Assert that not only the document is loaded, but also always the responsiblePerson
// This might be unexpected for partial strategies
// but since we don't know if entities are dirty, we need to be conservative and load the object
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.assertSelect().fetching(Person.class).and();
} else {
fullFetch(builder);
}
builder.update(Document.class).validate();
// Unfortunately, even after an update, we have to reload the entity to merge again
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
afterBuilder.assertSelect().fetching(Person.class).and();
if (isFullMode()) {
afterBuilder.update(Document.class);
} else if (version) {
versionUpdate(afterBuilder);
}
} else {
afterBuilder.assertSelect().fetching(Document.class, Person.class).and();
if (version) {
afterBuilder.update(Document.class);
}
}
afterBuilder.validate();
assertEquals("newDoc", docView.getName());
assertEquals(doc1.getName(), docView.getName());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableOnlyEntityTest method testUpdateWithModifyExisting.
@Test
public void testUpdateWithModifyExisting() {
// Given & When
final UpdatableDocumentEntityView docView = updateWithModifyExisting();
// Then
// Since we update the old responsiblePerson, load it along with the document for updating it later
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.assertSelect().fetching(Person.class).and();
if (isFullMode()) {
builder.update(Document.class);
} else if (version) {
versionUpdate(builder);
}
} else {
fullFetch(builder);
if (version) {
versionUpdate(builder);
}
}
builder.update(Person.class).validate();
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
afterBuilder.assertSelect().fetching(Person.class).and();
if (isFullMode()) {
afterBuilder.update(Document.class);
} else if (version) {
versionUpdate(afterBuilder);
}
} else {
afterBuilder.assertSelect().fetching(Document.class, Person.class).and();
if (version) {
afterBuilder.update(Document.class);
}
}
afterBuilder.validate();
assertEquals(doc1.getResponsiblePerson().getId(), docView.getResponsiblePerson().getId());
assertEquals("newOwner", doc1.getResponsiblePerson().getName());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityCollectionsTest 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 (isFullMode()) {
if (isQueryStrategy()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
} else {
fullFetch(builder);
}
} else if (!isQueryStrategy()) {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
builder.validate();
assertNoUpdateAndReload(docView);
if (supportsNullCollectionElements()) {
assertEquals(doc1.getPeople(), docView.getPeople());
} else {
assertEquals(doc1.getPeople().size() + 1, docView.getPeople().size());
}
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityCollectionsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView docView = addToCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// Finally a single relation insert is done. In partial modes that don't do fetching, a collection recreation is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isFullMode()) {
if (isQueryStrategy()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
} else {
fullFetch(builder);
}
} else if (!isQueryStrategy()) {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
builder.assertInsert().forRelation(Document.class, "people").and();
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateNestedMutableFlatViewCollectionsTest method testUpdateCollectionElement.
@Test
public void testUpdateCollectionElement() {
// Given
final UpdatableDocumentWithCollectionsView docView = getDoc1View();
clearQueries();
// When
docView.getNameContainers().get(0).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();
if (!isQueryStrategy()) {
fullFetch(builder);
}
if (version || isFullMode() && isQueryStrategy()) {
builder.update(Document.class);
}
if (isFullMode()) {
builder.delete(Document.class, "nameContainers").insert(Document.class, "nameContainers");
} else {
builder.update(Document.class, "nameContainers");
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals("newPers", doc1.getNameContainers().get(0).getNameObject().getPrimaryName());
assertSubviewEquals(doc1.getNameContainers(), docView.getNameContainers());
}
Aggregations