YAB and YOB defect fix
Change-Id: Ifed54236cfa83b4754383467818581bec59191d9
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/MockYmsManager.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/MockYmsManager.java
new file mode 100644
index 0000000..22f4fd9
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/MockYmsManager.java
@@ -0,0 +1,124 @@
+/*
+ * 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.yab;
+
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ych.YangCodecHandler;
+import org.onosproject.yms.ych.YangDataTreeCodec;
+import org.onosproject.yms.ych.YangProtocolEncodingFormat;
+import org.onosproject.yms.ydt.YdtBuilder;
+import org.onosproject.yms.ydt.YdtResponse;
+import org.onosproject.yms.ydt.YdtWalker;
+import org.onosproject.yms.ydt.YmsOperationType;
+import org.onosproject.yms.ymsm.YmsService;
+import org.onosproject.yms.ynh.YangNotificationService;
+import org.onosproject.yms.ysr.YangModuleIdentifier;
+import org.onosproject.yms.ysr.YangModuleLibrary;
+
+import java.util.List;
+
+/**
+ * Represents implementation of YANG application management system manager.
+ */
+public class MockYmsManager
+ implements YmsService {
+
+ YangSchemaRegistry schemaRegistry;
+ TestYangSchemaNodeProvider testYangSchemaNodeProvider =
+ new TestYangSchemaNodeProvider();
+
+ @Override
+ public YdtBuilder getYdtBuilder(String logicalRootName,
+ String rootNamespace,
+ YmsOperationType operationType) {
+ testYangSchemaNodeProvider.processSchemaRegistry(new TestManager());
+ schemaRegistry = testYangSchemaNodeProvider.getDefaultYangSchemaRegistry();
+ return new YangRequestWorkBench(logicalRootName, rootNamespace,
+ operationType, schemaRegistry, false);
+ }
+
+ @Override
+ public YdtBuilder getYdtBuilder(String logicalRootName,
+ String rootNamespace,
+ YmsOperationType operationType,
+ Object schemaRegistryForYdt) {
+ return null;
+ }
+
+ @Override
+ public YdtWalker getYdtWalker() {
+ return null;
+ }
+
+ @Override
+ public YdtResponse executeOperation(YdtBuilder operationRequest) {
+ YangApplicationBroker requestBroker =
+ new YangApplicationBroker(schemaRegistry);
+ switch (operationRequest.getYmsOperationType()) {
+ case EDIT_CONFIG_REQUEST:
+ try {
+ return requestBroker.processEdit(operationRequest);
+ } catch (CloneNotSupportedException e) {
+ }
+ break;
+ case QUERY_CONFIG_REQUEST:
+ case QUERY_REQUEST:
+ return requestBroker.processQuery(operationRequest);
+ case RPC_REQUEST:
+ return requestBroker.processOperation(operationRequest);
+ default:
+ }
+ return null;
+ }
+
+ @Override
+ public YangNotificationService getYangNotificationService() {
+ return null;
+ }
+
+ @Override
+ public void registerService(Object appManager, Class<?> yangService,
+ List<String> supportedFeatureList) {
+ }
+
+ @Override
+ public void unRegisterService(Object appManager, Class<?> yangService) {
+
+ }
+
+ @Override
+ public YangModuleLibrary getYangModuleLibrary() {
+ return null;
+ }
+
+ @Override
+ public String getYangFile(YangModuleIdentifier moduleIdentifier) {
+ return null;
+ }
+
+ @Override
+ public void registerDefaultCodec(YangDataTreeCodec defaultCodec,
+ YangProtocolEncodingFormat dataFormat) {
+ }
+
+ @Override
+ public YangCodecHandler getYangCodecHandler() {
+ return null;
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/TestManager.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/TestManager.java
new file mode 100644
index 0000000..c07a18f
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/TestManager.java
@@ -0,0 +1,82 @@
+/*
+ * 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.yab;
+
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.Test;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.TestOpParam;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.TestService;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.Cont1;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.DefaultCont1;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse.DefaultRockTheHouseOutput;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse.RockTheHouseInput;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse.RockTheHouseOutput;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse1.RockTheHouse1Input;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse2.DefaultRockTheHouse2Output;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse2.RockTheHouse2Output;
+
+/**
+ * Implementation of the application management service.
+ */
+public class TestManager implements TestService {
+
+ Test response;
+
+ @Override
+ public Test getTest(TestOpParam test) {
+ Cont1 cont = new DefaultCont1.Cont1Builder().leaf4("4").build();
+ Test response = new TestOpParam.TestBuilder().cont1(cont).build();
+ return response;
+ }
+
+ @Override
+ public void setTest(TestOpParam test) {
+ response = test;
+ }
+
+ @Override
+ public Test getAugmentedTestCont4(TestOpParam test) {
+ Cont1 cont = new DefaultCont1.Cont1Builder().leaf4("4").build();
+ Test response = new TestOpParam.TestBuilder().cont1(cont).build();
+ return response;
+ }
+
+ @Override
+ public void setAugmentedTestCont4(TestOpParam augmentedTestCont4) {
+ response = augmentedTestCont4;
+ }
+
+ @Override
+ public RockTheHouseOutput rockTheHouse(RockTheHouseInput inputVar) {
+ return DefaultRockTheHouseOutput.builder().hello("hello").build();
+ }
+
+
+ @Override
+ public void rockTheHouse1(RockTheHouse1Input inputVar) {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public RockTheHouse2Output rockTheHouse2() {
+ return DefaultRockTheHouse2Output
+ .builder().leaf14("14").build();
+ }
+
+ @Override
+ public void rockTheHouse3() {
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/YangApplicationBrokerTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/YangApplicationBrokerTest.java
new file mode 100644
index 0000000..33a9a56
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/YangApplicationBrokerTest.java
@@ -0,0 +1,1080 @@
+/*
+ * 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.yab;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtAppContext;
+import org.onosproject.yms.app.ydt.YdtAppNodeOperationType;
+import org.onosproject.yms.app.ydt.YdtNode;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE;
+import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
+import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST;
+import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REQUEST;
+import static org.onosproject.yms.ydt.YmsOperationType.RPC_REQUEST;
+
+/**
+ * Unit test case for YANG application broker.
+ */
+public class YangApplicationBrokerTest {
+
+ MockYmsManager ymsManager = new MockYmsManager();
+
+ /**
+ * Returns YANG data tree to check edit operation of container.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForEditOperationWithoutDelete() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("cont2", null, MERGE);
+ defaultYdtBuilder.addChild("cont3", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf1", null, "1");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, MERGE);
+ defaultYdtBuilder.addChild("cont5", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf9", null, "9");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ private YangRequestWorkBench buildYdtForKeyLeavesInDeleteTree() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("list2", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf7", null, "7");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont7", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of container.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForEditOperationWithDelete() {
+ String rootName = "rootNode";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("cont2", null, DELETE);
+ defaultYdtBuilder.addChild("cont3", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf1", null, "1");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ defaultYdtBuilder.addChild("cont5", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf9", null, "9");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check edit operation of list.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForListEditOperationWithoutDelete() {
+ String rootName = "listWithoutDelete";
+ Set<String> valueSet = new LinkedHashSet<>();
+ valueSet.add("10");
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("list1", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf2", null, "2");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf3", null, "3");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf7", null, "7");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaflist8", null, valueSet);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of list.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForListEditOperationWithDelete() {
+ String rootName = "listWithDelete";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("list1", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf2", null, "2");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf3", null, "3");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check query operation of container.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForQueryOperation() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ QUERY_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont1", null);
+ defaultYdtBuilder.addChild("cont2", null);
+ defaultYdtBuilder.addChild("cont3", null);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null);
+ defaultYdtBuilder.addChild("cont5", null);
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check query operation of list.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForListQueryOperation() {
+ String rootName = "listQuery";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ QUERY_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont1", null);
+ defaultYdtBuilder.addChild("list1", null);
+ defaultYdtBuilder.addLeaf("leaf2", null, "2");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of a node.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtWithOneDeleteNode() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of last node.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtWithDeleteNodeAsLastChild() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to with delete operation of all the nodes.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtWithAllDeleteNode() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", DELETE);
+ defaultYdtBuilder.addChild("cont1", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation with only input.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpcWithOnlyInput() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house1", null);
+ defaultYdtBuilder.addChild("input", null);
+ defaultYdtBuilder.addLeaf("leaf13", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation with only output.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpcWithOnlyOutput() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house2", null);
+ defaultYdtBuilder.addChild("output", null);
+ defaultYdtBuilder.addLeaf("leaf14", null, "14");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation with both input and output.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpcWithBothInputOutput() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house", null);
+ defaultYdtBuilder.addChild("input", null);
+ defaultYdtBuilder.addLeaf("zip-code", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("output", null);
+ defaultYdtBuilder.addLeaf("hello", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpc() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house3", null);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check query operation with multiple level of
+ * augment.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForQueryWithMultipleAugment() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ QUERY_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation with multiple level of
+ * augment.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForDeleteWithMultipleAugment() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Checks whether YANG data tree and delete tree is correct.
+ */
+ @Test
+ public void validateDeleteTreeOnlyOneNodeInDeleteList()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForEditOperationWithDelete();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ YdtContext cont1YdtContext;
+ YdtContext cont2YdtContext;
+ YdtContext cont3YdtContext;
+ YdtContext cont4YdtContext;
+ YdtContext deleteTree;
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ cont2YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(cont2YdtContext.getName(), is("cont2"));
+
+ cont3YdtContext = cont2YdtContext.getFirstChild();
+ assertThat(cont3YdtContext.getName(), is("cont3"));
+
+ ydtContext = cont3YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf1"));
+ assertThat(ydtContext.getValue(), is("1"));
+
+ ydtContext = cont2YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ cont4YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(cont4YdtContext.getName(), is("cont4"));
+
+ ydtContext = cont4YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont5"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf9"));
+ assertThat(ydtContext.getValue(), is("9"));
+
+ ydtContext = cont4YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ // verify whether delete ydt tree is correct
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ cont1YdtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ cont2YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(cont2YdtContext.getName(), is("cont2"));
+
+ cont3YdtContext = cont2YdtContext.getFirstChild();
+ assertThat(cont3YdtContext.getName(), is("cont3"));
+
+ ydtContext = cont3YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf1"));
+ assertThat(ydtContext.getValue(), is("1"));
+
+ assertThat(cont2YdtContext.getNextSibling(), nullValue());
+
+ cont4YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(cont4YdtContext.getName(), is("cont4"));
+
+ ydtContext = cont4YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont5"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf9"));
+ assertThat(ydtContext.getValue(), is("9"));
+
+ assertThat(cont4YdtContext.getNextSibling(), nullValue());
+
+ // ydtTree after removing delete nodes
+ ydtContext = appContext.getModuleContext();
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ ydtContext = cont1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ ydtContext = cont1YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+ }
+
+ /**
+ * Checks whether YANG data tree and delete tree is correct.
+ */
+ @Test
+ public void validateListDeleteTree()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListEditOperationWithDelete();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ YdtContext cont1YdtContext;
+ YdtContext list1YdtContext;
+ YdtContext list2YdtContext;
+ YdtContext deleteTree;
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ list1YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(list1YdtContext.getName(), is("list1"));
+
+ ydtContext = list1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf2"));
+ assertThat(ydtContext.getValue(), is("2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf3"));
+ assertThat(ydtContext.getValue(), is("3"));
+
+ ydtContext = list1YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ list2YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(list2YdtContext.getName(), is("list2"));
+
+ ydtContext = list2YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ ydtContext = list2YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ cont1YdtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ list1YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(list1YdtContext.getName(), is("list1"));
+
+ ydtContext = list1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf2"));
+ assertThat(ydtContext.getValue(), is("2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf3"));
+ assertThat(ydtContext.getValue(), is("3"));
+
+ assertThat(list1YdtContext.getNextSibling(), nullValue());
+
+ list2YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(list2YdtContext.getName(), is("list2"));
+
+ ydtContext = list2YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // verify whether ydt tree is correct
+ ydtContext = appContext.getModuleContext();
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ ydtContext = cont1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ ydtContext = cont1YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid edit
+ * request.
+ */
+ @Test
+ public void testExecuteEditOperationWithoutDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForEditOperationWithoutDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid delete
+ * request.
+ */
+ @Test
+ public void testExecuteEditOperationWithDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForEditOperationWithDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid edit
+ * request for list.
+ */
+ @Test
+ public void testExecuteListEditOperationWithoutDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListEditOperationWithoutDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid delete
+ * request for list.
+ */
+ @Test
+ public void testExecuteListEditOperationWithDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListEditOperationWithDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid query
+ * request.
+ */
+ @Test
+ public void testExecuteQueryOperation()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryOperation();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid query
+ * request for list.
+ */
+ @Test
+ public void testExecuteListQueryOperation()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListQueryOperation();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether delete tree is updated correctly.
+ */
+ @Test
+ public void testSiblingsInDeleteTree()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtWithOneDeleteNode();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ assertThat(ydtContext.getPreviousSibling(), nullValue());
+
+ ydtContext = appContext.getModuleContext();
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks last child is updated correctly after delete tree is built.
+ */
+ @Test
+ public void testLastChildInYdtTree()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtWithDeleteNodeAsLastChild();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+ assertThat(YdtAppNodeOperationType.BOTH,
+ is(appContext.getOperationType()));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ ydtContext = deleteTree.getFirstChild().getLastChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ assertThat(ydtContext.getPreviousSibling(), nullValue());
+
+ ydtContext = appContext.getModuleContext();
+
+ assertThat(ydtContext.getLastChild().getName(), is("list2"));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks YDT tree with all delete nodes.
+ */
+ @Test
+ public void testYdtTreeWithAllDeleteNodes()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtWithAllDeleteNode();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ assertThat(YdtAppNodeOperationType.DELETE_ONLY,
+ is(appContext.getOperationType()));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks whether key leaves are also available when there is delete
+ * request for list.
+ */
+ @Test
+ public void testKeyLeavesInDeleteTree() throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForKeyLeavesInDeleteTree();
+
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ assertThat(YdtAppNodeOperationType.BOTH, is(appContext.getOperationType()));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf7"));
+ assertThat(ydtContext.getValue(), is("7"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont7"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext, notNullValue());
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext, notNullValue());
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont7"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ ydtContext = appContext.getModuleContext();
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf7"));
+ assertThat(ydtContext.getValue(), is("7"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks YDT tree and application tree for query request with mutiple
+ * augments.
+ */
+ @Test
+ public void testApptreeForQueryWithMultipleAugment()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryWithMultipleAugment();
+ YdtAppContext appContext = defaultYdtBuilder.getAppRootNode()
+ .getFirstChild();
+ YdtContext ydtNode = appContext.getModuleContext();
+ YangNode yangNode = (YangNode) ((YdtNode) ydtNode).getYangSchemaNode();
+
+ YangApplicationBroker yab = new YangApplicationBroker(defaultYdtBuilder.
+ getYangSchemaRegistry());
+ yab.setAugGenMethodSet(defaultYdtBuilder.getAugGenMethodSet());
+ yab.processAugmentForChildNode(appContext, yangNode);
+
+ assertThat(appContext.getModuleContext().getName(), is("test"));
+
+ appContext = appContext.getFirstChild();
+
+ String augmentName = ((YangAugment) appContext
+ .getAugmentingSchemaNode()).getTargetNode().get(0)
+ .getResolvedNode().getJavaClassNameOrBuiltInType();
+ assertThat(augmentName, is("cont4"));
+
+ assertThat(appContext.getFirstChild(), nullValue());
+ assertThat(appContext.getLastChild(), nullValue());
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid query request
+ * for data resource with multiple augments.
+ */
+ @Test
+ public void testQueryWithMultipleAugment()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryWithMultipleAugment();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether YDT is updated correctly for delete with multiple augment.
+ */
+ @Test
+ public void testYdtForDeleteWithMultipleAugment()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForDeleteWithMultipleAugment();
+ YdtAppContext appContext = defaultYdtBuilder.getAppRootNode()
+ .getFirstChild();
+
+ YangApplicationBroker yab = new YangApplicationBroker(defaultYdtBuilder.
+ getYangSchemaRegistry());
+ yab.setAugGenMethodSet(defaultYdtBuilder.getAugGenMethodSet());
+ YdtContext deleteTree = yab.buildDeleteTree(appContext.getDeleteNodes());
+ yab.processAugmentedNodesForDelete(deleteTree.getFirstChild(),
+ appContext);
+
+ assertThat(appContext.getModuleContext().getName(), is("test"));
+
+ appContext = appContext.getFirstChild();
+ String augmentName = ((YangAugment) appContext
+ .getAugmentingSchemaNode()).getTargetNode().get(0)
+ .getResolvedNode().getJavaClassNameOrBuiltInType();
+ assertThat(augmentName, is("cont4"));
+
+ assertThat(appContext.getFirstChild(), nullValue());
+ assertThat(appContext.getLastChild(), nullValue());
+
+ YdtContext ydtContext = deleteTree.getFirstChild();
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid delete request
+ * for data resource with multiple augments.
+ */
+ @Test
+ public void testDeleteWithMultipleAugment() {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForDeleteWithMultipleAugment();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request with only output.
+ */
+ @Test
+ public void testRpcWithOutput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpcWithOnlyOutput();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request with only input.
+ */
+ @Test
+ public void testRpcWithInput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpcWithOnlyInput();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request with input and output.
+ */
+ @Test
+ public void testRpcWithInputOutput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpcWithBothInputOutput();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request without input and
+ * output.
+ */
+ @Test
+ public void testRpcWithoutInputOutput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpc();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+}
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"));
+ }
+}