YAB and YOB defect fix
Change-Id: Ifed54236cfa83b4754383467818581bec59191d9
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobAugmentTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobAugmentTest.java
new file mode 100644
index 0000000..da75702
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobAugmentTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.urn.ip.topo.rev20140101.ymsiptopology.node.AugmentedTopoNode;
+import org.onosproject.yang.gen.v1.urn.ip.topo.rev20140101.ymsiptopology.node.DefaultAugmentedTopoNode;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.YmsTopologyOpParam;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.DefaultNode;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.yms.app.yob.YobTestUtils.NODE;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROUTER_ID;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROUTER_IP;
+import static org.onosproject.yms.app.yob.YobTestUtils.STR_LEAF_VALUE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TOPOLOGY;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the non
+ * schema augmented nodes.
+ */
+public class YobAugmentTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void augmentedLeaf() throws IOException {
+
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(ROUTER_ID, "urn:ip:topo", STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull("Fail to create augmented YANG object", yangObject);
+
+ assertEquals("invalid augmented node created", YmsTopologyOpParam.class,
+ yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("failed to build augmented node", topology.node());
+ assertEquals("Single node entry is expected", 1, topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ DefaultNode node = (DefaultNode) topology.node().get(0);
+ assertNotNull("Augmented info is missing", node.yangAugmentedInfo(
+ AugmentedTopoNode.class));
+ assertEquals("Augmented class is incorrect",
+ DefaultAugmentedTopoNode.class,
+ node.yangAugmentedInfo(AugmentedTopoNode.class)
+ .getClass());
+
+ DefaultAugmentedTopoNode augmentedNode = (DefaultAugmentedTopoNode)
+ node.yangAugmentedInfo(AugmentedTopoNode.class);
+ assertThat("Augmented leaf value is incorrect",
+ augmentedNode.routerId(), is(STR_LEAF_VALUE));
+ }
+
+ @Test
+ public void augmentedLeaves() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(ROUTER_ID, "urn:ip:topo", STR_LEAF_VALUE);
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addLeaf(ROUTER_IP, "urn:ip:topo", STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull("Fail to create augmented YANG object", yangObject);
+
+ assertEquals("invalid augmented node created",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("failed to build augmented node", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ DefaultNode node = (DefaultNode) topology.node().get(0);
+ assertNotNull("Augmented info is missing", node.yangAugmentedInfo(
+ AugmentedTopoNode.class));
+ assertEquals("Augmented class is incorrect",
+ DefaultAugmentedTopoNode.class,
+ node.yangAugmentedInfo(AugmentedTopoNode.class)
+ .getClass());
+
+ DefaultAugmentedTopoNode augmentedNode = (DefaultAugmentedTopoNode)
+ node.yangAugmentedInfo(AugmentedTopoNode.class);
+ assertThat("Augmented router id is incorrect",
+ augmentedNode.routerId(), is(STR_LEAF_VALUE));
+ assertThat("Augmented router ip is incorrect",
+ augmentedNode.routerIp(), is(STR_LEAF_VALUE));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBinaryTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBinaryTest.java
new file mode 100644
index 0000000..a749874
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBinaryTest.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.BinarytestOpParam;
+import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.binarytest.cont1.AugmentedCont1;
+import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.binarytest.food.snack.Sportsarena;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the binary.
+ */
+public class YobBinaryTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testBinaryInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("binaryList", null);
+ ydtBuilder.addLeaf("binary", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.binaryList().get(0).binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addLeaf("name", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.name().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInGrouping() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("cont1", "ydt.binarytest");
+ ydtBuilder.addLeaf("surname", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.cont1().surname();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("cont1", "ydt.binarytest");
+ ydtBuilder.addLeaf("lastname", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ AugmentedCont1 augmentedCont1 = (AugmentedCont1) binarytestOpParam.cont1()
+ .yangAugmentedInfo(AugmentedCont1.class);
+ byte[] binaryValue = augmentedCont1.lastname();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInCase() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("food", "ydt.binarytest");
+ ydtBuilder.addLeaf("pretzel", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+ Sportsarena sportsArena = ((Sportsarena) binarytestOpParam.food()
+ .snack());
+ byte[] binaryValue = sportsArena.pretzel();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInUnion() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addLeaf("middlename", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.middlename().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java
new file mode 100644
index 0000000..41ca592
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.bit.rev20160524.BitOpParam;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YDT based on the bits.
+ */
+public class YobBitTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testBitsInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("bit", "ydt.bit");
+ ydtBuilder.addChild("bitList", null);
+ ydtBuilder.addLeaf("bit", null, "disable-nagle");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addChild("bitList", null);
+ ydtBuilder.addLeaf("bit", null, "auto-sense-speed");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addChild("bitList", null);
+ ydtBuilder.addLeaf("bit", null, "ten-Mb-only");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BitOpParam bitOpParam = ((BitOpParam) yangObject);
+
+ assertThat(bitOpParam.bitList().get(0).bit().get(0), is(true));
+ assertThat(bitOpParam.bitList().get(0).bit().get(1), is(false));
+ assertThat(bitOpParam.bitList().get(1).bit().get(0), is(false));
+ assertThat(bitOpParam.bitList().get(1).bit().get(1), is(true));
+ assertThat(bitOpParam.bitList().get(2).bit().get(0), is(false));
+ assertThat(bitOpParam.bitList().get(2).bit().get(1), is(false));
+ assertThat(bitOpParam.bitList().get(2).bit().get(2), is(true));
+ assertThat(bitOpParam.bitList().get(2).bit().get(2), is(true));
+ }
+
+ @Test
+ public void testBitsInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("bit", "ydt.bit");
+ ydtBuilder.addLeaf("name", null, "bit3");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BitOpParam bitOpParam = ((BitOpParam) yangObject);
+
+ assertThat(bitOpParam.name().bits().get(0), is(false));
+ assertThat(bitOpParam.name().bits().get(3), is(true));
+ }
+
+ @Test
+ public void testBitsQuery() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, YmsOperationType.QUERY_REQUEST,
+ utils.schemaRegistry(), true);
+ ydtBuilder.addChild("bit", "ydt.bit");
+ ydtBuilder.addChild("name", "ydt.bit");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BitOpParam bitOpParam = ((BitOpParam) yangObject);
+ assertThat(bitOpParam.selectLeafFlags().get(1), is(true));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java
new file mode 100644
index 0000000..456a892
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class YobBooleanTest {
+
+ private static final String BOOLEAN_LIST = "booleanList";
+ private static final String AUTO_PREFIX_BOOLEAN = "yangAutoPrefixBoolean";
+
+ /*
+ BOOLEAN
+ Positive scenario
+ input with in true and false
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.booleanYdt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+
+ Field field = yangObject.getClass().getDeclaredField(BOOLEAN_LIST);
+ field.setAccessible(true);
+ List booleanList = (List) field.get(yangObject);
+ Field invalidInterval = booleanList.get(0).getClass()
+ .getDeclaredField(AUTO_PREFIX_BOOLEAN);
+ invalidInterval.setAccessible(true);
+ assertTrue((boolean) invalidInterval.get(booleanList.get(0)));
+ assertFalse((boolean) invalidInterval.get(booleanList.get(1)));
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobChoiceTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobChoiceTest.java
new file mode 100644
index 0000000..03c2421
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobChoiceTest.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.YmsTopologyOpParam;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.DefaultNode;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.Node;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.Case1a;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.Case1b;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.DefaultCase1a;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.DefaultCase1b;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.case1b.choice1b.Case1Bi;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.case1b.choice1b.DefaultCase1Bi;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1A1;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1A2;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1BIA;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1BIB;
+import static org.onosproject.yms.app.yob.YobTestUtils.NODE;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.STR_LEAF_VALUE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TOPOLOGY;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the non
+ * schema choice and case nodes.
+ */
+public class YobChoiceTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void caseInChoice() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1A1, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("choice1 is not set in node", node.choice1());
+ assertEquals("choice 1 type is not ", DefaultCase1a.class,
+ node.choice1().getClass());
+
+ Case1a case1a = (Case1a) node.choice1();
+ assertNotNull("leaf1a1 is not set in case", case1a.leaf1A1());
+ assertEquals("leaf1a1 type is not correct", String.class,
+ case1a.leaf1A1().getClass());
+ assertEquals("leaf1a1 value is not correct", STR_LEAF_VALUE,
+ case1a.leaf1A1());
+
+ }
+
+ @Test
+ public void caseWithMultiAttribute() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1A1, null, STR_LEAF_VALUE);
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addLeaf(LEAF_1A2, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("choice1 is not set in node", node.choice1());
+ assertEquals("choice 1 type is not ", DefaultCase1a.class,
+ node.choice1().getClass());
+
+ Case1a case1a = (Case1a) node.choice1();
+ assertNotNull("leaf1a1 is not set in case", case1a.leaf1A1());
+ assertEquals("leaf1a1 type is not correct", String.class,
+ case1a.leaf1A1().getClass());
+ assertEquals("leaf1a1 value is not correct", STR_LEAF_VALUE,
+ case1a.leaf1A1());
+
+ assertNotNull("leaf1a2 is not set in case", case1a.leaf1A2());
+ assertEquals("leaf1a2 type is not correct", String.class,
+ case1a.leaf1A2().getClass());
+ assertEquals("leaf1a1 value is not correct", STR_LEAF_VALUE,
+ case1a.leaf1A1());
+
+ }
+
+ @Test
+ public void recursiveChoice() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1BIA, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("Choice 1 is not set in Node", node.choice1());
+ assertEquals("Choice 1 is not of type DefaultCase1b",
+ DefaultCase1b.class, node.choice1().getClass());
+
+ Case1b case1b = (Case1b) node.choice1();
+ assertNotNull("Case1b does not have child choice1b ",
+ case1b.choice1b());
+ assertEquals("choice1b is not of type DefaultCase1Bi",
+ DefaultCase1Bi.class, case1b.choice1b().getClass());
+
+ Case1Bi case1Bi = (Case1Bi) case1b.choice1b();
+ assertNotNull("leaf1bia is not set", case1Bi.leaf1Bia());
+ assertEquals("leaf1bia type is not string", String.class,
+ case1Bi.leaf1Bia().getClass());
+ assertEquals("leaf1bia value is wrong", STR_LEAF_VALUE,
+ case1Bi.leaf1Bia());
+ }
+
+ @Test
+ public void recursiveChoiceWithMultipleAttribute() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1BIA, null, STR_LEAF_VALUE);
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addLeaf(LEAF_1BIB, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("Choice 1 is not set in Node", node.choice1());
+ assertEquals("Choice 1 is not of type DefaultCase1b",
+ DefaultCase1b.class,
+ node.choice1().getClass());
+
+ Case1b case1b = (Case1b) node.choice1();
+ assertNotNull("Case1b does not have child choice1b ",
+ case1b.choice1b());
+ assertEquals("choice1b is not of type DefaultCase1Bi",
+ DefaultCase1Bi.class,
+ case1b.choice1b().getClass());
+
+ Case1Bi case1Bi = (Case1Bi) case1b.choice1b();
+ assertNotNull("leaf1bia is not set", case1Bi.leaf1Bia());
+ assertEquals("leaf1bia type is not string", String.class,
+ case1Bi.leaf1Bia().getClass());
+ assertEquals("leaf1bia value is wrong", STR_LEAF_VALUE,
+ case1Bi.leaf1Bia());
+
+ assertNotNull("leaf1bib is not set", case1Bi.leaf1Bib());
+ assertEquals("leaf1bia type is not string", String.class,
+ case1Bi.leaf1Bib().getClass());
+ assertEquals("leaf1bia value is wrong", STR_LEAF_VALUE,
+ case1Bi.leaf1Bib());
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java
new file mode 100644
index 0000000..dbc27f1
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobDecimal64Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for decimal64 with fraction 2
+ i. min value
+ ii. max value
+
+ input at boundary for decimal64 with minimum fraction
+ i. min value
+ ii. mid value
+ iii. max value
+
+ input at boundary for decimal64 with maximum fraction
+ i. min value
+ ii. mid value
+ iii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ input with multi interval range
+ if range is 10..40 | 50..100 for decimal64
+ i.1. input 11
+ i.2. input 10
+ i.3. input 40
+ i.4. input 50
+ i.5. input 55
+ i.6. input 100
+
+ if range is "min .. 3.14 | 10 | 20..max" for decimal64
+ i.1. input min
+ i.2. input 2.505
+ i.3. input 3.14
+ i.4. input 10
+ i.5. input 20
+ i.6. input 92233720368547757
+ i.7. input 92233720368547758.07
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.decimal64Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-92233720368547758.08", negInt
+ .get(yangObject).toString());
+ Field negIntWithMaxFraction = yangObject.getClass()
+ .getDeclaredField("negIntWithMaxFraction");
+ negIntWithMaxFraction.setAccessible(true);
+ assertEquals("-9.223372036854775808", negIntWithMaxFraction
+ .get(yangObject).toString());
+ Field negIntWithMinFraction = yangObject.getClass()
+ .getDeclaredField("negIntWithMinFraction");
+ negIntWithMinFraction.setAccessible(true);
+ assertEquals("-922337203685477580.8", negIntWithMinFraction
+ .get(yangObject).toString());
+ Field posInt = yangObject.getClass()
+ .getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("92233720368547758.07", posInt
+ .get(yangObject).toString());
+ Field posIntWithMaxFraction = yangObject
+ .getClass().getDeclaredField("posIntWithMaxFraction");
+ posIntWithMaxFraction.setAccessible(true);
+ assertEquals("9.223372036854775807", posIntWithMaxFraction
+ .get(yangObject).toString());
+ Field posIntWithMinFraction = yangObject.getClass()
+ .getDeclaredField("posIntWithMinFraction");
+ posIntWithMinFraction.setAccessible(true);
+ assertEquals("922337203685477580.7", posIntWithMinFraction
+ .get(yangObject).toString());
+ Field minIntWithRange = yangObject.getClass()
+ .getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange
+ .get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java
new file mode 100644
index 0000000..e919147
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the schema
+ * nodes with empty data type.
+ */
+public class YobEmptyTest {
+
+ /*
+ EMPTY
+ Positive scenario
+ input with in empty.
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.emptyTypeYdt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+
+ try {
+ Field field = yangObject.getClass().getDeclaredField("emptyList");
+ field.setAccessible(true);
+ List booleanList = (List) field.get(yangObject);
+ Field invalidInterval = booleanList.get(0)
+ .getClass().getDeclaredField("empty");
+ invalidInterval.setAccessible(true);
+ assertEquals(true, invalidInterval.get(booleanList.get(0)));
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java
new file mode 100644
index 0000000..40ba5f1
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobEnumTest {
+
+/*
+ ENUM
+
+ Positive scenario
+
+ input with in enum
+ input with "ten"
+ input with "hundred"
+ input with "thousand"
+*/
+
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.enumYdt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field field = yangObject.getClass().getDeclaredField("enumList");
+ field.setAccessible(true);
+ List enumList = (List) field.get(yangObject);
+ assertEquals(false, enumList.isEmpty());
+ Field enumleaf = enumList.get(0)
+ .getClass().getDeclaredField("enumleaf");
+ enumleaf.setAccessible(true);
+ assertEquals("ten", enumleaf
+ .get(enumList.get(0)).toString().toLowerCase());
+ assertEquals("hundred", enumleaf
+ .get(enumList.get(1)).toString().toLowerCase());
+ assertEquals("thousand", enumleaf
+ .get(enumList.get(2)).toString().toLowerCase());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobGroupingUsesTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobGroupingUsesTest.java
new file mode 100644
index 0000000..547bac7
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobGroupingUsesTest.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.YmsIetfNetworkOpParam;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networksstate.Network;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.YmsNetworkTopology;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ymsnetworktopology.networks.network.AugmentedNdNetwork;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ymsnetworktopology.networks.network.DefaultAugmentedNdNetwork;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ymsnetworktopology.networks.network.augmentedndnetwork.Link;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.YmsIetfTeTopology;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.YmsIetfTeTopologyOpParam;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.TeAdminStatus;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.networks.network.link.AugmentedNtLink;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.networks.network.link.DefaultAugmentedNtLink;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.teadminstatus.TeAdminStatusEnum;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.telinkconfig.bundlestacklevel.DefaultBundle;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.telinkconfig.bundlestacklevel.bundle.bundledlinks.BundledLink;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.onosproject.yms.app.yob.YobTestUtils.ADMIN_STATUS;
+import static org.onosproject.yms.app.yob.YobTestUtils.BUNDLED_LINK;
+import static org.onosproject.yms.app.yob.YobTestUtils.BUNDLED_LINKS;
+import static org.onosproject.yms.app.yob.YobTestUtils.CONFIG;
+import static org.onosproject.yms.app.yob.YobTestUtils.IETF_TE_TOPOLOGY;
+import static org.onosproject.yms.app.yob.YobTestUtils.LINK;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORK;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORKS;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORKS_STATE;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORK_REF;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.SEQUENCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.STR_LEAF_VALUE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE_LINK_TEMPLATE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE_NODE_ATTRIBUTES;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE_NODE_EVENT;
+import static org.onosproject.yms.app.yob.YobTestUtils.UP;
+import static org.onosproject.yms.app.yob.YobTestUtils.YMS_IETF_NETWORK;
+import static org.onosproject.yms.app.yob.YobTestUtils.YMS_NETWORK_TOPOLOGY;
+import static org.onosproject.yms.ydt.YdtContextOperationType.CREATE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the grouping
+ * and uses nodes.
+ */
+public class YobGroupingUsesTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testGroupingUsesLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(YMS_IETF_NETWORK, null, CREATE);
+ ydtBuilder.addChild(NETWORKS_STATE, null);
+ ydtBuilder.addChild(NETWORK, null);
+ ydtBuilder.addLeaf(NETWORK_REF, null, STR_LEAF_VALUE);
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfNetworkOpParam ietfNetwork = (YmsIetfNetworkOpParam) yangObject;
+ Network network = ietfNetwork.networksState().network().iterator().next();
+ assertThat(network.networkRef(), is(STR_LEAF_VALUE));
+ }
+
+ @Test
+ public void testGroupingUsesContainer() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(IETF_TE_TOPOLOGY, null, CREATE);
+ ydtBuilder.addChild(TE_NODE_EVENT, null);
+ ydtBuilder.addChild(TE_NODE_ATTRIBUTES, null);
+ ydtBuilder.addLeaf(ADMIN_STATUS, null, UP);
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfTeTopologyOpParam ietfTeTopology = (YmsIetfTeTopologyOpParam)
+ yangObject;
+ TeAdminStatus adminStatus = ietfTeTopology.teNodeEvent()
+ .teNodeAttributes()
+ .adminStatus();
+ assertThat(adminStatus.enumeration(), is(TeAdminStatusEnum.UP));
+ }
+
+ @Test
+ public void testGroupingUsesInterfile() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(YMS_IETF_NETWORK, null, CREATE);
+ ydtBuilder.addChild(NETWORKS, null);
+ ydtBuilder.addChild(NETWORK, null);
+ ydtBuilder.addChild(LINK, YMS_NETWORK_TOPOLOGY);
+ ydtBuilder.addChild(TE, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(CONFIG, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(BUNDLED_LINKS, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(BUNDLED_LINK, IETF_TE_TOPOLOGY);
+ ydtBuilder.addLeaf(SEQUENCE, null, "1");
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfNetworkOpParam ietfNetwork = (YmsIetfNetworkOpParam) yangObject;
+
+ org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang
+ .ietf.network.rev20151208.ymsietfnetwork
+ .networks.Network network = ietfNetwork.networks().network().get(0);
+
+ DefaultAugmentedNdNetwork augmentedNdNetworks = (DefaultAugmentedNdNetwork) network
+ .yangAugmentedInfo(AugmentedNdNetwork.class);
+ assertThat(augmentedNdNetworks.yangAugmentedNdNetworkOpType(),
+ is(YmsNetworkTopology.OnosYangOpType.CREATE));
+
+ Link link = augmentedNdNetworks.link().get(0);
+ DefaultAugmentedNtLink augmentedNtLink = (DefaultAugmentedNtLink) link
+ .yangAugmentedInfo(AugmentedNtLink.class);
+ assertThat(augmentedNtLink.yangAugmentedNtLinkOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+
+ DefaultBundle bundleStackLevel = (DefaultBundle) augmentedNtLink.te()
+ .config().bundleStackLevel();
+ assertThat(bundleStackLevel.yangBundleOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+
+ BundledLink bundledLink = bundleStackLevel.bundledLinks().bundledLink().get(0);
+ assertThat(bundledLink.yangBundledLinkOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+ assertThat(bundledLink.sequence(), is(1L));
+ }
+
+ @Test
+ public void testGroupingUsesAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(YMS_IETF_NETWORK, null, CREATE);
+ ydtBuilder.addChild(NETWORKS, null);
+ ydtBuilder.addChild(NETWORK, null);
+ ydtBuilder.addChild(LINK, YMS_NETWORK_TOPOLOGY);
+ ydtBuilder.addChild(TE, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(CONFIG, IETF_TE_TOPOLOGY);
+ ydtBuilder.addLeaf(TE_LINK_TEMPLATE, null, "1");
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfNetworkOpParam ietfNetwork = (YmsIetfNetworkOpParam) yangObject;
+
+ org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang
+ .ietf.network.rev20151208.ymsietfnetwork
+ .networks.Network network = ietfNetwork.networks().network().get(0);
+
+ DefaultAugmentedNdNetwork augmentedNdNetworks = (DefaultAugmentedNdNetwork) network
+ .yangAugmentedInfo(AugmentedNdNetwork.class);
+ assertThat(augmentedNdNetworks.yangAugmentedNdNetworkOpType(),
+ is(YmsNetworkTopology.OnosYangOpType.CREATE));
+
+ Link link = augmentedNdNetworks.link().get(0);
+ DefaultAugmentedNtLink augmentedNtLink = (DefaultAugmentedNtLink) link
+ .yangAugmentedInfo(AugmentedNtLink.class);
+ assertThat(augmentedNtLink.yangAugmentedNtLinkOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+
+ assertThat(augmentedNtLink.te().config().teLinkTemplate().get(0),
+ is("1"));
+ }
+}
+
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java
new file mode 100644
index 0000000..38aed89
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import static org.junit.Assert.assertNotNull;
+
+public class YobIetfNetworkTest {
+
+ @Test
+ public void ietfNetwork1Test() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.ietfNetwork1Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ //TODO yangObject need to verify
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java
new file mode 100644
index 0000000..7d6dc1c
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobInteger16Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer16Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-32768", negInt.get(yangObject).toString());
+ Field posInt = yangObject.getClass().getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("32767", posInt.get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange.get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("65535", maxUint.get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("minUintWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("10", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java
new file mode 100644
index 0000000..1e73dc7
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobInteger32Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer32Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-2147483648", negInt.get(yangObject).toString());
+ Field posInt = yangObject.getClass().getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("2147483647", posInt.get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange.get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("4294967295", maxUint.get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("minUintWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("10", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java
new file mode 100644
index 0000000..eca6986
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+public class YobInteger64Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer64Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-9223372036854775808", negInt
+ .get(yangObject).toString());
+ Field posIntField = yangObject
+ .getClass().getDeclaredField("posInt");
+ posIntField.setAccessible(true);
+ assertEquals("9223372036854775807", posIntField
+ .get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange.get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("18446744073709551615", maxUint
+ .get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("minUintWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("10", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java
new file mode 100644
index 0000000..d6f75f9
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobInteger8Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ input with multi interval range
+ if range is 10..40 | 50..100 for integer
+ i.1. input 11
+ i.2. input 10
+ i.3. input 40
+ i.4. input 50
+ i.5. input 55
+ i.6. input 100
+
+ if range is 10..40 | 50..100 for unsigned integer
+ i.1. input 11
+ i.2. input 10
+ i.3. input 40
+ i.4. input 50
+ i.5. input 55
+ i.6. input 100
+
+ if range is "min .. 2 | 10 | 20..max" for integer
+ i.1. input -128
+ i.2. input 1
+ i.3. input 2
+ i.4. input 10
+ i.5. input 20
+ i.6. input 100
+ i.7. input 127
+
+ if range is "min .. 2 | 10 | 20..max" for unsigned Integer
+ i.1. input 0
+ i.2. input 1
+ i.3. input 2
+ i.4. input 10
+ i.5. input 20
+ i.6. input 100
+ i.7. input 255
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer8Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-128", negInt.get(yangObject).toString());
+ Field posInt = yangObject.getClass().getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("127", posInt.get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange
+ .get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange
+ .get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("255", maxUint.get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("100", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLeafRefTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLeafRefTest.java
new file mode 100644
index 0000000..c7e5fe3
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLeafRefTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.leafreftest.rev20160524.LeafreftestOpParam;
+import org.onosproject.yang.gen.v1.ydt.leafreftest.rev20160524.leafreftest.cont1.AugmentedCont1;
+import org.onosproject.yang.gen.v1.ydt.leafreftest.rev20160524.leafreftest.food.snack.Sportsarena;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the leaf ref.
+ */
+public class YobLeafRefTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testLeafrefInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("leafrefList", null);
+ ydtBuilder.addLeaf("id", null, "leafref");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafrefTestOpParam = ((LeafreftestOpParam)
+ yangObject);
+ assertThat(leafrefTestOpParam.leafrefList().get(0).id().toString(),
+ is("leafref"));
+ }
+
+ @Test
+ public void testLeafrefInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addLeaf("name", null, "leafref");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafrefTestOpParam = ((LeafreftestOpParam) yangObject);
+ assertThat(leafrefTestOpParam.name().toString(), is("leafref"));
+ }
+
+ @Test
+ public void testLeafrefInGrouping() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("cont1", "ydt.leafreftest");
+ ydtBuilder.addLeaf("surname", null, "leafref");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafreftestOpParam = ((LeafreftestOpParam) yangObject);
+ assertThat(leafreftestOpParam.cont1().surname().toString(),
+ is("leafref"));
+ }
+
+ @Test
+ public void testLeafrefInAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("cont1", "ydt.leafreftest");
+ ydtBuilder.addLeaf("lastname", null, "yang");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafreftestOpParam = ((LeafreftestOpParam) yangObject);
+ AugmentedCont1 augmentedCont1 = (AugmentedCont1) leafreftestOpParam
+ .cont1().yangAugmentedInfo(AugmentedCont1.class);
+ assertThat(augmentedCont1.lastname().toString(), is("yang"));
+ }
+
+ @Test
+ public void testLeafrefInCase() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("food", "ydt.leafreftest");
+ ydtBuilder.addLeaf("pretzel", null, "yang");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafreftestOpParam = ((LeafreftestOpParam)
+ yangObject);
+ Sportsarena sportsArena = ((Sportsarena) leafreftestOpParam.food()
+ .snack());
+ assertThat(sportsArena.pretzel().toString(), is("yang"));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobListTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobListTest.java
new file mode 100644
index 0000000..4f30ca2
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobListTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class YobListTest {
+
+ @Test
+ public void listwithoutcontainerTest() {
+ YangRequestWorkBench defaultYdtBuilder =
+ YdtTestUtils.listWithoutContainerYdt();
+ validateYangObjectList(defaultYdtBuilder);
+ }
+
+ private void validateYangObjectList(
+ YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils.
+ getSchemaRegistry());
+ assertNotNull(yangObject);
+ assertTrue(yangObject.getClass().getSimpleName()
+ .equals("RootlistOpParam"));
+ try {
+
+ Field field =
+ yangObject.getClass().getDeclaredField("listwithcontainer");
+ field.setAccessible(true);
+ List listwithcontainer = (List) field.get(yangObject);
+ assertNull(listwithcontainer);
+ Field field1 = yangObject.getClass()
+ .getDeclaredField("listwithoutcontainer");
+ field1.setAccessible(true);
+ List listwithoutcontainer = (List) field1.get(yangObject);
+ assertEquals(false, listwithoutcontainer.isEmpty());
+ Field invalidinterval = listwithoutcontainer.get(0).getClass()
+ .getDeclaredField("invalidinterval");
+ invalidinterval.setAccessible(true);
+ assertEquals("12", invalidinterval.get(listwithoutcontainer.get(0))
+ .toString());
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void listwithcontainerTest()
+ throws IOException {
+ YangRequestWorkBench defaultYdtBuilder =
+ YdtTestUtils.listWithContainerYdt();
+
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext ydtContext = defaultYdtBuilder.getRootNode();
+
+ YdtContext ydtContext1 = ydtContext.getFirstChild();
+
+ DefaultYobBuilder defaultYobBuilder = new DefaultYobBuilder();
+
+ Object yangObject = defaultYobBuilder.getYangObject(
+ (YdtExtendedContext) ydtContext1, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ assertTrue(yangObject.getClass().getSimpleName()
+ .equals("RootlistOpParam"));
+ try {
+
+ Field field = yangObject.getClass()
+ .getDeclaredField("listwithoutcontainer");
+ field.setAccessible(true);
+ List listwithoutcontainer = (List) field.get(yangObject);
+ assertNull(listwithoutcontainer);
+ Field listwithcontainerField =
+ yangObject.getClass().getDeclaredField("listwithcontainer");
+ listwithcontainerField.setAccessible(true);
+ List listwithcontainer =
+ (List) listwithcontainerField.get(yangObject);
+ Field invalid = listwithcontainer.get(0).getClass()
+ .getDeclaredField("invalid");
+ invalid.setAccessible(true);
+ assertEquals("12",
+ invalid.get(listwithcontainer.get(0)).toString());
+ Field invalidinterval = listwithcontainer.get(0).getClass()
+ .getDeclaredField("invalidinterval");
+ invalidinterval.setAccessible(true);
+ List invalidintervalList =
+ (List) invalidinterval.get(listwithcontainer.get(0));
+ assertEquals("1", invalidintervalList.get(0).toString());
+ assertEquals("2", invalidintervalList.get(1).toString());
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java
new file mode 100644
index 0000000..8d3b5e3
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertEquals;
+
+public class YobLogisticsManagerTest {
+
+ @Test
+ public void logisticsManagerTest() throws IOException {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils
+ .logisticsManagerYdt();
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ while (childCtx != null) {
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ Class<?> aClass = yangObject.getClass();
+ if (aClass.getSimpleName().equals("CustomssupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ Field onosYangNodeOperationType = aClass
+ .getDeclaredField("yangCustomssupervisorOpType");
+ field.setAccessible(true);
+ onosYangNodeOperationType.setAccessible(true);
+ try {
+ assertEquals("abc", field.get(yangObject).toString());
+ assertEquals("MERGE", onosYangNodeOperationType
+ .get(yangObject).toString());
+ } catch (IllegalAccessException e) {
+ Assert.fail();
+ }
+ } catch (NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+
+ if (aClass.getSimpleName().equals(
+ "MerchandisersupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ field.setAccessible(true);
+ try {
+ assertEquals("abc", field.get(yangObject).toString());
+ } catch (IllegalAccessException e) {
+ Assert.fail();
+ }
+ } catch (NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+
+ if (aClass.getSimpleName().equals("WarehousesupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ field.setAccessible(true);
+ try {
+ ArrayList<String> arrayList =
+ (ArrayList<String>) field.get(yangObject);
+ assertEquals("1", arrayList.get(0));
+ assertEquals("2", arrayList.get(1));
+ assertEquals("3", arrayList.get(2));
+ assertEquals("4", arrayList.get(3));
+ assertEquals("5", arrayList.get(4));
+ } catch (IllegalAccessException e) {
+ Assert.fail();
+ }
+ } catch (NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+ childCtx = childCtx.getNextSibling();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobTestUtils.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobTestUtils.java
new file mode 100644
index 0000000..11818d8
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobTestUtils.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yms.app.yob;
+
+import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+
+/**
+ * YOB test Utility.
+ */
+final class YobTestUtils {
+
+ /**
+ * Schema nodes.
+ */
+ static final String ROOT_DATA_RESOURCE = "/restconf/data";
+ static final String TOPOLOGY = "yms-topology";
+ static final String NODE = "node";
+ static final String LEAF_1A1 = "leaf1a1";
+ static final String LEAF_1A2 = "leaf1a2";
+ static final String LEAF_1BIA = "leaf1bia";
+ static final String LEAF_1BIB = "leaf1bib";
+ static final String ROUTER_ID = "router-id";
+ static final String ROUTER_IP = "router-ip";
+ static final String STR_LEAF_VALUE = "leaf value";
+ static final String YMS_IETF_NETWORK = "yms-ietf-network";
+ static final String NETWORKS_STATE = "networks-state";
+ static final String NETWORKS = "networks";
+ static final String NETWORK = "network";
+ static final String NETWORK_REF = "network-ref";
+ static final String IETF_TE_TOPOLOGY = "yms-ietf-te-topology";
+ static final String TE_NODE_EVENT = "te-node-event";
+ static final String TE_NODE_ATTRIBUTES = "te-node-attributes";
+ static final String ADMIN_STATUS = "admin-status";
+ static final String UP = "up";
+ static final String LINK = "link";
+ static final String YMS_NETWORK_TOPOLOGY = "yms-network-topology";
+ static final String TE = "te";
+ static final String CONFIG = "config";
+ static final String BUNDLED_LINKS = "bundled-links";
+ static final String BUNDLED_LINK = "bundled-link";
+ static final String SEQUENCE = "sequence";
+ static final String TE_LINK_TEMPLATE = "te-link-template";
+
+ private YobTestUtils() {
+ TEST_SCHEMA_PROVIDER.processSchemaRegistry(null);
+ }
+
+ private static final TestYangSchemaNodeProvider
+ TEST_SCHEMA_PROVIDER = new TestYangSchemaNodeProvider();
+
+ YangSchemaRegistry schemaRegistry() {
+ return TEST_SCHEMA_PROVIDER.getDefaultYangSchemaRegistry();
+ }
+
+ /**
+ * Returns the YANG object builder factory instance.
+ *
+ * @return YANG object builder factory instance
+ */
+ static YobTestUtils instance() {
+ return LazyHolder.INSTANCE;
+ }
+
+ /*
+ * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the
+ * LazyHolder class is loaded via a call to the instance() method below.
+ */
+ private static class LazyHolder {
+ private static final YobTestUtils INSTANCE = new YobTestUtils();
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobUnionTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobUnionTest.java
new file mode 100644
index 0000000..1829286
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobUnionTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.uniontest.rev20160524.UniontestOpParam;
+import org.onosproject.yang.gen.v1.ydt.uniontest.rev20160524.uniontest.cont1.AugmentedCont1;
+import org.onosproject.yang.gen.v1.ydt.uniontest.rev20160524.uniontest.food.snack.Sportsarena;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the union.
+ */
+public class YobUnionTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testUnionInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("unionList", null);
+ ydtBuilder.addLeaf("id", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam unionTestOpParam = ((UniontestOpParam) yangObject);
+
+ byte[] binaryValue = unionTestOpParam.unionList().get(0).id().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testUnionInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addLeaf("name", null, "bit1");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam unionTestOpParam = ((UniontestOpParam) yangObject);
+ assertThat(unionTestOpParam.name().union().bits().get(1), is(true));
+ }
+
+ @Test
+ public void testUnionInGrouping() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("cont1", "ydt.uniontest");
+ ydtBuilder.addLeaf("surname", null, "yang");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam uniontestOpParam = ((UniontestOpParam) yangObject);
+ assertThat(uniontestOpParam.cont1().surname().string(), is("yang"));
+ }
+
+ @Test
+ public void testUnionInAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("cont1", "ydt.uniontest");
+ ydtBuilder.addLeaf("lastname", null, "bit0");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam uniontestOpParam = ((UniontestOpParam) yangObject);
+
+ AugmentedCont1 augmentedCont1 = (AugmentedCont1) uniontestOpParam
+ .cont1().yangAugmentedInfo(AugmentedCont1.class);
+ assertThat(augmentedCont1.lastname().bits().get(0), is(true));
+ }
+
+ @Test
+ public void testUnionInCase() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("food", "ydt.uniontest");
+ ydtBuilder.addLeaf("pretzel", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam uniontestOpParam = ((UniontestOpParam) yangObject);
+ Sportsarena sportsArena = ((Sportsarena) uniontestOpParam.food()
+ .snack());
+ byte[] binaryValue = sportsArena.pretzel().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+}