use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class AbstractEntityViewUpdateEmbeddableTest method updateMutable.
public T updateMutable() {
// Given
final T docView = getDoc1View();
clearQueries();
// When
docView.setNameObject(new NameObject("newPrimaryName", "newSecondaryName"));
return docView;
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableMapsTest method assertChangesUpdateAndFlush.
protected void assertChangesUpdateAndFlush(UpdatableDocumentEmbeddableWithMapsView docView) {
if (!isFullMode()) {
SingularChangeModel<UpdatableDocumentEmbeddableWithMapsView> changeModel = evm.getChangeModel(docView);
assertTrue(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
MapChangeModel<?, ?> nameMapChange = (MapChangeModel<Object, Object>) changeModel.<Map<Object, Object>>get("nameMap");
assertTrue(nameMapChange.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameMapChange.getKind());
if (registerType) {
assertEquals(1, nameMapChange.getAddedElements().size());
assertEquals(0, nameMapChange.getRemovedElements().size());
assertEquals(0, nameMapChange.getMutatedElements().size());
assertEquals(1, nameMapChange.getElementChanges().size());
assertEquals(ChangeModel.ChangeKind.UPDATED, nameMapChange.getAddedElements().get(0).getKind());
assertNull(nameMapChange.getAddedElements().get(0).getInitialState());
assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), nameMapChange.getAddedElements().get(0).getCurrentState());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedElements().get(0)), nameMapChange.getElementChanges());
assertEquals(1, nameMapChange.getAddedKeys().size());
assertEquals(0, nameMapChange.getRemovedKeys().size());
assertEquals(0, nameMapChange.getMutatedKeys().size());
assertEquals(1, nameMapChange.getKeyChanges().size());
assertEquals(ChangeModel.ChangeKind.UPDATED, nameMapChange.getAddedKeys().get(0).getKind());
assertEquals("newPrimaryName", nameMapChange.getAddedKeys().get(0).getCurrentState());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedKeys().get(0)), nameMapChange.getKeyChanges());
assertEquals(2, nameMapChange.getAddedObjects().size());
assertEquals(0, nameMapChange.getRemovedObjects().size());
assertEquals(0, nameMapChange.getMutatedObjects().size());
assertEquals(2, nameMapChange.getObjectChanges().size());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedKeys().get(0), nameMapChange.getAddedElements().get(0)), nameMapChange.getAddedObjects());
assertEquals(0, nameMapChange.getMutatedObjects().size());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedKeys().get(0), nameMapChange.getAddedElements().get(0)), nameMapChange.getObjectChanges());
} else {
assertEquals(1, nameMapChange.getAddedElements().size());
assertEquals(0, nameMapChange.getRemovedElements().size());
assertEquals(1, nameMapChange.getMutatedElements().size());
assertEquals(2, nameMapChange.getElementChanges().size());
assertEquals(ChangeModel.ChangeKind.UPDATED, nameMapChange.getAddedElements().get(0).getKind());
assertNull(nameMapChange.getAddedElements().get(0).getInitialState());
assertEquals(new NameObject("newPrimaryName", "newSecondaryName"), nameMapChange.getAddedElements().get(0).getCurrentState());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameMapChange.getMutatedElements().get(0).getKind());
assertEquals(new NameObject("doc1", "doc1"), nameMapChange.getMutatedElements().get(0).getCurrentState());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedElements().get(0), nameMapChange.getMutatedElements().get(0)), nameMapChange.getElementChanges());
assertEquals(1, nameMapChange.getAddedKeys().size());
assertEquals(0, nameMapChange.getRemovedKeys().size());
assertEquals(0, nameMapChange.getMutatedKeys().size());
assertEquals(1, nameMapChange.getKeyChanges().size());
assertEquals(ChangeModel.ChangeKind.UPDATED, nameMapChange.getAddedKeys().get(0).getKind());
assertEquals("newPrimaryName", nameMapChange.getAddedKeys().get(0).getCurrentState());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedKeys().get(0)), nameMapChange.getKeyChanges());
assertEquals(2, nameMapChange.getAddedObjects().size());
assertEquals(0, nameMapChange.getRemovedObjects().size());
assertEquals(1, nameMapChange.getMutatedObjects().size());
assertEquals(3, nameMapChange.getObjectChanges().size());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedKeys().get(0), nameMapChange.getAddedElements().get(0)), nameMapChange.getAddedObjects());
assertUnorderedEquals(Arrays.asList(nameMapChange.getMutatedElements().get(0)), nameMapChange.getMutatedObjects());
assertUnorderedEquals(Arrays.asList(nameMapChange.getAddedKeys().get(0), nameMapChange.getAddedElements().get(0), nameMapChange.getMutatedElements().get(0)), nameMapChange.getObjectChanges());
}
assertUnorderedEquals(Arrays.asList(nameMapChange), changeModel.getDirtyChanges());
}
update(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(2, nameMapChange.getMutatedElements().size());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameMapChange.getMutatedElements().get(0).getKind());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameMapChange.getMutatedElements().get(1).getKind());
assertEquals(2, nameMapChange.getElementChanges().size());
assertUnorderedEquals(Arrays.asList(nameMapChange.getMutatedElements().get(0), nameMapChange.getMutatedElements().get(1)), nameMapChange.getElementChanges());
assertUnorderedEquals(Arrays.asList(new NameObject("doc1", "doc1"), new NameObject("newPrimaryName", "newSecondaryName")), Arrays.asList(nameMapChange.getMutatedElements().get(0).getCurrentState(), nameMapChange.getMutatedElements().get(1).getCurrentState()));
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(2, nameMapChange.getMutatedObjects().size());
assertEquals(2, nameMapChange.getObjectChanges().size());
assertUnorderedEquals(Arrays.asList(nameMapChange.getMutatedObjects().get(0), nameMapChange.getMutatedObjects().get(1)), nameMapChange.getObjectChanges());
assertUnorderedEquals(Arrays.asList(nameMapChange), changeModel.getDirtyChanges());
}
}
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableTest method assertEmptySimpleChangeModel.
protected void assertEmptySimpleChangeModel(UpdatableDocumentEmbeddableView docView) {
if (!isFullMode()) {
SingularChangeModel<UpdatableDocumentEmbeddableView> changeModel = evm.getChangeModel(docView);
ChangeModel<?> nameChange = changeModel.get("nameObject");
if (registerType) {
assertFalse(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, changeModel.getKind());
assertFalse(nameChange.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, nameChange.getKind());
assertTrue(changeModel.getDirtyChanges().isEmpty());
} else {
assertTrue(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
assertTrue(nameChange.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, nameChange.getKind());
assertEquals(Arrays.asList(nameChange), changeModel.getDirtyChanges());
}
assertEquals(new NameObject("doc1", null), nameChange.getCurrentState());
}
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableNestedEmbeddableMapsTest method assertNameObjectSubviewEquals.
private void assertNameObjectSubviewEquals(Map<String, NameObject> entities, Map<String, SimpleNameObjectView> views) {
assertEquals(entities.size(), views.size());
Map<String, SimpleNameObjectView> unmatched = new HashMap<>(views);
for (Map.Entry<String, NameObject> entry : entities.entrySet()) {
NameObject value = entry.getValue();
SimpleNameObjectView view = unmatched.remove(entry.getKey());
if (view == null || !Objects.equals(value.getPrimaryName(), view.getPrimaryName()) || !Objects.equals(value.getSecondaryName(), view.getSecondaryName()) || (value.getIntIdEntity() == null) != (view.getIntIdEntity() == null) && !Objects.equals(value.getIntIdEntity().getId(), view.getIntIdEntity().getId())) {
Assert.fail("Unmatched name object: " + value);
}
}
if (!unmatched.isEmpty()) {
Assert.fail("Unmatched views: " + unmatched);
}
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableCollectionsTest method assertMutableChangeModel.
private void assertMutableChangeModel(UpdatableDocumentEmbeddableWithCollectionsView docView) {
if (!isFullMode()) {
SingularChangeModel<UpdatableDocumentEmbeddableWithCollectionsView> changeModel = evm.getChangeModel(docView);
PluralChangeModel<?, ?> namesChange = (PluralChangeModel<?, ?>) changeModel.get("names");
if (registerType) {
assertFalse(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, changeModel.getKind());
assertFalse(namesChange.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, namesChange.getKind());
assertEquals(0, namesChange.getAddedElements().size());
assertEquals(0, namesChange.getRemovedElements().size());
assertEquals(0, namesChange.getMutatedElements().size());
assertEquals(0, namesChange.getElementChanges().size());
assertEquals(0, changeModel.getDirtyChanges().size());
} else {
assertTrue(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
assertTrue(namesChange.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, namesChange.getKind());
assertEquals(1, namesChange.getAddedElements().size());
assertEquals(1, namesChange.getRemovedElements().size());
assertEquals(0, namesChange.getMutatedElements().size());
assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(0).getKind());
assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getRemovedElements().get(0).getKind());
assertUnorderedEquals(Arrays.asList(namesChange.getAddedElements().get(0), namesChange.getRemovedElements().get(0)), namesChange.getElementChanges());
assertEquals(new NameObject("doc1", "doc1"), namesChange.getAddedElements().get(0).getCurrentState());
assertEquals(new NameObject("doc1", "doc1"), namesChange.getRemovedElements().get(0).getInitialState());
assertEquals(Arrays.asList(namesChange), changeModel.getDirtyChanges());
}
}
}
Aggregations