use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateCreatableEntityCollectionsTest 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
// The added person is not loaded, only a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.assertInsert().forRelation(Document.class, "people").validate();
assertNoUpdateAndReload(docView, true);
assertEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateCreatableEntityCollectionsTest method testUpdateAddToNewCollection.
@Test
public void testUpdateAddToNewCollection() {
// Given & When
final UpdatableDocumentEntityWithCollectionsView docView = addToNewCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// The added person is not loaded, only a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
builder.delete(Document.class, "people").insert(Document.class, "people");
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
builder.update(Document.class);
}
builder.assertInsert().forRelation(Document.class, "people").validate();
// No need for an update since it isn't dirty
assertNoUpdateAndReload(docView, true);
assertEquals(doc1.getPeople(), docView.getPeople());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToCollectionAndModifyEntity.
@Test
public void testUpdateAddToCollectionAndModifyEntity() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = addToCollectionAndModifyEntity();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// The added person is not loaded, only a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertEquals(doc1.getContacts(), docView.getContacts());
assertEquals("pers2", p2.getName());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class EntityViewUpdateCreatableEntityMapsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given & When
final UpdatableDocumentEntityWithMapsView docView = addToCollection();
// Then
// Assert that the document and the people are loaded i.e. a full fetch
// The added person is not loaded, only a single relation insert is done
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode()) {
assertReplaceAnd(builder);
}
} else {
fullFetch(builder);
}
if (version || isQueryStrategy() && isFullMode()) {
versionUpdate(builder);
}
builder.insert(Document.class, "contacts").validate();
assertNoUpdateAndReload(docView, true);
assertEquals(doc1.getContacts(), docView.getContacts());
}
use of com.blazebit.persistence.testsuite.entity.Document 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());
}
Aggregations