use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableMapsTest method testUpdateAddToNewCollection.
@Test
public void testUpdateAddToNewCollection() {
// Given
final UpdatableDocumentEmbeddableWithMapsView docView = updateAddToNewCollection();
Long oldVersion = docView.getVersion();
assertChangesUpdateAndFlush(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode() || !registerType) {
assertReplaceAnd(builder);
}
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
if (!registerType) {
assertReplaceAnd(builder);
}
} else {
if (registerType && preferLoadingAndDiffingOverRecreate()) {
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
} else {
builder.select(Document.class);
if (version) {
builder.update(Document.class);
}
assertReplaceAnd(builder);
}
}
}
builder.assertInsert().forRelation(Document.class, "nameMap").validate();
assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
if (isFullMode() || !registerType) {
assertReplaceAnd(afterBuilder);
if (isFullMode() && registerType) {
afterBuilder.insert(Document.class, "nameMap");
}
}
if (isFullMode() || version && !registerType) {
afterBuilder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(afterBuilder);
if (!registerType) {
assertReplaceAnd(afterBuilder);
if (version) {
afterBuilder.update(Document.class);
}
}
} else {
if (!registerType) {
afterBuilder.select(Document.class);
if (version) {
afterBuilder.update(Document.class);
}
assertReplaceAnd(afterBuilder);
}
}
}
if (!registerType) {
afterBuilder.assertInsert().forRelation(Document.class, "nameMap").and();
assertVersionDiff(oldVersion, docView.getVersion(), 2, 2);
} else {
assertVersionDiff(oldVersion, docView.getVersion(), 1, isQueryStrategy() ? 2 : 1);
}
afterBuilder.validate();
assertEquals(doc1.getNameMap(), docView.getNameMap());
}
use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableMapsTest method testUpdateReplaceCollection.
@Test
public void testUpdateReplaceCollection() {
// Given
final UpdatableDocumentEmbeddableWithMapsView docView = updateReplaceCollection();
Long oldVersion = docView.getVersion();
assertMutableChangeModel(docView);
update(docView);
assertMutableChangeModel(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode() || !registerType) {
assertReplaceAnd(builder);
}
if (isFullMode() || version && !registerType) {
builder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(builder);
if (!registerType) {
assertReplaceAnd(builder);
if (version) {
builder.update(Document.class);
}
}
} else {
if (!registerType) {
builder.select(Document.class);
if (version) {
builder.update(Document.class);
}
assertReplaceAnd(builder);
}
}
}
builder.validate();
if (registerType) {
assertVersionDiff(oldVersion, docView.getVersion(), 0, isQueryStrategy() ? 1 : 0);
} else {
assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
}
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
if (isFullMode() || !registerType) {
assertReplaceAnd(afterBuilder);
}
if (isFullMode() || version && !registerType) {
afterBuilder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(afterBuilder);
if (!registerType) {
assertReplaceAnd(afterBuilder);
if (version) {
afterBuilder.update(Document.class);
}
}
} else {
if (!registerType) {
afterBuilder.select(Document.class);
if (version) {
afterBuilder.update(Document.class);
}
assertReplaceAnd(afterBuilder);
}
}
}
afterBuilder.validate();
if (registerType) {
assertVersionDiff(oldVersion, docView.getVersion(), 0, isQueryStrategy() ? 2 : 0);
} else {
assertVersionDiff(oldVersion, docView.getVersion(), 2, 2);
}
assertEquals(doc1.getNameMap(), docView.getNameMap());
}
use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableMapsTest method testUpdateRemoveNonExisting.
@Test
public void testUpdateRemoveNonExisting() {
// Given
final UpdatableDocumentEmbeddableWithMapsView docView = updateRemoveNonExisting();
// When
update(docView);
// Then
clearPersistenceContextAndReload();
assertEquals(doc1.getNameMap(), docView.getNameMap());
}
use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableMapsTest method testUpdateAddToCollection.
@Test
public void testUpdateAddToCollection() {
// Given
final UpdatableDocumentEmbeddableWithMapsView docView = updateAddToCollection();
Long oldVersion = docView.getVersion();
assertChangesUpdateAndFlush(docView);
// Then
AssertStatementBuilder builder = assertUnorderedQuerySequence();
if (isQueryStrategy()) {
if (isFullMode() || !registerType) {
assertReplaceAnd(builder);
}
if (version || isFullMode()) {
builder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
if (!registerType) {
assertReplaceAnd(builder);
}
} else {
if (registerType && preferLoadingAndDiffingOverRecreate()) {
fullFetch(builder);
if (version) {
builder.update(Document.class);
}
} else {
builder.select(Document.class);
if (version) {
builder.update(Document.class);
}
assertReplaceAnd(builder);
}
}
}
builder.insert(Document.class, "nameMap").validate();
assertVersionDiff(oldVersion, docView.getVersion(), 1, 1);
AssertStatementBuilder afterBuilder = assertQueriesAfterUpdate(docView);
if (isQueryStrategy()) {
if (isFullMode() || !registerType) {
assertReplaceAnd(afterBuilder);
if (isFullMode() && registerType) {
afterBuilder.insert(Document.class, "nameMap");
}
}
if (isFullMode() || version && !registerType) {
afterBuilder.update(Document.class);
}
} else {
if (isFullMode()) {
fullFetch(afterBuilder);
if (!registerType) {
assertReplaceAnd(afterBuilder);
if (version) {
afterBuilder.update(Document.class);
}
}
} else {
if (!registerType) {
afterBuilder.select(Document.class);
if (version) {
afterBuilder.update(Document.class);
}
assertReplaceAnd(afterBuilder);
}
}
}
if (!registerType) {
afterBuilder.assertInsert().forRelation(Document.class, "nameMap").and();
assertVersionDiff(oldVersion, docView.getVersion(), 2, 2);
} else {
assertVersionDiff(oldVersion, docView.getVersion(), 1, isQueryStrategy() ? 2 : 1);
}
afterBuilder.validate();
assertEquals(doc1.getNameMap(), docView.getNameMap());
}
use of com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableMapsTest method assertMutableChangeModel.
private void assertMutableChangeModel(UpdatableDocumentEmbeddableWithMapsView docView) {
if (!isFullMode()) {
SingularChangeModel<UpdatableDocumentEmbeddableWithMapsView> changeModel = evm.getChangeModel(docView);
MapChangeModel<?, ?> nameMapChange = (MapChangeModel<Object, Object>) changeModel.<Map<Object, Object>>get("nameMap");
if (registerType) {
assertFalse(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, changeModel.getKind());
assertFalse(nameMapChange.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, nameMapChange.getKind());
assertEquals(0, nameMapChange.getAddedElements().size());
assertEquals(0, nameMapChange.getRemovedElements().size());
assertEquals(0, nameMapChange.getMutatedElements().size());
assertEquals(0, nameMapChange.getElementChanges().size());
assertEquals(0, nameMapChange.getAddedKeys().size());
assertEquals(0, nameMapChange.getRemovedKeys().size());
assertEquals(0, nameMapChange.getMutatedKeys().size());
assertEquals(0, nameMapChange.getKeyChanges().size());
assertEquals(0, nameMapChange.getAddedObjects().size());
assertEquals(0, nameMapChange.getRemovedObjects().size());
assertEquals(0, nameMapChange.getMutatedObjects().size());
assertEquals(0, nameMapChange.getObjectChanges().size());
assertEquals(0, changeModel.getDirtyChanges().size());
} else {
assertTrue(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
assertTrue(nameMapChange.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameMapChange.getKind());
assertEquals(0, nameMapChange.getAddedElements().size());
assertEquals(0, nameMapChange.getRemovedElements().size());
assertEquals(1, nameMapChange.getMutatedElements().size());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameMapChange.getMutatedElements().get(0).getKind());
assertEquals(new NameObject("doc1", "doc1"), nameMapChange.getMutatedElements().get(0).getCurrentState());
assertEquals(0, nameMapChange.getAddedKeys().size());
assertEquals(0, nameMapChange.getRemovedKeys().size());
assertEquals(0, nameMapChange.getMutatedKeys().size());
assertEquals(0, nameMapChange.getAddedObjects().size());
assertEquals(0, nameMapChange.getRemovedObjects().size());
assertEquals(1, nameMapChange.getMutatedObjects().size());
assertTrue(nameMapChange.getMutatedObjects().contains(nameMapChange.getMutatedElements().get(0)));
assertEquals(Arrays.asList(nameMapChange), changeModel.getDirtyChanges());
}
}
}
Aggregations