Merge "fix failure during connecting device when channelActive happens later than...
[netconf.git] / netconf / mdsal-netconf-connector / src / test / java / org / opendaylight / netconf / mdsal / connector / ops / get / FilterContentValidatorTest.java
index c3656cfd4c4dcc9de769eb7285bd74290e950af9..04a3a1414cbab3527945cee77f056c29cc9b32fc 100644 (file)
@@ -11,9 +11,6 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
 import com.google.common.base.Preconditions;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -31,15 +28,14 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.model.InitializationError;
-import org.opendaylight.controller.config.util.xml.XmlElement;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.netconf.api.xml.XmlElement;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
 
 @RunWith(value = Parameterized.class)
 public class FilterContentValidatorTest {
@@ -54,7 +50,7 @@ public class FilterContentValidatorTest {
     private FilterContentValidator validator;
 
     @Parameterized.Parameters
-    public static Collection<Object[]> data() throws IOException, SAXException, URISyntaxException, InitializationError {
+    public static Collection<Object[]> data() throws Exception {
         final List<Object[]> result = new ArrayList<>();
         final Path path = Paths.get(FilterContentValidatorTest.class.getResource("/filter/expected.txt").toURI());
         final List<String> expected = Files.readAllLines(path);
@@ -62,8 +58,9 @@ public class FilterContentValidatorTest {
             throw new InitializationError("Number of lines in results file must be same as test case count");
         }
         for (int i = 1; i <= TEST_CASE_COUNT; i++) {
-            final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class.getResourceAsStream("/filter/f" + i + ".xml"));
-            result.add(new Object[]{document, expected.get(i-1)});
+            final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class.getResourceAsStream(
+                    "/filter/f" + i + ".xml"));
+            result.add(new Object[]{document, expected.get(i - 1)});
         }
         return result;
     }
@@ -75,22 +72,22 @@ public class FilterContentValidatorTest {
 
     @Before
     public void setUp() throws Exception {
-        final List<InputStream> sources = new ArrayList<>();
-        sources.add(getClass().getResourceAsStream("/yang/filter-validator-test-mod-0.yang"));
-        sources.add(getClass().getResourceAsStream("/yang/filter-validator-test-augment.yang"));
-        final SchemaContext context = YangParserTestUtils.parseYangStreams(sources);
+        final SchemaContext context = YangParserTestUtils.parseYangResources(FilterContentValidatorTest.class,
+            "/yang/filter-validator-test-mod-0.yang", "/yang/filter-validator-test-augment.yang",
+            "/yang/mdsal-netconf-mapping-test.yang");
+
         final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
         doReturn(context).when(currentContext).getCurrentContext();
         validator = new FilterContentValidator(currentContext);
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Test
     public void testValidate() throws Exception {
         if (expected.startsWith("success")) {
             final String expId = expected.replace("success=", "");
             final YangInstanceIdentifier actual = validator.validate(filterContent);
-            final YangInstanceIdentifier expected = fromString(expId);
-            Assert.assertEquals(expected, actual);
+            Assert.assertEquals(fromString(expId), actual);
         } else if (expected.startsWith("error")) {
             try {
                 validator.validate(filterContent);
@@ -141,12 +138,11 @@ public class FilterContentValidatorTest {
         return prev;
     }
 
-    private static QName createNodeQName(final QName prev, final String qNameString) {
-        final QName qName = QName.create(qNameString);
-        if (qName.getModule().getNamespace() != null) {
-            return qName;
-        } else {
-            return QName.create(Preconditions.checkNotNull(prev), qNameString);
+    private static QName createNodeQName(final QName prev, final String input) {
+        try {
+            return QName.create(input);
+        } catch (IllegalArgumentException e) {
+            return QName.create(Preconditions.checkNotNull(prev), input);
         }
     }
 }