Search in sources :

Example 26 with NameObject

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;
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 27 with NameObject

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());
        }
    }
}
Also used : MapChangeModel(com.blazebit.persistence.view.change.MapChangeModel) UpdatableDocumentEmbeddableWithMapsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 28 with NameObject

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());
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) UpdatableDocumentEmbeddableView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView)

Example 29 with NameObject

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);
    }
}
Also used : SimpleNameObjectView(com.blazebit.persistence.view.testsuite.update.embeddable.nested.model.SimpleNameObjectView) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with NameObject

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());
        }
    }
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) PluralChangeModel(com.blazebit.persistence.view.change.PluralChangeModel)

Aggregations

NameObject (com.blazebit.persistence.testsuite.entity.NameObject)30 Test (org.junit.Test)7 Document (com.blazebit.persistence.testsuite.entity.Document)6 NameObjectContainer (com.blazebit.persistence.testsuite.entity.NameObjectContainer)5 Person (com.blazebit.persistence.testsuite.entity.Person)5 Category (org.junit.experimental.categories.Category)5 UpdatableDocumentEmbeddableView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView)4 Tuple (javax.persistence.Tuple)4 Date (java.util.Date)3 Map (java.util.Map)3 Version (com.blazebit.persistence.testsuite.entity.Version)2 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)2 MapChangeModel (com.blazebit.persistence.view.change.MapChangeModel)2 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)2 AbstractEntityViewUpdateEmbeddableTest (com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableTest)2 UpdatableDocumentEmbeddableWithCollectionsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView)2 UpdatableDocumentEmbeddableWithMapsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView)2 UpdatableNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)2 ReadonlyNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.ReadonlyNameObjectView)2 HashMap (java.util.HashMap)2