use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleUpdatableOnlySubviewMapsTest method testUpdateAddToNewCollectionAndModifySubview.
@Test
public void testUpdateAddToNewCollectionAndModifySubview() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
PersonView newPerson = getP2View(PersonView.class);
clearQueries();
// When
newPerson.setName("newPerson");
docView.setContacts(new HashMap<>(docView.getContacts()));
docView.getContacts().put(2, newPerson);
update(docView);
// Then
// In partial mode, only the document is loaded. In full mode, the people are also loaded
// Since we load the people in the full mode, we do a proper diff and can compute that only a single item was added
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
}
} else {
if (isFullMode()) {
fullFetch(builder);
} else {
if (preferLoadingAndDiffingOverRecreate()) {
fullFetch(builder);
} else {
assertReplaceAnd(builder);
}
}
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView);
assertEquals(doc1.getContacts().size(), docView.getContacts().size());
assertEquals("pers2", p2.getName());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableOnlySubviewTest 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.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubviewMapsTest method testUpdateAddToNewCollectionAndModify.
@Test
public void testUpdateAddToNewCollectionAndModify() {
// Given
final UpdatableDocumentWithMapsView docView = getDoc1View();
UpdatablePersonView newPerson = getP2View(UpdatablePersonView.class);
clearQueries();
// When
newPerson.setName("newPerson");
docView.setContacts(new HashMap<>(docView.getContacts()));
docView.getContacts().put(2, newPerson);
update(docView);
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// In addition, the new person is loaded because it is dirty
// Finally a single relation insert is done and an update to the person is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.update(Person.class);
builder.delete(Document.class, "contacts").insert(Document.class, "contacts");
}
builder.update(Person.class);
} else {
fullFetch(builder);
builder.select(Person.class);
builder.update(Person.class);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertSubviewEquals(doc1.getContacts(), docView.getContacts());
assertEquals("newPerson", p2.getName());
}
use of com.blazebit.persistence.testsuite.entity.Document 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.testsuite.entity.Document 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());
}
Aggregations