[ONOS-6655] Defect fix
Change-Id: Id9e924891809157d866b100cc251f6a09b6bfa61
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModIdToRscIdConverter.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModIdToRscIdConverter.java
index 9417c90..a2991ed 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModIdToRscIdConverter.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModIdToRscIdConverter.java
@@ -24,6 +24,7 @@
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangRpc;
import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
+import org.onosproject.yang.compiler.datamodel.YangSchemaNodeType;
import org.onosproject.yang.model.AtomicPath;
import org.onosproject.yang.model.ModelObjectId;
import org.onosproject.yang.model.MultiInstanceLeaf;
@@ -36,6 +37,7 @@
import java.util.Set;
import java.util.regex.Pattern;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_AUGMENT_NODE;
import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.nonEmpty;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
@@ -172,9 +174,10 @@
// with the input fetchNode's data
node = node.getChild();
while (node != null) {
- if (node.getJavaAttributeName().toLowerCase()
- .equals(strArray[i]) &&
- node.getYangSchemaNodeType() != YANG_NON_DATA_NODE) {
+ YangSchemaNodeType type = node.getYangSchemaNodeType();
+ if (type != YANG_NON_DATA_NODE && type != YANG_AUGMENT_NODE &&
+ node.getJavaAttributeName().toLowerCase()
+ .equals(strArray[i])) {
//last index fetchNode will be input fetchNode.
lastIndexNode = node.getChild();
break;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
index 46f8c92..a016fda 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
@@ -34,6 +34,11 @@
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum2Enum;
import org.onosproject.yang.gen.v1.ytbmodulewithcontainer.rev20160826.ytbmodulewithcontainer.DefaultSched;
import org.onosproject.yang.gen.v1.ytbmodulewithleaflist.rev20160826.YtbModuleWithLeafList;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.DefaultContentInput;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.DefaultContentOutput;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.contentinput.DefaultIn;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.contentinput.InTypedef;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.contentoutput.outch.DefaultFirst;
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.DefaultCarrier;
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.DefaultMultiplexes;
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.Multiplexes;
@@ -60,6 +65,7 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -91,9 +97,10 @@
*/
public class DefaultDataTreeBuilderTest {
+ private final TestYangSchemaNodeProvider schemaProvider = new
+ TestYangSchemaNodeProvider();
@Rule
public ExpectedException thrown = ExpectedException.none();
-
private ResourceData rscData;
private DefaultDataTreeBuilder treeBuilder;
private DefaultYangModelRegistry registry;
@@ -105,8 +112,6 @@
private DataNode node;
private ModelObjectId mid;
private DefaultModelObjectData.Builder data;
- private final TestYangSchemaNodeProvider schemaProvider = new
- TestYangSchemaNodeProvider();
/**
* Do the prior setup for each UT.
@@ -1185,4 +1190,66 @@
validateDataNode(childNode, "type", ns, SINGLE_INSTANCE_LEAF_VALUE_NODE,
false, "tunnel-p2p");
}
+
+ /**
+ * Unit test for RPC with grouping and augment in file.
+ */
+ @Test
+ public void processRpc() {
+ setUp();
+ InTypedef typedef = new InTypedef("con-leaf");
+ DefaultIn con = new DefaultIn();
+ DefaultContentInput input = new DefaultContentInput();
+ con.conIn(typedef);
+ input.in(con);
+
+ data = new DefaultModelObjectData.Builder();
+ data.addModelObject(input);
+ rscData = treeBuilder.getResourceData(data.build());
+
+ String ns = "yms:test:ytb:ytb:rpc";
+ List<DataNode> inDn = rscData.dataNodes();
+ id = rscData.resourceId();
+ keys = id.nodeKeys();
+ assertThat(2, is(keys.size()));
+
+ sid = keys.get(0).schemaId();
+ assertThat("/", is(sid.name()));
+ assertThat(null, is(sid.namespace()));
+
+ sid = keys.get(1).schemaId();
+ assertThat("content", is(sid.name()));
+ assertThat(ns, is(sid.namespace()));
+
+ DataNode node = inDn.get(0);
+ validateDataNode(node, "input", ns, SINGLE_INSTANCE_NODE, true, null);
+
+ List<Short> ll = new LinkedList<>();
+ DefaultFirst first = new DefaultFirst();
+ DefaultContentOutput output = new DefaultContentOutput();
+
+ ll.add((short) 9);
+ first.call(ll);
+ output.outCh(first);
+
+ data = new DefaultModelObjectData.Builder();
+ data.addModelObject(output);
+ rscData = treeBuilder.getResourceData(data.build());
+
+ inDn = rscData.dataNodes();
+ id = rscData.resourceId();
+ keys = id.nodeKeys();
+ assertThat(2, is(keys.size()));
+
+ sid = keys.get(0).schemaId();
+ assertThat("/", is(sid.name()));
+ assertThat(null, is(sid.namespace()));
+
+ sid = keys.get(1).schemaId();
+ assertThat("content", is(sid.name()));
+ assertThat(ns, is(sid.namespace()));
+
+ node = inDn.get(0);
+ validateDataNode(node, "output", ns, SINGLE_INSTANCE_NODE, true, null);
+ }
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java
index f5807ab..cc6f615 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java
@@ -23,31 +23,42 @@
import org.onosproject.yang.gen.v1.yrtietfte.rev20170310.yrtietfte.tunnelp2pproperties.DefaultState;
import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.networks.DefaultAugmentedNwNetworks;
import org.onosproject.yang.gen.v1.yrtietftetopology.rev20160317.yrtietftetopology.tetopologiesaugment.te.templates.LinkTemplate;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.DefaultContentInput;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.DefaultContentOutput;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.contentinput.In;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.contentinput.InTypedef;
+import org.onosproject.yang.gen.v1.ytbrpc.rev20160826.ytbrpc.content.contentoutput.outch.First;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultResourceData;
import org.onosproject.yang.model.ModelObject;
import org.onosproject.yang.model.ModelObjectData;
import org.onosproject.yang.model.ResourceData;
+import org.onosproject.yang.model.ResourceId;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onosproject.yang.runtime.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.SerializerHelper.addToResourceId;
import static org.onosproject.yang.runtime.SerializerHelper.exitDataNode;
import static org.onosproject.yang.runtime.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.SerializerHelper.initializeResourceId;
/**
* Tests the YANG object building for the YANG data tree based on the non
* schema augmented nodes.
*/
public class YobGroupingUsesTest {
- TestYangSerializerContext context = new TestYangSerializerContext();
+
private static final String NW_NS = "urn:ietf:params:xml:ns:yang:yrt-ietf-network";
private static final String TE_NS = "urn:ietf:params:xml:ns:yang:yrt-ietf-te-topology";
private static final String TE = "urn:ietf:params:xml:ns:yang:ietf-te";
+ private static final String RPC_NS = "yms:test:ytb:ytb:rpc";
+ TestYangSerializerContext context = new TestYangSerializerContext();
private DataNode.Builder dBlr;
private String value;
+ private ResourceId.Builder rIdBlr;
public DataNode buildDataNodeForInterFileGrouping() {
@@ -131,6 +142,69 @@
return dBlr.build();
}
+ private ResourceData.Builder buildDataNodeWithInput() {
+ value = null;
+ rIdBlr = initializeResourceId(context);
+ rIdBlr = addToResourceId(rIdBlr, "content", RPC_NS, value);
+ dBlr = initializeDataNode(rIdBlr);
+ dBlr = addDataNode(dBlr, "input", RPC_NS, value, null);
+ dBlr = addDataNode(dBlr, "in", RPC_NS, value, null);
+ value = "name";
+ dBlr = addDataNode(dBlr, "con-in", RPC_NS, value, null);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ return DefaultResourceData.builder().addDataNode(dBlr.build())
+ .resourceId(rIdBlr.build());
+ }
+
+ private ResourceData.Builder buildDataNodeWithOutput() {
+ value = null;
+ rIdBlr = initializeResourceId(context);
+ rIdBlr = addToResourceId(rIdBlr, "content", RPC_NS, value);
+ dBlr = initializeDataNode(rIdBlr);
+ dBlr = addDataNode(dBlr, "output", RPC_NS, value, null);
+ value = "8";
+ dBlr = addDataNode(dBlr, "call", RPC_NS, value, null);
+ dBlr = exitDataNode(dBlr);
+ return DefaultResourceData.builder().addDataNode(dBlr.build())
+ .resourceId(rIdBlr.build());
+ }
+
+ /**
+ * Unit test for rpc input.
+ */
+ @Test
+ public void testRpcInput() {
+ ResourceData.Builder data = buildDataNodeWithInput();
+ DefaultYobBuilder builder = new DefaultYobBuilder(
+ (DefaultYangModelRegistry) context.getContext());
+ ModelObjectData modelObjectData = builder.getYangObject(data.build());
+
+ List<ModelObject> objects = modelObjectData.modelObjects();
+ ModelObject obj = objects.get(0);
+ DefaultContentInput in = ((DefaultContentInput) obj);
+ In input = in.in();
+ InTypedef leaf = input.conIn();
+ assertThat(leaf.string(), is("name"));
+ }
+
+ /**
+ * Unit test for rpc output.
+ */
+ @Test
+ public void testRpcOutput() {
+ ResourceData.Builder data = buildDataNodeWithOutput();
+ DefaultYobBuilder builder = new DefaultYobBuilder(
+ (DefaultYangModelRegistry) context.getContext());
+ ModelObjectData modelObjectData = builder.getYangObject(data.build());
+ List<ModelObject> objects = modelObjectData.modelObjects();
+ ModelObject obj = objects.get(0);
+ DefaultContentOutput out = ((DefaultContentOutput) obj);
+ First first = (First) out.outCh();
+ List<Short> call = first.call();
+ assertThat(call.get(0), is((short) 8));
+ }
+
/**
* Unit test for identity-ref.
*/
diff --git a/runtime/src/test/resources/ytbTestYangFiles/YtbRpc.yang b/runtime/src/test/resources/ytbTestYangFiles/YtbRpc.yang
new file mode 100644
index 0000000..33057ab
--- /dev/null
+++ b/runtime/src/test/resources/ytbTestYangFiles/YtbRpc.yang
@@ -0,0 +1,46 @@
+module YtbRpc {
+ yang-version 1;
+ namespace "yms:test:ytb:ytb:rpc";
+ prefix "sch";
+ revision "2016-08-26";
+
+ augment "/content/input/in" {
+ container real {
+ leaf in {
+ type string;
+ }
+ }
+ }
+
+ grouping rpc-group {
+ leaf val {
+ type string;
+ }
+ }
+
+ rpc content {
+ input {
+ typedef in-typedef {
+ type string;
+ }
+ container in {
+ leaf con-in {
+ type in-typedef;
+ }
+ }
+ }
+
+ output {
+ grouping in-group {
+ leaf-list call {
+ type uint8;
+ }
+ }
+ choice out-ch {
+ case first {
+ uses in-group;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file