Fix testtool GetSchema broken since v1.6.0 13/82913/2
authorEliezio Oliveira <eliezio.oliveira@est.tech>
Mon, 1 Jul 2019 16:53:52 +0000 (17:53 +0100)
committerEliezio Oliveira <eliezio.oliveira@est.tech>
Thu, 4 Jul 2019 11:49:23 +0000 (12:49 +0100)
Offending commit: af7babe

Change-Id: Ia43cdcf10b54d9528921675fed321665771bd667
JIRA: NETCONF-624
Signed-off-by: Eliezio Oliveira <eliezio.oliveira@est.tech>
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/package-info.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/test/java/org/opendaylight/netconf/test/tool/TestToolTest.java

diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/package-info.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/package-info.java
new file mode 100644 (file)
index 0000000..e65ec07
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+@XmlSchema(
+        elementFormDefault = XmlNsForm.QUALIFIED,
+        xmlns = {
+                @XmlNs(namespaceURI = MonitoringConstants.EXTENSION_NAMESPACE, prefix =
+                        MonitoringConstants.EXTENSION_NAMESPACE_PREFIX),
+                @XmlNs(namespaceURI = MonitoringConstants.NAMESPACE, prefix = "")
+        },
+        namespace = MonitoringConstants.NAMESPACE
+)
+package org.opendaylight.netconf.test.tool.monitoring;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
index c821ad6990fa61be9df42b45d1fb5f9d6728349d..f72671c20e5e8405d3fbdeb064afa68a05c25388 100644 (file)
@@ -11,12 +11,15 @@ package org.opendaylight.netconf.test.tool;
 import static org.junit.Assert.assertNotNull;
 import static org.xmlunit.assertj.XmlAssert.assertThat;
 
+import com.google.common.collect.ImmutableMap;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.concurrent.DefaultThreadFactory;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.io.File;
 import java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
@@ -39,6 +42,7 @@ import org.opendaylight.netconf.nettyutil.NeverReconnectStrategy;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler;
 import org.opendaylight.netconf.test.tool.config.Configuration;
 import org.opendaylight.netconf.test.tool.config.ConfigurationBuilder;
+import org.opendaylight.netconf.test.tool.config.YangResource;
 import org.w3c.dom.Document;
 
 @SuppressWarnings("SameParameterValue")
@@ -92,6 +96,10 @@ public class TestToolTest {
         + "    2014-07-29T13:42:12Z\n"
         + "  </reset-finished-at>\n"
         + "</rpc-reply>";
+    private static final Map<String, String> PREFIX_2_URI = ImmutableMap.of(
+        "base10", "urn:ietf:params:xml:ns:netconf:base:1.0",
+        "ncmon", "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"
+    );
 
     @BeforeClass
     public static void setUpClass() {
@@ -126,6 +134,27 @@ public class TestToolTest {
             .areIdentical();
     }
 
+    @Test
+    public void shouldSupportGetSchema()
+        throws Exception {
+        String getSchema = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"m-0\">\n"
+            + "  <get>\n"
+            + "    <filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n"
+            + "      <netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
+            + "        <schemas/>\n"
+            + "      </netconf-state>\n"
+            + "    </filter>\n"
+            + "  </get>\n"
+            + "</rpc>";
+        Document docResponse = invokeRpc(TCP_SIMULATOR_CONFIG, getSchema);
+        Set<YangResource> expectedYangResources = Configuration.DEFAULT_YANG_RESOURCES;
+        assert expectedYangResources.size() > 0;
+        assertThat(docResponse)
+            .withNamespaceContext(PREFIX_2_URI)
+            .valueByXPath("count(//base10:rpc-reply/base10:data/ncmon:netconf-state/ncmon:schemas/ncmon:schema)")
+            .isEqualTo(expectedYangResources.size());
+    }
+
     private Document invokeRpc(Configuration simulatorConfig, String xmlRequest)
         throws Exception {
         // GIVEN