use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder 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.testsuite.base.jpa.assertion.AssertStatementBuilder 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.testsuite.base.jpa.assertion.AssertStatementBuilder 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.testsuite.base.jpa.assertion.AssertStatementBuilder 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());
}
use of com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder in project blaze-persistence by Blazebit.
the class EntityViewUpdateUpdatableOnlyEntityTest method testUpdateToNewPerson.
@Test
public void testUpdateToNewPerson() {
try {
// Given & When
final UpdatableDocumentEntityView docView = updateToNewPerson(true);
fail("Expected a transient reference error for the new person!");
} catch (PersistenceException | IllegalStateException ex) {
// Then
assertEquals(1L, updateCommitCount.get());
assertTrue(ex.getMessage().contains("transient"));
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
}
// We need to load the rollback view
builder.select(Document.class);
builder.validate();
clearPersistenceContextAndReload();
assertEquals(p1.getId(), doc1.getResponsiblePerson().getId());
}
}
Aggregations