use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToCollectionAndModifyEntity.
@Test
public void testUpdateAddToCollectionAndModifyEntity() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView docView = addToCollectionAndModifyEntity();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// In addition, the new person is loaded because of the merge invocation
// Finally a single relation insert is done and an update to the person is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.select(Person.class);
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder).select(Person.class);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.update(Person.class).insert(Document.class, "people").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);
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(afterBuilder);
}
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
afterBuilder.validate();
assertEquals(doc1.getPeople(), docView.getPeople());
assertEquals("newPerson", p2.getName());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateSetCollectionToNull.
@Test
public void testUpdateSetCollectionToNull() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView 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()) {
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
if (version) {
builder.update(Document.class);
}
}
builder.delete(Document.class, "people").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, "people");
} else {
fullFetch(afterBuilder);
}
if (version || isQueryStrategy()) {
afterBuilder.update(Document.class);
}
}
afterBuilder.validate();
assertNullCollection(docView.getPeople());
assertEquals(0, doc1.getPeople().size());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddNewEntityToCollection.
@Test
public void testUpdateAddNewEntityToCollection() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView docView = addNewEntityToCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// In addition, the new person is loaded because of the merge invocation
// Finally the person is persisted and a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder);
}
builder.insert(Person.class);
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "people").validate();
// Unfortunately, even after an update, we have to reload the entity to merge again
// This time we even have to re-load owned associations because they aren't lazy and could be dirty
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
afterBuilder.select(Person.class);
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(afterBuilder);
}
afterBuilder.assertSelect().fetching(Person.class, "favoriteDocuments").fetching(Document.class).and().assertSelect().fetching(Person.class, "localized").and().select(Document.class);
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
if (doesJpaMergeOfRecentlyPersistedEntityForceUpdate()) {
afterBuilder.update(Person.class);
}
afterBuilder.validate();
assertEquals(doc1.getPeople(), docView.getPeople());
Iterator<Person> iter = doc1.getPeople().iterator();
Person nextPerson = iter.next();
if (nextPerson.getId().equals(p1.getId())) {
assertEquals("pers1", nextPerson.getName());
assertEquals("newPerson", iter.next().getName());
} else {
assertEquals("newPerson", nextPerson.getName());
assertEquals("pers1", iter.next().getName());
}
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest 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
// In addition, the new person is loaded because of the merge invocation, but only a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.select(Person.class);
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder).select(Person.class);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "people").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);
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(afterBuilder);
}
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
afterBuilder.validate();
assertEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEntityCollectionsTest method testUpdateAddToNewCollectionAndModifyEntity.
@Test
public void testUpdateAddToNewCollectionAndModifyEntity() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView docView = addToNewCollectionAndModifyEntity();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// In addition, the new person is loaded because of the merge invocation
// Finally a single relation insert is done and an update to the person is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.select(Person.class);
builder.select(Person.class);
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder).select(Person.class);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.update(Person.class).insert(Document.class, "people").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);
afterBuilder.select(Person.class);
if (isFullMode()) {
afterBuilder.delete(Document.class, "people").insert(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(afterBuilder);
}
if (version || isQueryStrategy() && isFullMode()) {
afterBuilder.update(Document.class);
}
afterBuilder.validate();
assertEquals(doc1.getPeople(), docView.getPeople());
assertEquals("newPerson", p2.getName());
}
Aggregations