use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
docView.setName("newDoc");
update(docView);
// Then
// Since only the document changed we don't need to load the owner
// Just assert the update is properly done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class);
}
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
}
builder.update(Document.class).validate();
assertNoUpdateAndReload(docView);
assertEquals("newDoc", docView.getName());
assertEquals(doc1.getName(), docView.getName());
}
use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateToNull.
@Test
public void testUpdateToNull() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
docView.setResponsiblePerson(null);
update(docView);
// Then
// Assert that only the document is loaded and finally also updated
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (!isQueryStrategy()) {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
}
builder.update(Document.class).validate();
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isFullMode()) {
if (isQueryStrategy()) {
afterBuilder.update(Document.class);
} else {
fullFetch(afterBuilder);
}
}
afterBuilder.validate();
Assert.assertNull(doc1.getResponsiblePerson());
}
use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithModifyExisting.
@Test
public void testUpdateWithModifyExisting() {
// Given
final UpdatableDocumentView docView = getDoc1View();
clearQueries();
// When
docView.getResponsiblePerson().setName("newPerson");
update(docView);
// Then
// Since we update the old responsiblePerson, load it along with the document for updating it later
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.update(Person.class);
if (isFullMode() || version) {
builder.update(Document.class);
}
} else {
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
builder.update(Person.class);
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals("newPerson", doc1.getResponsiblePerson().getName());
}
use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithModifySubview.
@Test
public void testUpdateWithModifySubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
clearQueries();
// When
newOwner.setName("newPerson");
docView.setResponsiblePerson(newOwner);
update(docView);
// Then
// Since the owner changed we don't need to load the old owner
// Now the new owner has to be loaded as it is updated as well
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
builder.update(Person.class).update(Document.class);
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
builder.select(Document.class);
}
builder.select(Person.class).update(Document.class).update(Person.class);
}
builder.validate();
assertNoUpdateAndReload(docView);
assertEquals(p2.getId(), doc1.getResponsiblePerson().getId());
assertEquals("newPerson", doc1.getResponsiblePerson().getName());
}
use of com.blazebit.persistence.view.testsuite.update.subview.simple.mutable.model.UpdatableDocumentView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewTest method testUpdateWithSubview.
@Test
public void testUpdateWithSubview() {
// Given
final UpdatableDocumentView docView = getDoc1View();
UpdatablePersonView newOwner = getP2View(UpdatablePersonView.class);
clearQueries();
// When
docView.setResponsiblePerson(newOwner);
update(docView);
// Then
// Since the owner changed we don't need to load the old owner
// The new owner also doesn't have to be loaded, except in full mode
AssertStatementBuilder builder = assertUnorderedQuerySequence();
;
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class);
}
} else {
if (isFullMode()) {
fullFetch(builder).select(Person.class);
} else {
builder.select(Document.class);
}
}
builder.update(Document.class).validate();
assertNoUpdateAndReload(docView);
assertEquals(p2.getId(), doc1.getResponsiblePerson().getId());
}
Aggregations