Fixed incorrect XML test suites & Usage of removed API 97/9197/4
authorTony Tkacik <ttkacik@cisco.com>
Mon, 21 Jul 2014 11:48:03 +0000 (13:48 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 21 Jul 2014 12:56:52 +0000 (14:56 +0200)
Change in underlying YANG Tools codec, unvereded
that there were test-suites which did string
comparison for testing of XML responses and
any change in XML serialization (valid from
XML point-of-view) triggered this tests to
fail.

Reworked offending tests to use XML W3C Document
for testing instead of string comparison and regexes.

Change-Id: Ib6e35e8d2fe79275666235370d1dda461277a59f
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/util/NormalizedNodeXmlConverterTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java
opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/commands/local/Disconnect.java
opendaylight/netconf/netconf-cli/src/test/java/org/opendaylight/controller/netconf/cli/io/IOUtilTest.java

index 02deb5a815a4b52b34dda1d7f5d7c9b2453142ec..28e358a06acb99a8c05d54b208fd476d826164f3 100644 (file)
@@ -7,10 +7,31 @@
  */
 package org.opendaylight.controller.cluster.datastore.util;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Test;
@@ -44,29 +65,10 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.TransformerFactoryConfigurationError;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.URI;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
 
 /**
@@ -96,8 +98,8 @@ public class NormalizedNodeXmlConverterTest {
     }
   }
 
-  public static DataSchemaNode getSchemaNode(SchemaContext context,
-      String moduleName, String childNodeName) {
+  public static DataSchemaNode getSchemaNode(final SchemaContext context,
+      final String moduleName, final String childNodeName) {
     for (Module module : context.getModules()) {
       if (module.getName().equals(moduleName)) {
         DataSchemaNode found =
@@ -111,12 +113,13 @@ public class NormalizedNodeXmlConverterTest {
         + childNodeName);
   }
 
-  static DataSchemaNode findChildNode(Set<DataSchemaNode> children, String name) {
+  static DataSchemaNode findChildNode(final Set<DataSchemaNode> children, final String name) {
     List<DataNodeContainer> containers = Lists.newArrayList();
 
     for (DataSchemaNode dataSchemaNode : children) {
-      if (dataSchemaNode.getQName().getLocalName().equals(name))
+      if (dataSchemaNode.getQName().getLocalName().equals(name)) {
         return dataSchemaNode;
+    }
       if (dataSchemaNode instanceof DataNodeContainer) {
         containers.add((DataNodeContainer) dataSchemaNode);
       } else if (dataSchemaNode instanceof ChoiceNode) {
@@ -135,13 +138,13 @@ public class NormalizedNodeXmlConverterTest {
   }
 
   private static InstanceIdentifier.NodeIdentifier getNodeIdentifier(
-      String localName) {
-    return new InstanceIdentifier.NodeIdentifier(new QName(
+      final String localName) {
+    return new InstanceIdentifier.NodeIdentifier(QName.create(
         URI.create(NAMESPACE), revision, localName));
   }
 
   public static InstanceIdentifier.AugmentationIdentifier getAugmentIdentifier(
-      String... childNames) {
+      final String... childNames) {
     Set<QName> qn = Sets.newHashSet();
 
     for (String childName : childNames) {
@@ -233,7 +236,7 @@ public class NormalizedNodeXmlConverterTest {
 
 
 
-  public void init(String yangPath, String xmlPath, ContainerNode expectedNode)
+  public void init(final String yangPath, final String xmlPath, final ContainerNode expectedNode)
       throws Exception {
     SchemaContext schema = parseTestSchema(yangPath);
     this.xmlPath = xmlPath;
@@ -242,7 +245,7 @@ public class NormalizedNodeXmlConverterTest {
     this.expectedNode = expectedNode;
   }
 
-  SchemaContext parseTestSchema(String yangPath) throws Exception {
+  SchemaContext parseTestSchema(final String yangPath) throws Exception {
 
     YangParserImpl yangParserImpl = new YangParserImpl();
     InputStream stream =
@@ -268,8 +271,9 @@ public class NormalizedNodeXmlConverterTest {
             .parse(Collections.singletonList(doc.getDocumentElement()),
                 containerNode);
 
-    if (expectedNode != null)
-      junit.framework.Assert.assertEquals(expectedNode, built);
+    if (expectedNode != null) {
+        junit.framework.Assert.assertEquals(expectedNode, built);
+    }
 
     logger.info("{}", built);
 
@@ -287,10 +291,9 @@ public class NormalizedNodeXmlConverterTest {
     System.out.println(toString(doc.getDocumentElement()));
     System.out.println(toString(el));
 
-    boolean diff =
-        new Diff(
-            XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
-            XMLUnit.buildTestDocument(toString(el))).similar();
+    new Diff(
+        XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
+        XMLUnit.buildTestDocument(toString(el))).similar();
   }
 
   private static ContainerNode listLeafListWithAttributes() {
@@ -353,8 +356,9 @@ public class NormalizedNodeXmlConverterTest {
             .parse(Collections.singletonList(doc.getDocumentElement()),
                 containerNode);
 
-    if (expectedNode != null)
-      junit.framework.Assert.assertEquals(expectedNode, built);
+    if (expectedNode != null) {
+        junit.framework.Assert.assertEquals(expectedNode, built);
+    }
 
     logger.info("{}", built);
 
@@ -372,14 +376,13 @@ public class NormalizedNodeXmlConverterTest {
     System.out.println(toString(doc.getDocumentElement()));
     System.out.println(toString(el));
 
-    boolean diff =
-        new Diff(
-            XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
-            XMLUnit.buildTestDocument(toString(el))).similar();
+    new Diff(
+        XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
+        XMLUnit.buildTestDocument(toString(el))).similar();
   }
 
 
-  private Document loadDocument(String xmlPath) throws Exception {
+  private Document loadDocument(final String xmlPath) throws Exception {
     InputStream resourceAsStream =
         NormalizedNodeXmlConverterTest.class.getResourceAsStream(xmlPath);
 
@@ -399,7 +402,7 @@ public class NormalizedNodeXmlConverterTest {
     BUILDERFACTORY = factory;
   }
 
-  private Document readXmlToDocument(InputStream xmlContent)
+  private Document readXmlToDocument(final InputStream xmlContent)
       throws IOException, SAXException {
     DocumentBuilder dBuilder;
     try {
@@ -413,7 +416,7 @@ public class NormalizedNodeXmlConverterTest {
     return doc;
   }
 
-  public static String toString(Element xml) {
+  public static String toString(final Element xml) {
     try {
       Transformer transformer =
           TransformerFactory.newInstance().newTransformer();
@@ -442,11 +445,10 @@ public class NormalizedNodeXmlConverterTest {
     System.out.println(toString(convertedDoc.getDocumentElement()));
     XMLUnit.setIgnoreWhitespace(true);
     XMLUnit.setIgnoreComments(true);
-    boolean diff =
-        new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
-            .getDocumentElement())),
-            XMLUnit.buildTestDocument(toString(convertedDoc
-                .getDocumentElement()))).similar();
+    new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
+        .getDocumentElement())),
+        XMLUnit.buildTestDocument(toString(convertedDoc
+            .getDocumentElement()))).similar();
     System.out.println(toString(expectedDoc.getDocumentElement()));
 
   }
@@ -464,11 +466,10 @@ public class NormalizedNodeXmlConverterTest {
     System.out.println(toString(convertedDoc.getDocumentElement()));
     XMLUnit.setIgnoreWhitespace(true);
     XMLUnit.setIgnoreComments(true);
-    boolean diff =
-        new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
-            .getDocumentElement())),
-            XMLUnit.buildTestDocument(toString(convertedDoc
-                .getDocumentElement()))).similar();
+    new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
+        .getDocumentElement())),
+        XMLUnit.buildTestDocument(toString(convertedDoc
+            .getDocumentElement()))).similar();
     System.out.println(toString(expectedDoc.getDocumentElement()));
 
     // now we will try to convert xml back to normalize node.
index 536d140cf1b78e05b7a3e77d38e43a32d8a1f8f4..ff4678d36fc507dfdf21794c452308fb71dbc3a1 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
@@ -17,8 +18,6 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
@@ -28,16 +27,20 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+
 import org.glassfish.jersey.server.ResourceConfig;
 import org.glassfish.jersey.test.JerseyTest;
 import org.junit.BeforeClass;
@@ -64,11 +67,16 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
 import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
 public class RestGetOperationTest extends JerseyTest {
 
     static class NodeData {
@@ -90,6 +98,8 @@ public class RestGetOperationTest extends JerseyTest {
     private static SchemaContext schemaContextModules;
     private static SchemaContext schemaContextBehindMountPoint;
 
+    private static final String RESTCONF_NS = "urn:ietf:params:xml:ns:yang:ietf-restconf";
+
     @BeforeClass
     public static void init() throws FileNotFoundException {
         schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs");
@@ -241,7 +251,7 @@ public class RestGetOperationTest extends JerseyTest {
         validateModulesResponseJson(response);
 
         response = target(uri).request("application/yang.api+xml").get();
-        validateModulesResponseXml(response);
+        validateModulesResponseXml(response,schemaContextModules);
     }
 
     // /streams/
@@ -257,9 +267,12 @@ public class RestGetOperationTest extends JerseyTest {
         assertTrue(responseBody.contains("streams"));
 
         response = target(uri).request("application/yang.api+xml").get();
-        responseBody = response.readEntity(String.class);
-        assertNotNull(responseBody);
-        assertTrue(responseBody.contains("<streams xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\""));
+        Document responseXmlBody = response.readEntity(Document.class);
+        assertNotNull(responseXmlBody);
+        Element rootNode = responseXmlBody.getDocumentElement();
+
+        assertEquals("streams", rootNode.getLocalName());
+        assertEquals(RESTCONF_NS, rootNode.getNamespaceURI());
     }
 
     // /modules/module
@@ -271,18 +284,23 @@ public class RestGetOperationTest extends JerseyTest {
 
         Response response = target(uri).request("application/yang.api+xml").get();
         assertEquals(200, response.getStatus());
-        String responseBody = response.readEntity(String.class);
-        assertTrue("Module2 in xml wasn't found", prepareXmlRegex("module2", "2014-01-02", "module:2", responseBody)
-                .find());
-        String[] split = responseBody.split("<module");
-        assertEquals("<module element is returned more then once", 2, split.length);
+        Document responseXml = response.readEntity(Document.class);
+
+
+
+        QName qname = assertedModuleXmlToModuleQName(responseXml.getDocumentElement());
+        assertNotNull(qname);
+
+        assertEquals("module2", qname.getLocalName());
+        assertEquals("module:2", qname.getNamespace().toString());
+        assertEquals("2014-01-02", qname.getFormattedRevision());
 
         response = target(uri).request("application/yang.api+json").get();
         assertEquals(200, response.getStatus());
-        responseBody = response.readEntity(String.class);
+        String responseBody = response.readEntity(String.class);
         assertTrue("Module2 in json wasn't found", prepareJsonRegex("module2", "2014-01-02", "module:2", responseBody)
                 .find());
-        split = responseBody.split("\"module\"");
+        String[] split = responseBody.split("\"module\"");
         assertEquals("\"module\" element is returned more then once", 2, split.length);
 
     }
@@ -296,19 +314,12 @@ public class RestGetOperationTest extends JerseyTest {
 
         Response response = target(uri).request("application/yang.api+xml").get();
         assertEquals(200, response.getStatus());
-        String responseBody = response.readEntity(String.class);
-        assertTrue("Xml response for /operations dummy-rpc1-module1 is incorrect",
-                validateOperationsResponseXml(responseBody, "dummy-rpc1-module1", "module:1").find());
-        assertTrue("Xml response for /operations dummy-rpc2-module1 is incorrect",
-                validateOperationsResponseXml(responseBody, "dummy-rpc2-module1", "module:1").find());
-        assertTrue("Xml response for /operations dummy-rpc1-module2 is incorrect",
-                validateOperationsResponseXml(responseBody, "dummy-rpc1-module2", "module:2").find());
-        assertTrue("Xml response for /operations dummy-rpc2-module2 is incorrect",
-                validateOperationsResponseXml(responseBody, "dummy-rpc2-module2", "module:2").find());
+        Document responseDoc = response.readEntity(Document.class);
+        validateOperationsResponseXml(responseDoc, schemaContextModules);
 
         response = target(uri).request("application/yang.api+json").get();
         assertEquals(200, response.getStatus());
-        responseBody = response.readEntity(String.class);
+        String responseBody = response.readEntity(String.class);
         assertTrue("Json response for /operations dummy-rpc1-module1 is incorrect",
                 validateOperationsResponseJson(responseBody, "dummy-rpc1-module1", "module1").find());
         assertTrue("Json response for /operations dummy-rpc2-module1 is incorrect",
@@ -320,6 +331,30 @@ public class RestGetOperationTest extends JerseyTest {
 
     }
 
+    private void validateOperationsResponseXml(final Document responseDoc, final SchemaContext schemaContext) {
+        Element operationsElem = responseDoc.getDocumentElement();
+        assertEquals(RESTCONF_NS, operationsElem.getNamespaceURI());
+        assertEquals("operations", operationsElem.getLocalName());
+
+
+        HashSet<QName> foundOperations = new HashSet<>();
+
+        NodeList operationsList = operationsElem.getChildNodes();
+        for(int i = 0;i < operationsList.getLength();i++) {
+            org.w3c.dom.Node operation = operationsList.item(i);
+
+            String namespace = operation.getNamespaceURI();
+            String name = operation.getLocalName();
+            QName opQName = QName.create(URI.create(namespace), null, name);
+            foundOperations.add(opQName);
+        }
+
+        for(RpcDefinition schemaOp : schemaContext.getOperations()) {
+            assertTrue(foundOperations.contains(schemaOp.getQName().withoutRevision()));
+        }
+
+    }
+
     // /operations/pathToMountPoint/yang-ext:mount
     @Test
     public void getOperationsBehindMountPointTest() throws FileNotFoundException, UnsupportedEncodingException {
@@ -337,15 +372,13 @@ public class RestGetOperationTest extends JerseyTest {
 
         Response response = target(uri).request("application/yang.api+xml").get();
         assertEquals(200, response.getStatus());
-        String responseBody = response.readEntity(String.class);
-        assertTrue("Xml response for /operations/mount_point rpc-behind-module1 is incorrect",
-                validateOperationsResponseXml(responseBody, "rpc-behind-module1", "module:1:behind:mount:point").find());
-        assertTrue("Xml response for /operations/mount_point rpc-behind-module2 is incorrect",
-                validateOperationsResponseXml(responseBody, "rpc-behind-module2", "module:2:behind:mount:point").find());
+
+        Document responseDoc = response.readEntity(Document.class);
+        validateOperationsResponseXml(responseDoc, schemaContextBehindMountPoint);
 
         response = target(uri).request("application/yang.api+json").get();
         assertEquals(200, response.getStatus());
-        responseBody = response.readEntity(String.class);
+        String responseBody = response.readEntity(String.class);
         assertTrue("Json response for /operations/mount_point rpc-behind-module1 is incorrect",
                 validateOperationsResponseJson(responseBody, "rpc-behind-module1", "module1-behind-mount-point").find());
         assertTrue("Json response for /operations/mount_point rpc-behind-module2 is incorrect",
@@ -441,15 +474,7 @@ public class RestGetOperationTest extends JerseyTest {
 
         response = target(uri).request("application/yang.api+xml").get();
         assertEquals(200, response.getStatus());
-        responseBody = response.readEntity(String.class);
-        assertTrue(
-                "module1-behind-mount-point in json wasn't found",
-                prepareXmlRegex("module1-behind-mount-point", "2014-02-03", "module:1:behind:mount:point", responseBody)
-                        .find());
-        assertTrue(
-                "module2-behind-mount-point in json wasn't found",
-                prepareXmlRegex("module2-behind-mount-point", "2014-02-04", "module:2:behind:mount:point", responseBody)
-                        .find());
+        validateModulesResponseXml(response, schemaContextBehindMountPoint);
 
     }
 
@@ -481,26 +506,83 @@ public class RestGetOperationTest extends JerseyTest {
 
         response = target(uri).request("application/yang.api+xml").get();
         assertEquals(200, response.getStatus());
-        responseBody = response.readEntity(String.class);
-        assertTrue(
-                "module1-behind-mount-point in json wasn't found",
-                prepareXmlRegex("module1-behind-mount-point", "2014-02-03", "module:1:behind:mount:point", responseBody)
-                        .find());
-        split = responseBody.split("<module");
-        assertEquals("<module element is returned more then once", 2, split.length);
+        Document responseXml = response.readEntity(Document.class);
+
+        QName module = assertedModuleXmlToModuleQName(responseXml.getDocumentElement());
+
+        assertEquals("module1-behind-mount-point", module.getLocalName());
+        assertEquals("2014-02-03", module.getFormattedRevision());
+        assertEquals("module:1:behind:mount:point", module.getNamespace().toString());
+
 
     }
 
-    private void validateModulesResponseXml(final Response response) {
+    private void validateModulesResponseXml(final Response response, final SchemaContext schemaContext) {
         assertEquals(200, response.getStatus());
-        String responseBody = response.readEntity(String.class);
+        Document responseBody = response.readEntity(Document.class);
+        NodeList moduleNodes = responseBody.getDocumentElement().getElementsByTagNameNS(RESTCONF_NS, "module");
 
-        assertTrue("Module1 in xml wasn't found", prepareXmlRegex("module1", "2014-01-01", "module:1", responseBody)
-                .find());
-        assertTrue("Module2 in xml wasn't found", prepareXmlRegex("module2", "2014-01-02", "module:2", responseBody)
-                .find());
-        assertTrue("Module3 in xml wasn't found", prepareXmlRegex("module3", "2014-01-03", "module:3", responseBody)
-                .find());
+        assertTrue(moduleNodes.getLength() > 0);
+
+        HashSet<QName> foundModules = new HashSet<>();
+
+        for(int i=0;i < moduleNodes.getLength();i++) {
+            org.w3c.dom.Node module = moduleNodes.item(i);
+
+            QName name = assertedModuleXmlToModuleQName(module);
+            foundModules.add(name);
+        }
+
+        assertAllModules(foundModules,schemaContext);
+    }
+
+    private void assertAllModules(final Set<QName> foundModules, final SchemaContext schemaContext) {
+        for(Module module : schemaContext.getModules()) {
+            QName current = QName.create(module.getQNameModule(),module.getName());
+            assertTrue("Module not found in response.",foundModules.contains(current));
+        }
+
+    }
+
+    private QName assertedModuleXmlToModuleQName(final org.w3c.dom.Node module) {
+        assertEquals("module", module.getLocalName());
+        assertEquals(RESTCONF_NS, module.getNamespaceURI());
+        String revision = null;
+        String namespace = null;
+        String name = null;
+
+
+        NodeList childNodes = module.getChildNodes();
+
+        for(int i =0;i < childNodes.getLength(); i++) {
+            org.w3c.dom.Node child = childNodes.item(i);
+            assertEquals(RESTCONF_NS, child.getNamespaceURI());
+
+            switch(child.getLocalName()) {
+                case "name":
+                    assertNull("Name element appeared multiple times",name);
+                    name = child.getTextContent().trim();
+                    break;
+                case "revision":
+                    assertNull("Revision element appeared multiple times",revision);
+                    revision = child.getTextContent().trim();
+                    break;
+
+                case "namespace":
+                    assertNull("Namespace element appeared multiple times",namespace);
+                    namespace = child.getTextContent().trim();
+                    break;
+            }
+        }
+
+        assertNotNull("Revision was not part of xml",revision);
+        assertNotNull("Module namespace was not part of xml",namespace);
+        assertNotNull("Module identiffier was not part of xml",name);
+
+
+        // TODO Auto-generated method stub
+
+        return QName.create(namespace,revision,name);
     }
 
     private void validateModulesResponseJson(final Response response) {
@@ -542,34 +624,6 @@ public class RestGetOperationTest extends JerseyTest {
 
     }
 
-    private Matcher prepareXmlRegex(final String module, final String revision, final String namespace,
-            final String searchIn) {
-        StringBuilder regex = new StringBuilder();
-        regex.append("^");
-
-        regex.append(".*<module.*");
-        regex.append(".*>");
-
-        regex.append(".*<name>");
-        regex.append(".*" + module);
-        regex.append(".*<\\/name>");
-
-        regex.append(".*<revision>");
-        regex.append(".*" + revision);
-        regex.append(".*<\\/revision>");
-
-        regex.append(".*<namespace>");
-        regex.append(".*" + namespace);
-        regex.append(".*<\\/namespace>");
-
-        regex.append(".*<\\/module.*>");
-
-        regex.append(".*");
-        regex.append("$");
-
-        Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
-        return ptrn.matcher(searchIn);
-    }
 
     private void prepareMockForModulesTest(final ControllerContext mockedControllerContext)
             throws FileNotFoundException {
@@ -626,7 +680,7 @@ public class RestGetOperationTest extends JerseyTest {
         getDataWithUriIncludeWhiteCharsParameter("operational");
     }
 
-    private void getDataWithUriIncludeWhiteCharsParameter(String target) throws UnsupportedEncodingException {
+    private void getDataWithUriIncludeWhiteCharsParameter(final String target) throws UnsupportedEncodingException {
         mockReadConfigurationDataMethod();
         String uri = "/" + target + "/ietf-interfaces:interfaces/interface/eth0";
         Response response = target(uri).queryParam("prettyPrint", "false").request("application/xml").get();
index 723e484c9c456eee6dfed86a8805cd1fcf624781..e9383886eaac79f2462ff262bf6097789142205d 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.controller.netconf.cli.commands.local;
 
-import com.google.common.collect.Lists;
 import org.opendaylight.controller.netconf.cli.NetconfDeviceConnectionManager;
 import org.opendaylight.controller.netconf.cli.commands.AbstractCommand;
 import org.opendaylight.controller.netconf.cli.commands.Command;
@@ -21,6 +20,8 @@ import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
 import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 
+import com.google.common.collect.Lists;
+
 /**
  * Local disconnect command
  */
@@ -40,7 +41,7 @@ public class Disconnect extends AbstractCommand {
         connectionManager.disconnect();
 
         return new Output(new CompositeNodeTOImpl(getCommandId(), null,
-                Lists.<Node<?>> newArrayList(new SimpleNodeTOImpl<>(new QName(getCommandId(), "status"), null,
+                Lists.<Node<?>> newArrayList(new SimpleNodeTOImpl<>(QName.create(getCommandId(), "status"), null,
                         "Connection disconnected"))));
     }
 
index 2021bf722c5390560e2860f334563c34323d6815..5a2445279b4df24214d0c998f8fa78ba6f17d3a2 100644 (file)
@@ -7,20 +7,23 @@
  */
 package org.opendaylight.controller.netconf.cli.io;
 
-import com.google.common.collect.Maps;
 import java.util.Map;
+
 import junit.framework.Assert;
+
 import org.junit.Test;
 import org.opendaylight.controller.netconf.cli.commands.CommandConstants;
 import org.opendaylight.yangtools.yang.common.QName;
 
+import com.google.common.collect.Maps;
+
 public class IOUtilTest {
 
     @Test
     public void testQNameFromKeyStringNew() throws Exception {
         final String s = IOUtil.qNameToKeyString(CommandConstants.HELP_QNAME, "module");
         final Map<String, QName> modulesMap = Maps.newHashMap();
-        modulesMap.put("module", new QName(CommandConstants.HELP_QNAME, "module"));
+        modulesMap.put("module", QName.create(CommandConstants.HELP_QNAME, "module"));
         final QName qName = IOUtil.qNameFromKeyString(s, modulesMap);
         Assert.assertEquals(CommandConstants.HELP_QNAME, qName);
     }