diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-10-19 15:32:57 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-10-20 14:20:55 +0000 |
commit | 85fd3da7efba703d473c8120c1680b65be28f565 (patch) | |
tree | 706a6cf95318412ba0e8d28f928daccb7357c6e8 /infra/data-impl/src/test/java | |
parent | db9ce3d32c794b0cfa78fc5b3c8d5efcd0bd4532 (diff) |
HONEYCOMB-261 Make ModificationDiff schema aware
to check presence statement on containers for starters
+ update all checks in ModificationDiff to be performed on schema
instead of data
Change-Id: I6ec1a0f9e1ca821ef9f6835072d075dd0994bdb6
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/data-impl/src/test/java')
-rw-r--r-- | infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java | 2 | ||||
-rw-r--r-- | infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java | 28 |
2 files changed, 26 insertions, 4 deletions
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java index dc962662d..0a7c85b3b 100644 --- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java +++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java @@ -92,7 +92,7 @@ public class ModifiableDataTreeDelegatorTest { final Map.Entry<InstanceIdentifier<?>, DataObject> parsed = new AbstractMap.SimpleEntry<>(DEFAULT_ID, DEFAULT_DATA_OBJECT); when(serializer.fromNormalizedNode(any(YangInstanceIdentifier.class), any(NormalizedNode.class))).thenReturn(parsed); - configDataTree = new ModifiableDataTreeDelegator(serializer, dataTree, writer, contextBroker); + configDataTree = new ModifiableDataTreeDelegator(serializer, dataTree, ModificationDiffTest.getSchemaCtx(), writer, contextBroker); } @Test diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java index cc00f2dc6..029457331 100644 --- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java +++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java @@ -41,6 +41,8 @@ public class ModificationDiffTest { static final QName TEXT_LEAF_QNAME = QName.create(TOP_CONTAINER_QNAME, "text"); static final QName NESTED_LIST_QNAME = QName.create(TOP_CONTAINER_QNAME, "nested-list"); static final QName DEEP_LIST_QNAME = QName.create(TOP_CONTAINER_QNAME, "deep-list"); + static final QName EMPTY_QNAME = QName.create(TOP_CONTAINER_QNAME, "empty"); + static final QName IN_EMPTY_QNAME = QName.create(TOP_CONTAINER_QNAME, "in-empty"); static final QName WITH_CHOICE_CONTAINER_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:test:diff", "2015-01-05", "with-choice"); @@ -133,6 +135,26 @@ public class ModificationDiffTest { assertThat(modificationDiff.getUpdates().size(), is(0)); } + @Test + public void testWriteNonPresenceEmptyNestedContainer() throws Exception { + final TipProducingDataTree dataTree = getDataTree(); + final DataTreeModification dataTreeModification = getModification(dataTree); + final NormalizedNode<?, ?> topContainer = Builders.containerBuilder() + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME)) + .withChild(ImmutableNodes.containerNode(EMPTY_QNAME)) + .withChild(ImmutableNodes.leafNode(STRING_LEAF_QNAME, "1")) + .build(); + dataTreeModification.write(TOP_CONTAINER_ID, topContainer); + final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification); + + final ModificationDiff modificationDiff = getModificationDiff(prepare); + dataTree.commit(prepare); + + // Only the STRING_LEAF_QNAME is considered a modification, the EMPTY_QNAME container is ignored since it is + // not a presence container + assertThat(modificationDiff.getUpdates().size(), is(1)); + } + private DataTreeCandidateTip prepareModification(final TipProducingDataTree dataTree, final DataTreeModification dataTreeModification) throws DataValidationFailedException { @@ -159,8 +181,8 @@ public class ModificationDiffTest { assertUpdate(updates.values().iterator().next(), TOP_CONTAINER_ID, topContainer, topContainerAfter); } - private ModificationDiff getModificationDiff(final DataTreeCandidateTip prepare) { - return ModificationDiff.recursivelyFromCandidateRoot(prepare.getRootNode()); + private ModificationDiff getModificationDiff(final DataTreeCandidateTip prepare) throws ReactorException { + return ModificationDiff.recursivelyFromCandidateRoot(prepare.getRootNode(), getSchemaCtx()); } @Test @@ -447,7 +469,7 @@ public class ModificationDiffTest { .build(); } - private static SchemaContext getSchemaCtx() throws ReactorException { + static SchemaContext getSchemaCtx() throws ReactorException { final CrossSourceStatementReactor.BuildAction buildAction = YangInferencePipeline.RFC6020_REACTOR.newBuild(); buildAction.addSource(new YangStatementSourceImpl(ModificationDiffTest.class.getResourceAsStream("/test-diff.yang"))); return buildAction.buildEffective(); |