X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDataTreeCandidatePayloadTest.java;h=c7e20bb9446068a6a86b18b66a568f7f1397e6e3;hp=781c3dba71f7dbfdf5078e9ac25dac2a373292ab;hb=7204c455a1636a7fc89bcd28fe9e9000eaa81b3b;hpb=412db94945c5db5d2da918f5e23bd3abcecc4d10 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayloadTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayloadTest.java index 781c3dba71..c7e20bb944 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayloadTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayloadTest.java @@ -11,25 +11,34 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; + import java.io.IOException; import java.util.Collection; import org.apache.commons.lang3.SerializationUtils; import org.junit.Before; import org.junit.Test; +import org.opendaylight.controller.md.cluster.datastore.model.TestModel; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; +import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; +import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; -import org.opendaylight.controller.md.cluster.datastore.model.TestModel; +@Deprecated public class DataTreeCandidatePayloadTest { + static final QName LEAF_SET = QName.create(TestModel.TEST_QNAME, "leaf-set"); + private DataTreeCandidate candidate; - private static DataTreeCandidateNode findNode(final Collection nodes, final PathArgument arg) { + private static DataTreeCandidateNode findNode(final Collection nodes, + final PathArgument arg) { for (DataTreeCandidateNode node : nodes) { if (arg.equals(node.getIdentifier())) { return node; @@ -61,36 +70,37 @@ public class DataTreeCandidatePayloadTest { assertEquals("root type", expRoot.getModificationType(), actRoot.getModificationType()); switch (actRoot.getModificationType()) { - case DELETE: - case WRITE: - assertEquals("root data", expRoot.getDataAfter(), actRoot.getDataAfter()); - break; - case SUBTREE_MODIFIED: - assertChildrenEquals(expRoot.getChildNodes(), actRoot.getChildNodes()); - break; - default: - fail("Unexpect root type " + actRoot.getModificationType()); - break; + case DELETE: + case WRITE: + assertEquals("root data", expRoot.getDataAfter(), actRoot.getDataAfter()); + break; + case SUBTREE_MODIFIED: + assertChildrenEquals(expRoot.getChildNodes(), actRoot.getChildNodes()); + break; + default: + fail("Unexpect root type " + actRoot.getModificationType()); + break; } assertCandidateNodeEquals(expected.getRootNode(), actual.getRootNode()); } - private static void assertCandidateNodeEquals(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) { + private static void assertCandidateNodeEquals(final DataTreeCandidateNode expected, + final DataTreeCandidateNode actual) { assertEquals("child type", expected.getModificationType(), actual.getModificationType()); assertEquals("child identifier", expected.getIdentifier(), actual.getIdentifier()); switch (actual.getModificationType()) { - case DELETE: - case WRITE: - assertEquals("child data", expected.getDataAfter(), actual.getDataAfter()); - break; - case SUBTREE_MODIFIED: - assertChildrenEquals(expected.getChildNodes(), actual.getChildNodes()); - break; - default: - fail("Unexpect root type " + actual.getModificationType()); - break; + case DELETE: + case WRITE: + assertEquals("child data", expected.getDataAfter(), actual.getDataAfter()); + break; + case SUBTREE_MODIFIED: + assertChildrenEquals(expected.getChildNodes(), actual.getChildNodes()); + break; + default: + fail("Unexpect root type " + actual.getModificationType()); + break; } } @@ -98,8 +108,8 @@ public class DataTreeCandidatePayloadTest { public void setUp() { final YangInstanceIdentifier writePath = TestModel.TEST_PATH; final NormalizedNode writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)). - withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build(); + new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) + .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build(); candidate = DataTreeCandidates.fromNormalizedNode(writePath, writeData); } @@ -120,4 +130,63 @@ public class DataTreeCandidatePayloadTest { final DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate); assertCandidateEquals(candidate, SerializationUtils.clone(payload).getCandidate()); } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void testLeafSetEntryNodeCandidate() throws Exception { + YangInstanceIdentifier.NodeWithValue entryPathArg = new YangInstanceIdentifier.NodeWithValue(LEAF_SET, "one"); + YangInstanceIdentifier leafSetEntryPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(LEAF_SET) + .node(entryPathArg).build(); + + NormalizedNode leafSetEntryNode = Builders.leafSetEntryBuilder() + .withNodeIdentifier(entryPathArg).withValue("one").build(); + + candidate = DataTreeCandidates.fromNormalizedNode(leafSetEntryPath, leafSetEntryNode); + DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate); + assertCandidateEquals(candidate, payload.getCandidate()); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void testLeafSetNodeCandidate() throws Exception { + YangInstanceIdentifier.NodeWithValue entryPathArg = new YangInstanceIdentifier.NodeWithValue(LEAF_SET, "one"); + YangInstanceIdentifier leafSetPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(LEAF_SET).build(); + + LeafSetEntryNode leafSetEntryNode = Builders.leafSetEntryBuilder() + .withNodeIdentifier(entryPathArg).withValue("one").build(); + NormalizedNode leafSetNode = Builders.leafSetBuilder().withNodeIdentifier( + new YangInstanceIdentifier.NodeIdentifier(LEAF_SET)).withChild(leafSetEntryNode).build(); + + DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(leafSetPath, leafSetNode); + DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate); + assertCandidateEquals(candidate, payload.getCandidate()); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void testOrderedLeafSetNodeCandidate() throws Exception { + YangInstanceIdentifier.NodeWithValue entryPathArg = new YangInstanceIdentifier.NodeWithValue(LEAF_SET, "one"); + YangInstanceIdentifier leafSetPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(LEAF_SET).build(); + + LeafSetEntryNode leafSetEntryNode = Builders.leafSetEntryBuilder() + .withNodeIdentifier(entryPathArg).withValue("one").build(); + NormalizedNode leafSetNode = Builders.orderedLeafSetBuilder().withNodeIdentifier( + new YangInstanceIdentifier.NodeIdentifier(LEAF_SET)).withChild(leafSetEntryNode).build(); + + candidate = DataTreeCandidates.fromNormalizedNode(leafSetPath, leafSetNode); + DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate); + assertCandidateEquals(candidate, payload.getCandidate()); + } + + @Test + public void testLeafNodeCandidate() throws Exception { + YangInstanceIdentifier leafPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH) + .node(TestModel.DESC_QNAME).build(); + LeafNode leafNode = Builders.leafBuilder().withNodeIdentifier( + new YangInstanceIdentifier.NodeIdentifier(TestModel.DESC_QNAME)).withValue("test").build(); + + candidate = DataTreeCandidates.fromNormalizedNode(leafPath, leafNode); + DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate); + assertCandidateEquals(candidate, payload.getCandidate()); + } }