Bug 7159: Add yang-test-util artifact
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codec / xml / Bug2964Test.java
index 3cf1b9b6a16c5755d08b123f88b29086c5a855fd..8cfc79f2920c08a92ea80358e275e0aa06ba571c 100644 (file)
@@ -1,8 +1,26 @@
+/*
+ * Copyright (c) 2016 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
+ */
+
 package org.opendaylight.yangtools.yang.data.impl.codec.xml;
 
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.io.ByteSource;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -12,28 +30,15 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 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 java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
 public class Bug2964Test {
 
-    public static final String XML_CONTENT = "<cont2 xmlns=\"urn:opendaylight:yangtools:leafref:test\">\n" +
-            "<point-to-identityrefleaf>test-identity</point-to-identityrefleaf>\n" +
-            "</cont2>";
+    public static final String XML_CONTENT = "<cont2 xmlns=\"urn:opendaylight:yangtools:leafref:test\">\n"
+            + "<point-to-identityrefleaf>test-identity</point-to-identityrefleaf>\n" + "</cont2>";
 
     private static final DocumentBuilderFactory BUILDERFACTORY;
 
@@ -55,17 +60,12 @@ public class Bug2964Test {
 
     @Before
     public void setUp() throws Exception {
-        final ByteSource byteSource = new ByteSource() {
-            @Override
-            public InputStream openStream() throws IOException {
-                return Bug2964Test.this.getClass().getResourceAsStream("/leafref-test.yang");
-            }
-        };
-        schema = new YangParserImpl().parseSources(Lists.newArrayList(byteSource));
+        final File leafRefTestYang = new File(getClass().getResource("/leafref-test.yang").toURI());
+        schema = YangParserTestUtils.parseYangSources(leafRefTestYang);
     }
 
     public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException {
-        return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8)));
+        return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8)));
     }
 
     @Test
@@ -75,10 +75,11 @@ public class Bug2964Test {
         final Document document = readXmlToDocument(XML_CONTENT);
         final Element identityLeafRefElement = (Element) document.getDocumentElement().getFirstChild().getNextSibling();
 
-        final Module leafrefModule = schema.findModuleByNamespaceAndRevision(
-                namespaceUri, null);
-        final ContainerSchemaNode cont2 = (ContainerSchemaNode) leafrefModule.getDataChildByName(CONT_2);
-        final DataSchemaNode identityLeafRefSchema = cont2.getDataChildByName(IDENTITY_LEAFREF);
+        final Module leafrefModule = schema.findModuleByNamespaceAndRevision(namespaceUri, null);
+        final ContainerSchemaNode cont2 = (ContainerSchemaNode) leafrefModule.getDataChildByName(QName.create(
+                leafrefModule.getQNameModule(), CONT_2));
+        final DataSchemaNode identityLeafRefSchema = cont2.getDataChildByName(QName.create(
+                leafrefModule.getQNameModule(), IDENTITY_LEAFREF));
         final Object parsedValue = DomUtils.parseXmlValue(identityLeafRefElement, DomUtils.defaultValueCodecProvider(),
                 identityLeafRefSchema, ((LeafSchemaNode) identityLeafRefSchema).getType(), schema);