UT running time optimization and UT for model unregistration added.
Change-Id: Id839abe929604203f0b6ab1f4480369453bdfb1a
diff --git a/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java b/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java
index 1ce96b4..c457ec4 100644
--- a/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java
+++ b/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java
@@ -30,6 +30,7 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
+import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
@@ -104,7 +105,9 @@
List<YangNode> curNodes) {
DefaultYangModel model = new DefaultYangModel();
YangModuleId id;
- for (YangSchemaNode node : curNodes) {
+ Iterator<YangNode> it = curNodes.iterator();
+ while (it.hasNext()) {
+ YangSchemaNode node = it.next();
id = processModuleId((YangNode) node);
org.onosproject.yang.YangModule module =
new DefaultYangModule(id, get(node.getFileName()), get(path));
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java b/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java
index b064e9b..0f0d8a6 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java
@@ -54,9 +54,10 @@
/**
* Represents YANG model registry implementation.
*/
-public class DefaultYangModelRegistry implements YangModelRegistry, SingleInstanceNodeContext {
+public class DefaultYangModelRegistry implements YangModelRegistry,
+ SingleInstanceNodeContext {
- private static final Logger log = getLogger(DefaultYangModelRegistry.class);
+ private final Logger log = getLogger(getClass());
private static final String AT = "@";
/*
@@ -181,9 +182,9 @@
"unregistered.", sClass
.getSimpleName(), param);
} else {
- throw new RuntimeException(
- sClass.getSimpleName() +
- " service was not registered.");
+ log.error("Either {} service was not registered or " +
+ "already unregistered from model " +
+ "registry.", sClass.getSimpleName());
}
}
} else {
@@ -277,12 +278,16 @@
* @return registered class
*/
public Class<?> getRegisteredClass(YangSchemaNode schemaNode) {
- String interfaceName = getInterfaceClassName(schemaNode);
- String serviceName = getServiceName(schemaNode);
- Class<?> regClass = registerClassStore.get(serviceName);
- if (regClass == null) {
- regClass = registerClassStore.get(interfaceName);
+ Class<?> regClass = null;
+ if (schemaNode != null) {
+ String interfaceName = getInterfaceClassName(schemaNode);
+ String serviceName = getServiceName(schemaNode);
+ regClass = registerClassStore.get(serviceName);
+ if (regClass == null) {
+ regClass = registerClassStore.get(interfaceName);
+ }
}
+ log.error("{} node should not be null.");
return regClass;
}
@@ -476,7 +481,7 @@
*
* @param nodes set of module/submodule nodes
*/
- public void updateChildContext(Set<YangNode> nodes) {
+ private void updateChildContext(Set<YangNode> nodes) {
// Preparing schema id for logical node with name "/"
for (YangNode node : nodes) {
node.setLeafRootContext(this);
@@ -513,7 +518,7 @@
*
* @param curNode choice node
*/
- public void updateSchemaContextForChoiceChild(YangNode curNode) {
+ private void updateSchemaContextForChoiceChild(YangNode curNode) {
YangNode child = curNode.getChild();
// Setting the parent context for case
while (child != null) {
@@ -527,7 +532,7 @@
*
* @param curNode case node
*/
- public void updateSchemaContextForCaseChild(YangNode curNode) {
+ private void updateSchemaContextForCaseChild(YangNode curNode) {
curNode.setLeafRootContext(this);
YangNode child = curNode.getChild();
updateContextForChoiceCase(child);
@@ -538,8 +543,7 @@
checkNotNull(schemaId);
if (schemaId.namespace() == null) {
- log.error("node with {} namespace not found.",
- schemaId.namespace());
+ log.error("node with {} namespace not found.", schemaId.namespace());
}
String namespace = schemaId.namespace();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
index 8d6caba..0e12c39 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
@@ -25,6 +25,8 @@
import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
@@ -101,10 +103,6 @@
"org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf" +
".network4.IetfNetwork4OpParam";
- private static final String UN_REG_SCHEMA_NAME = "ietf-routing";
- private static final String UN_REG_INTERFACE_NAME = "IetfRouting";
- private static final String UN_REG_OP_PARAM_NAME = "IetfRoutingOpParam";
- private static final String UN_REG_SERVICE_NAME = "IetfRoutingService";
private static final String CHECK = "check";
private static final String DATE_NAMESPACE = "2015-00-08";
private static final String NAMESPACE =
@@ -126,39 +124,39 @@
provider.processSchemaRegistry();
+ List<YangNode> nodes = new ArrayList<>();
DefaultYangModelRegistry registry = provider.registry();
YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_3);
assertThat(true, is(SCHEMA_NAME_3.equals(yangNode.getName())));
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_3);
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_3);
assertThat(true, is(SCHEMA_NAME_3.equals(yangNode.getName())));
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_3);
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_3);
assertThat(true, is(SCHEMA_NAME_3.equals(yangNode.getName())));
-// provider.unregisterService(SERVICE_NAME_3);
- //TODO: fix unregister UT.
-//
-// yangNode = registry.getForAppName(SERVICE_NAME_3);
-// assertThat(true, is(yangNode == null));
-//
-// yangNode = registry.getForSchemaName(SCHEMA_NAME_3);
-// assertThat(true, is(yangNode == null));
-//
-// yangNode =
-// registry.getForInterfaceFileName(
-// INTERFACE_NAME_3);
-// assertThat(true, is(yangNode == null));
-//
-// yangNode =
-// registry.getForOpPramFileName(
-// OP_PARAM_NAME_3);
-// assertThat(true, is(yangNode == null));
+ Class<?> cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_3.equals(cls.getName())));
+
+ //Unregister service
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
+
+ yangNode = registry.getForAppName(SERVICE_NAME_3);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_3);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_3);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_3);
+ assertThat(true, is(yangNode == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls == null));
}
/**
@@ -172,179 +170,63 @@
throws IOException {
provider.processSchemaRegistry();
- DefaultYangModelRegistry registry =
- provider.registry();
+ DefaultYangModelRegistry registry = provider.registry();
+ List<YangNode> nodes = new ArrayList<>();
//Service with rev.
YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_4_15);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_REV_15);
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_REV_15);
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- // provider.unregisterService(SERVICE_NAME_REV_15);
+ Class<?> cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_REV_15.equals(cls.getName())));
+
+ //unregister SERVICE_NAME_REV_15.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
yangNode = registry.getForAppName(SERVICE_NAME_REV_15);
assertThat(true, is(yangNode == null));
- //Here the yangNode should be the node which does not have revision.
- // asset should pass with false.
- yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
- assertThat(true, is(((YangNode) yangNode).getRevision() == null));
-
- yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_NO_REV);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_NO_REV);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- //provider.unregisterService(SERVICE_NAME_NO_REV);
-
- yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
- assertThat(true, is(yangNode == null));
-
- //Here the yangNode should be the node which have different revision.
yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
assertThat(true, is(yangNode != null));
- //TODO: ureg.
-// assertThat(true, is(((YangNode) yangNode).getRevision() != null));
- }
- /**
- * Unit test case in which schema node should be present with multi
- * revisions.
- *
- * @throws IOException when fails to do IO operation
- */
- //TODO: add unreg in UT
- public void testForGetSchemaNodeWhenMultiRevision()
- throws IOException {
-
- provider.processSchemaRegistry();
- DefaultYangModelRegistry registry =
- provider.registry();
-
- //Service with rev.
- YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_4_15);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_REV_15);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_REV_15);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- //As we have not registered an application this object should be null.
- Object object = registry.getRegisteredClass(yangNode);
- assertThat(true, is(object == null));
-// provider.unregisterService(SERVICE_NAME_REV_15);
-
- yangNode = registry.getForAppName(SERVICE_NAME_REV_15);
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
assertThat(true, is(yangNode == null));
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
+ assertThat(true, is(yangNode == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls == null));
+
//Here the yangNode should be the node which does not have revision.
// asset should pass with false.
yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
assertThat(true, is(((YangNode) yangNode).getRevision() == null));
- //Service with different revision.
- yangNode = registry
- .getForAppName(SERVICE_NAME_REV_16);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode = registry.getForSchemaName(SCHEMA_NAME_4_16);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_REV_16);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_REV_16);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- //As we have not registered an application this object should be null.
- object = registry.getRegisteredClass(yangNode);
- assertThat(true, is(object == null));
-// provider.unregisterService(SERVICE_NAME_REV_16);
-
- yangNode = registry.getForAppName(SERVICE_NAME_REV_16);
- assertThat(true, is(yangNode == null));
-
- //Here the yangNode should be the node which have different revision.
- yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
- assertThat(true, is(((YangNode) yangNode).getRevision() == null));
-
- //Service with different revision.
- yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode = registry.getForSchemaName(SCHEMA_NAME_4_17);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_REV_17);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_REV_17);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
- //As we have not registered an application this object should be null.
- object = registry.getRegisteredClass(yangNode);
- assertThat(true, is(object == null));
-// provider.unregisterService(SERVICE_NAME_REV_17);
-
- yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
- assertThat(true, is(yangNode == null));
-
- //Here the yangNode should be the node which have different revision.
- yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
- assertThat(true, is(((YangNode) yangNode).getRevision() == null));
-
- //Service no revision.
- yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+ //---------------------------------------------------------------//
yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_NO_REV);
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_NO_REV);
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- //As we have not registered an application this object should be null.
- object = registry.getRegisteredClass(yangNode);
- assertThat(true, is(object == null));
- // provider.unregisterService(SERVICE_NAME_NO_REV);
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_NO_REV.equals(cls.getName())));
+
+ //unregister SERVICE_NAME_NO_REV.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
assertThat(true, is(yangNode == null));
@@ -354,30 +236,223 @@
assertThat(true, is(yangNode != null));
assertThat(true, is(((YangNode) yangNode).getRevision() != null));
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
+ assertThat(true, is(yangNode == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls == null));
+ }
+
+ /**
+ * Unit test case in which schema node should be present with multi
+ * revisions.
+ *
+ * @throws IOException when fails to do IO operation
+ */
+ @Test
+ public void testForGetSchemaNodeWhenMultiRevision()
+ throws IOException {
+
+ provider.processSchemaRegistry();
+ DefaultYangModelRegistry registry = provider.registry();
+
+ List<YangNode> nodes = new ArrayList<>();
+ //Service with rev.
+ YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_4_15);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ Class<?> cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_REV_15.equals(cls.getName())));
+
+ //Unregister SERVICE_NAME_REV_15.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
+
+ yangNode = registry.getForAppName(SERVICE_NAME_REV_15);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(yangNode != null));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
+ assertThat(true, is(yangNode == null));
+
+ //Here the yangNode should be the node which does not have revision.
+ // asset should pass with false.
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls != null));
+
+ //---------------------------------------------------------------//
+
+ //Here the yangNode should be the node which does not have revision.
+ // asset should pass with false.
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+ //Service with different revision.
+ yangNode = registry.getForAppName(SERVICE_NAME_REV_16);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4_16);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_16);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_16);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_REV_16.equals(cls.getName())));
+
+ //Unregister SERVICE_NAME_REV_16.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
+
+ yangNode = registry.getForAppName(SERVICE_NAME_REV_16);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_16);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_16);
+ assertThat(true, is(yangNode == null));
+
+ //Here the yangNode should be the node which have different revision.
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls != null));
+
+ //---------------------------------------------------------------//
+
+ //Service with different revision.
+ yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4_17);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_17);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_17);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_REV_17.equals(cls.getName())));
+
+ //Unregister SERVICE_NAME_REV_17.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
+
+ yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_17);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_17);
+ assertThat(true, is(yangNode == null));
+
+ //Here the yangNode should be the node which have different revision.
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls != null));
+
+ //---------------------------------------------------------------//
+
+ //Service no revision.
+ yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
+ assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_NO_REV.equals(cls.getName())));
+
+ //Unregister SERVICE_NAME_NO_REV.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
+
+ yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
+ assertThat(true, is(yangNode == null));
+
+ //Here the yangNode should be the node which have different revision.
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(yangNode != null));
+ assertThat(true, is(((YangNode) yangNode).getRevision() != null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls != null));
+
+ //---------------------------------------------------------------//
+
//Service with different revision.
yangNode = registry.getForAppName(SERVICE_NAME_REV_14);
- assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+ assertThat(true, is(yangNode == null));
yangNode = registry.getForSchemaName(SCHEMA_NAME_4_14);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- yangNode =
- registry.getForInterfaceFileName(
- INTERFACE_NAME_REV_14);
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_14);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- yangNode =
- registry.getForOpPramFileName(
- OP_PARAM_NAME_REV_14);
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_14);
assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
- //As we have not registered an application this object should be null.
- object = registry.getRegisteredClass(yangNode);
- assertThat(true, is(object == null));
-// provider.unregisterService(SERVICE_NAME_REV_14);
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(INTERFACE_NAME_REV_14.equals(cls.getName())));
+
+ //Unregister SERVICE_NAME_REV_14.
+ nodes.add((YangNode) yangNode);
+ provider.unRegister(nodes);
yangNode = registry.getForAppName(SERVICE_NAME_REV_14);
assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_14);
+ assertThat(true, is(yangNode == null));
+
+ yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_14);
+ assertThat(true, is(yangNode == null));
+
+ cls = registry.getRegisteredClass(yangNode);
+ assertThat(true, is(cls == null));
}
/**
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java
index 59418e5..88f0a44 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java
@@ -29,6 +29,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -42,7 +43,6 @@
/**
* Represents mock bundle context. provides bundle context for YSR to do unit
* testing.
- * //TODO: add unreg ut.
*/
public class TestYangSchemaNodeProvider {
@@ -70,41 +70,63 @@
//Need to deserialize generated meta data file for unit tests.
Set<YangNode> appNode = deSerializeDataModel(META_PATH);
nodes.addAll(appNode);
-
- //Process loading class file.
- String appName;
- ClassLoader classLoader = TestYangSchemaNodeProvider.class.getClassLoader();
- for (YangSchemaNode node : nodes) {
-
- //If service class is not generated then use
- // interface file to load this class.
- appName = getInterfaceClassName(node);
- Class<?> cls;
- try {
- cls = classLoader.loadClass(appName);
- } catch (ClassNotFoundException e) {
- continue;
- }
-
- //Create model registration param.
- ModelRegistrationParam.Builder b =
- DefaultModelRegistrationParam.builder();
-
- //create a new YANG model
- YangModel model = processYangModel(META_PATH, nodes);
- //set YANG model
- b.setYangModel(model);
- //generate app info.
- AppModuleInfo info = new DefaultAppModuleInfo(cls, null);
- b.addAppModuleInfo(processModuleId((YangNode) node), info);
- reg.registerModel(b.build());
- }
+ reg.registerModel(prepareParam(nodes));
deleteDirectory(TEMP_FOLDER_PATH);
} catch (IOException e) {
}
}
/**
+ * Unregister given nodes from runtime service.
+ *
+ * @param nodes list of nodes
+ */
+ public void unRegister(List<YangNode> nodes) {
+ reg.unregisterModel(prepareParam(nodes));
+ }
+
+ /**
+ * Prepares model registration parameter.
+ *
+ * @param nodes list of nodes
+ * @return model registration parameter
+ */
+ private ModelRegistrationParam prepareParam(List<YangNode> nodes) {
+ //Process loading class file.
+ String appName;
+ ClassLoader classLoader = getClass().getClassLoader();
+
+ //Create model registration param.
+ ModelRegistrationParam.Builder b =
+ DefaultModelRegistrationParam.builder();
+
+ //create a new YANG model
+ YangModel model = processYangModel(META_PATH, nodes);
+ //set YANG model
+ b.setYangModel(model);
+
+ Iterator<YangNode> it = nodes.iterator();
+ while (it.hasNext()) {
+ YangSchemaNode node = it.next();
+
+ //If service class is not generated then use
+ // interface file to load this class.
+ appName = getInterfaceClassName(node);
+ Class<?> cls;
+ try {
+ cls = classLoader.loadClass(appName);
+ } catch (ClassNotFoundException e) {
+ continue;
+ }
+
+ //generate app info.
+ AppModuleInfo info = new DefaultAppModuleInfo(cls, null);
+ b.addAppModuleInfo(processModuleId((YangNode) node), info);
+ }
+ return b.build();
+ }
+
+ /**
* Returns schema registry.
*
* @return schema registry