Reduce use of getChildByName()
[yangtools.git] / yang / yang-data-codec-xml / src / test / java / org / opendaylight / yangtools / yang / data / codec / xml / Bug5396Test.java
index 938962e75e08324037c03cf7b1e7abfbcb70bbb1..c26c2d69cd985c00f7c62a7c0ca7d4f2cea68c5d 100644 (file)
@@ -5,7 +5,6 @@
  * 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.codec.xml;
 
 import static org.junit.Assert.assertEquals;
@@ -13,16 +12,16 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import java.net.URI;
-import javax.xml.stream.XMLInputFactory;
+import java.util.Optional;
 import javax.xml.stream.XMLStreamReader;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -43,10 +42,8 @@ public class Bug5396Test {
 
     @Before
     public void setUp() throws Exception {
-        fooModuleQName = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse(
-                    "2016-03-22"));
-
-        schemaContext = YangParserTestUtils.parseYangSource("/bug5396/yang/foo.yang");
+        fooModuleQName = QNameModule.create(new URI("foo"), Revision.of("2016-03-22"));
+        schemaContext = YangParserTestUtils.parseYangResource("/bug5396/yang/foo.yang");
     }
 
     @Test
@@ -68,12 +65,10 @@ public class Bug5396Test {
     private void testInputXML(final String xmlPath, final String expectedValue) throws Exception {
         final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(xmlPath);
         final Module fooModule = schemaContext.getModules().iterator().next();
-        final ContainerSchemaNode rootCont = (ContainerSchemaNode) fooModule.getDataChildByName(
-                QName.create(fooModule.getQNameModule(), "root"));
-        assertNotNull(rootCont);
+        final ContainerSchemaNode rootCont = (ContainerSchemaNode) fooModule.findDataChildByName(
+                QName.create(fooModule.getQNameModule(), "root")).get();
 
-        final XMLInputFactory factory = XMLInputFactory.newInstance();
-        final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+        final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
 
@@ -88,7 +83,7 @@ public class Bug5396Test {
 
         Optional<DataContainerChild<? extends PathArgument, ?>> myLeaf = rootContainer.getChild(new NodeIdentifier(
                 QName.create(fooModuleQName, "my-leaf")));
-        assertTrue(myLeaf.orNull() instanceof LeafNode);
+        assertTrue(myLeaf.orElse(null) instanceof LeafNode);
 
         assertEquals(expectedValue, myLeaf.get().getValue());
     }