Implementation of SchemaContextProvider interface
Change-Id: Id3a6b53aecbb1982c0fbef076cca1f2b119c9d0d
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcContextTest.java
new file mode 100644
index 0000000..6f61321
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcContextTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017-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.yang.runtime.impl;
+
+import org.junit.Test;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.RpcContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.processSchemaRegistry;
+import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.registry;
+
+/**
+ * Test cases for YANG runtime service interface file generation.
+ */
+public class RpcContextTest {
+ ModIdToRscIdConverter builder;
+ DefaultYangModelRegistry reg;
+ public static final String NS = "urn:params:xml:ns:yang:hello";
+ String value = null;
+ TestYangSerializerContext context = new TestYangSerializerContext();
+ DataNode.Builder dBlr;
+
+ /**
+ * Sets up all prerequisite.
+ */
+ private void setUp() {
+ processSchemaRegistry();
+ reg = registry();
+ builder = new ModIdToRscIdConverter(reg);
+ }
+
+ /**
+ * Check for service interface file.
+ */
+ @Test
+ public void checkRpcContext() {
+ setUp();
+ ResourceId.Builder rIdBlr = initializeResourceId(context);
+ rIdBlr = addToResourceId(rIdBlr, "hello-world", NS, value);
+
+ DefaultSchemaContextProvider scp = new DefaultSchemaContextProvider(
+ reg);
+
+ RpcContext context = scp.getRpcContext(rIdBlr.build());
+ assertEquals(context.rpcName(), "helloWorld");
+ assertEquals(context.serviceIntf().toString(), "interface org.onosproject" +
+ ".yang.gen.v1.hello.rev20150105.HelloService");
+ }
+}
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/rpc_test.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/rpc_test.yang
new file mode 100644
index 0000000..c1968a3
--- /dev/null
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/rpc_test.yang
@@ -0,0 +1,23 @@
+module hello {
+ yang-version 1;
+ namespace "urn:params:xml:ns:yang:hello";
+ prefix "hello";
+
+ revision "2015-01-05" {
+ description "Initial revision of hello model";
+ }
+
+ rpc hello-world {
+ input {
+ leaf x {
+ type string;
+ }
+ }
+
+ output {
+ leaf greeting {
+ type string;
+ }
+ }
+ }
+}
\ No newline at end of file