summaryrefslogtreecommitdiffstats
path: root/infra/data-impl/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'infra/data-impl/src/test')
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java2
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java28
-rw-r--r--infra/data-impl/src/test/resources/test-diff.yang6
3 files changed, 32 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();
diff --git a/infra/data-impl/src/test/resources/test-diff.yang b/infra/data-impl/src/test/resources/test-diff.yang
index 6c27ddc17..57708589d 100644
--- a/infra/data-impl/src/test/resources/test-diff.yang
+++ b/infra/data-impl/src/test/resources/test-diff.yang
@@ -16,6 +16,12 @@ module test-diff {
type string;
}
+ container empty {
+ leaf in-empty {
+ type string;
+ }
+ }
+
list nested-list {
key "name";