[ONOS-5764]Decoder is returning Null
Change-Id: I51dabe5a7133df6e5766cb3ed3c36a596936263b
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java
index 3e990be..266b391 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java
@@ -205,7 +205,6 @@
if (ydtBuilder != null) {
return getObjectList(ydtBuilder.getRootNode());
}
-
return null;
}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java
index b5a9ea2..11a14ff 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java
@@ -35,7 +35,10 @@
public void walk(XmlListener listener, Element element,
Element rootElement) {
try {
- listener.enterXmlElement(element, getElementType(element),
+ Element newElement = element.createCopy();
+ newElement.remove(element.getNamespace());
+
+ listener.enterXmlElement(element, getElementType(newElement),
rootElement);
if (element.hasContent() && !element.isTextOnly()) {
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java
index 1c6536a..eefc60f 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java
@@ -37,6 +37,8 @@
*/
private YdtExtendedBuilder ydtExtBuilder;
+ private String prevNodeNamespace;
+
/**
* Sets the YANG data tree builder object.
*
@@ -69,21 +71,42 @@
nameSpace = element.getNamespace().getURI();
}
+ /*
+ * When new module has to be added, and if curnode has reference of
+ * previous module, then we need to traverse back to parent(logical root
+ * node).
+ */
+ if (ydtExtBuilder.getRootNode() == ydtExtBuilder.getCurNode()
+ .getParent() && prevNodeNamespace != null &&
+ !prevNodeNamespace.equals(nameSpace)) {
+ ydtExtBuilder.traverseToParent();
+ }
+
if (nodeType == OBJECT_NODE && element.content() == null || element
.content().isEmpty()) {
nodeType = TEXT_NODE;
}
if (nodeType == OBJECT_NODE) {
if (ydtExtBuilder != null) {
+ if (ydtExtBuilder.getCurNode() == ydtExtBuilder.getRootNode()) {
+ ydtExtBuilder.addChild(null, nameSpace, opType);
+ }
ydtExtBuilder.addChild(element.getName(), nameSpace, opType);
}
} else if (nodeType == TEXT_NODE) {
if (ydtExtBuilder != null) {
+ if (ydtExtBuilder.getCurNode() == ydtExtBuilder.getRootNode()) {
+ ydtExtBuilder.addChild(null, nameSpace, opType);
+ }
ydtExtBuilder.addLeaf(element.getName(), nameSpace,
element.getText());
}
}
+
+ if (nameSpace != null) {
+ prevNodeNamespace = nameSpace;
+ }
}
@Override
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
index 75e00f2..cd37eea 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
@@ -317,6 +317,20 @@
boolean contextSwitch = false;
YangSchemaNode augmentingSchema = null;
YangSchemaNodeIdentifier id = getNodeIdentifier(name, namespace);
+ if (name == null) {
+ if (!curNode.equals(rootNode)) {
+ throw new YdtException("Name is null for node other than module");
+ }
+
+ /*
+ * Since XML will not have module name, id.name will be null. In
+ * that case get schema node by using namespace. In NBI flow,
+ * name will never be null.
+ */
+ YangSchemaNode node = registry
+ .getSchemaWrtNameSpace(id.getNameSpace().getModuleNamespace());
+ id.setName(node.getName());
+ }
try {
// Module/sub-module node handler.
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ych/DefaultYangCodecHandlerTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ych/DefaultYangCodecHandlerTest.java
index dea5877..7cb5a9c 100644
--- a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ych/DefaultYangCodecHandlerTest.java
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ych/DefaultYangCodecHandlerTest.java
@@ -973,54 +973,6 @@
/**
* Unit test case in which verifying object for xml string with config as
- * root name and empty container.
- */
- @Test
- public void proceessCodecDecodeFunctionForEmptyContainer() {
- String path = "src/test/resources/ychTestResourceFiles/getconfigemptycontainer.xml";
- StringBuilder sb = new StringBuilder();
- String sCurrentLine;
- testYangSchemaNodeProvider.processSchemaRegistry(null);
- DefaultYangSchemaRegistry schemaRegistry =
- testYangSchemaNodeProvider.getDefaultYangSchemaRegistry();
-
- YangCodecRegistry.initializeDefaultCodec();
- DefaultYangCodecHandler defaultYangCodecHandler =
- new DefaultYangCodecHandler(schemaRegistry);
-
- try (BufferedReader br = new BufferedReader(new FileReader(path))) {
-
- while ((sCurrentLine = br.readLine()) != null) {
- sb.append(sCurrentLine);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- // Verify the received object list
- List<Object> objectList =
- defaultYangCodecHandler.decode(sb.toString(),
- XML, QUERY_CONFIG_REQUEST);
- Iterator<Object> iterator = objectList.iterator();
- while (iterator.hasNext()) {
- Object object = iterator.next();
- if (object.getClass().getSimpleName()
- .equals(EMPTY_CONTAINER)) {
- EmptyContainerOpParam emptyContainerOpParam =
- (EmptyContainerOpParam) object;
- assertNull(AM_OBJ + "empty-container: container value is not" +
- "null",
- emptyContainerOpParam.emptyContainer());
- } else {
- assertEquals(AM_OBJ, EMPTY_CONTAINER, object
- .getClass().getSimpleName());
- }
- }
- }
-
-
- /**
- * Unit test case in which verifying object for xml string with config as
* root name and multiple module.
*/
@Test
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/combinedrootname.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/combinedrootname.xml
index 1997f3d..04078f1 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/combinedrootname.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/combinedrootname.xml
@@ -5,94 +5,92 @@
<running/>
</target>
<filter xmlns="ydt.filter-type" type="subtree">
- <Combined xmlns="ych:combined">
- <attributes>
- <origin>
- <value>123</value>
- </origin>
- <multi-exit-disc>
- <med>456</med>
- </multi-exit-disc>
- <local-pref>
- <pref>23</pref>
- </local-pref>
- <aigp>
- <aigp-tlv>
- <metric>456</metric>
- </aigp-tlv>
- </aigp>
- <unrecognized-attributes>
- <partial>false</partial>
- <transitive>false</transitive>
- <type>1</type>
- <value>QUJD</value>
- </unrecognized-attributes>
- <unrecognized-attributes>
- <partial>true</partial>
- <transitive>true</transitive>
- <type>2</type>
- <value>QUJD</value>
- </unrecognized-attributes>
- <unrecognized-attributes>
- <partial>true</partial>
- <transitive>false</transitive>
- <type>3</type>
- <value>QUJD</value>
- </unrecognized-attributes>
- <unrecognized-attributes>
- <partial>false</partial>
- <transitive>true</transitive>
- <type>4</type>
- <value>QUJD</value>
- </unrecognized-attributes>
- <bgp-parameters>
- <optional-capabilities>
- <c-parameters>
- <as4-bytes-capability>
- <as-number>11</as-number>
- </as4-bytes-capability>
- </c-parameters>
- </optional-capabilities>
- <optional-capabilities>
- <c-parameters>
- <as4-bytes-capability>
- <as-number>22</as-number>
- </as4-bytes-capability>
- </c-parameters>
- </optional-capabilities>
- <optional-capabilities>
- <c-parameters>
- <as4-bytes-capability>
- <as-number>33</as-number>
- </as4-bytes-capability>
- </c-parameters>
- </optional-capabilities>
- </bgp-parameters>
- <bgp-parameters>
- <optional-capabilities>
- <c-parameters>
- <as4-bytes-capability>
- <as-number>33</as-number>
- </as4-bytes-capability>
- </c-parameters>
- </optional-capabilities>
- <optional-capabilities>
- <c-parameters>
- <as4-bytes-capability>
- <as-number>33</as-number>
- </as4-bytes-capability>
- </c-parameters>
- </optional-capabilities>
- <optional-capabilities>
- <c-parameters>
- <as4-bytes-capability>
- <as-number>33</as-number>
- </as4-bytes-capability>
- </c-parameters>
- </optional-capabilities>
- </bgp-parameters>
- </attributes>
- </Combined>
+ <attributes xmlns="ych:combined">
+ <origin>
+ <value>123</value>
+ </origin>
+ <multi-exit-disc>
+ <med>456</med>
+ </multi-exit-disc>
+ <local-pref>
+ <pref>23</pref>
+ </local-pref>
+ <aigp>
+ <aigp-tlv>
+ <metric>456</metric>
+ </aigp-tlv>
+ </aigp>
+ <unrecognized-attributes>
+ <partial>false</partial>
+ <transitive>false</transitive>
+ <type>1</type>
+ <value>QUJD</value>
+ </unrecognized-attributes>
+ <unrecognized-attributes>
+ <partial>true</partial>
+ <transitive>true</transitive>
+ <type>2</type>
+ <value>QUJD</value>
+ </unrecognized-attributes>
+ <unrecognized-attributes>
+ <partial>true</partial>
+ <transitive>false</transitive>
+ <type>3</type>
+ <value>QUJD</value>
+ </unrecognized-attributes>
+ <unrecognized-attributes>
+ <partial>false</partial>
+ <transitive>true</transitive>
+ <type>4</type>
+ <value>QUJD</value>
+ </unrecognized-attributes>
+ <bgp-parameters>
+ <optional-capabilities>
+ <c-parameters>
+ <as4-bytes-capability>
+ <as-number>11</as-number>
+ </as4-bytes-capability>
+ </c-parameters>
+ </optional-capabilities>
+ <optional-capabilities>
+ <c-parameters>
+ <as4-bytes-capability>
+ <as-number>22</as-number>
+ </as4-bytes-capability>
+ </c-parameters>
+ </optional-capabilities>
+ <optional-capabilities>
+ <c-parameters>
+ <as4-bytes-capability>
+ <as-number>33</as-number>
+ </as4-bytes-capability>
+ </c-parameters>
+ </optional-capabilities>
+ </bgp-parameters>
+ <bgp-parameters>
+ <optional-capabilities>
+ <c-parameters>
+ <as4-bytes-capability>
+ <as-number>33</as-number>
+ </as4-bytes-capability>
+ </c-parameters>
+ </optional-capabilities>
+ <optional-capabilities>
+ <c-parameters>
+ <as4-bytes-capability>
+ <as-number>33</as-number>
+ </as4-bytes-capability>
+ </c-parameters>
+ </optional-capabilities>
+ <optional-capabilities>
+ <c-parameters>
+ <as4-bytes-capability>
+ <as-number>33</as-number>
+ </as4-bytes-capability>
+ </c-parameters>
+ </optional-capabilities>
+ </bgp-parameters>
+ </attributes>
</filter>
</edit-config>
</rpc>
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootname.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootname.xml
index c8509f1..64c25aa 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootname.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootname.xml
@@ -4,17 +4,13 @@
<target>
<running/>
</target>
- <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
- <Logistics-manager xmlns="ydt.root">
- <Customs-supervisor>abc</Customs-supervisor>
- <Purchasing-supervisor xmlns="ydt.root">
- <purchasing-specialist>bcd</purchasing-specialist>
- <support>cde</support>
- </Purchasing-supervisor>
- </Logistics-manager>
- <merchandisersupervisor xmlns="ydt.Merchandiser-supervisor">
- <supervisor>abc</supervisor>
- </merchandisersupervisor>
+ <config>
+ <Customs-supervisor xmlns="ydt.root">abc</Customs-supervisor>
+ <Purchasing-supervisor xmlns="ydt.root">
+ <purchasing-specialist>bcd</purchasing-specialist>
+ <support>cde</support>
+ </Purchasing-supervisor>
+ <supervisor xmlns="ydt.Merchandiser-supervisor">abc</supervisor>
</config>
</edit-config>
</rpc>
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootnameOperationType.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootnameOperationType.xml
index 6cecea49..ce63205 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootnameOperationType.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/configrootnameOperationType.xml
@@ -4,17 +4,13 @@
<target>
<running/>
</target>
- <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
- <Logistics-manager xmlns="ydt.root">
- <Customs-supervisor>abc</Customs-supervisor>
- <Purchasing-supervisor xmlns="ydt.root" operation="delete">
- <purchasing-specialist>bcd</purchasing-specialist>
- <support>cde</support>
- </Purchasing-supervisor>
- </Logistics-manager>
- <merchandisersupervisor xmlns="ydt.Merchandiser-supervisor">
- <supervisor>abc</supervisor>
- </merchandisersupervisor>
+ <config>
+ <Customs-supervisor xmlns="ydt.root">abc</Customs-supervisor>
+ <Purchasing-supervisor xmlns="ydt.root" operation="delete">
+ <purchasing-specialist>bcd</purchasing-specialist>
+ <support>cde</support>
+ </Purchasing-supervisor>
+ <supervisor xmlns="ydt.Merchandiser-supervisor">abc</supervisor>
</config>
</edit-config>
</rpc>
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getReply.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getReply.xml
index b6d11fe..0b836d3 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getReply.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getReply.xml
@@ -2,10 +2,8 @@
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:ex="http://example.net/content/1.0">
<data>
- <Logistics-manager xmlns="ydt.root">
- <Purchasing-supervisor xmlns="ydt.root">
- <purchasing-specialist>bcd</purchasing-specialist>
- </Purchasing-supervisor>
- </Logistics-manager>
+ <Purchasing-supervisor xmlns="ydt.root">
+ <purchasing-specialist>bcd</purchasing-specialist>
+ </Purchasing-supervisor>
</data>
</rpc-reply>
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigReply.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigReply.xml
index e27beab..bf3fc7b 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigReply.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigReply.xml
@@ -1,8 +1,6 @@
<rpc message-id="101"
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<data>
- <merchandisersupervisor xmlns="ydt.Merchandiser-supervisor">
- <supervisor>abc</supervisor>
- </merchandisersupervisor>
+ <supervisor xmlns="ydt.Merchandiser-supervisor">abc</supervisor>
</data>
</rpc>
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigrootname.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigrootname.xml
index df69691..0c35df5 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigrootname.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getconfigrootname.xml
@@ -5,9 +5,7 @@
<running/>
</source>
<filter type="subtree">
- <merchandisersupervisor xmlns="ydt.Merchandiser-supervisor">
- <supervisor>abc</supervisor>
- </merchandisersupervisor>
+ <supervisor xmlns="ydt.Merchandiser-supervisor">abc</supervisor>
</filter>
</get-config>
</rpc>
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getrootname.xml b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getrootname.xml
index 9773893..b7fc97d 100644
--- a/apps/yms/ut/src/test/resources/ychTestResourceFiles/getrootname.xml
+++ b/apps/yms/ut/src/test/resources/ychTestResourceFiles/getrootname.xml
@@ -2,11 +2,9 @@
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get>
<filter type="subtree">
- <Logistics-manager xmlns="ydt.root">
- <Purchasing-supervisor xmlns="ydt.root">
- <purchasing-specialist>bcd</purchasing-specialist>
- </Purchasing-supervisor>
- </Logistics-manager>
+ <Purchasing-supervisor xmlns="ydt.root">
+ <purchasing-specialist>bcd</purchasing-specialist>
+ </Purchasing-supervisor>
</filter>
</get>
</rpc>
\ No newline at end of file