Use AsyncResponse in RPC invocation path
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / TestRestconfUtils.java
index 86a36649bb397f6804d7d1c2ac331a88ec02cbbf..39d4292d1806e6356311ac68425cb8fb5c6b80f1 100644 (file)
@@ -5,10 +5,8 @@
  * 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.restconf.nb.rfc8040;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -18,6 +16,7 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Optional;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
@@ -33,10 +32,11 @@ import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,7 +52,8 @@ public final class TestRestconfUtils {
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public static SchemaContext loadSchemaContext(final String yangPath, final SchemaContext schemaContext) {
+    public static EffectiveModelContext loadSchemaContext(final String yangPath,
+            final EffectiveModelContext schemaContext) {
         try {
             Preconditions.checkArgument(yangPath != null, "Path can not be null.");
             Preconditions.checkArgument(!yangPath.isEmpty(), "Path can not be empty.");
@@ -73,13 +74,13 @@ public final class TestRestconfUtils {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile,
-            final String uri, final SchemaContext schemaContext) {
+            final String uri, final EffectiveModelContext schemaContext) {
         final InstanceIdentifierContext<?> iiContext =
-                ParserIdentifier.toInstanceIdentifier(uri, schemaContext, Optional.absent());
+                ParserIdentifier.toInstanceIdentifier(uri, schemaContext, Optional.empty());
         final InputStream inputStream = TestRestconfUtils.class.getResourceAsStream(pathToInputFile);
         try {
             final Document doc = UntrustedXML.newDocumentBuilder().parse(inputStream);
-            final NormalizedNode<?, ?> nn = parse(iiContext, doc);
+            final NormalizedNode nn = parse(iiContext, doc);
             return new NormalizedNodeContext(iiContext, nn);
         } catch (final Exception e) {
             LOG.error("Load xml file " + pathToInputFile + " fail.", e);
@@ -87,7 +88,7 @@ public final class TestRestconfUtils {
         return null;
     }
 
-    private static NormalizedNode<?, ?> parse(final InstanceIdentifierContext<?> iiContext, final Document doc)
+    private static NormalizedNode parse(final InstanceIdentifierContext<?> iiContext, final Document doc)
             throws XMLStreamException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
         final SchemaNode schemaNodeContext = iiContext.getSchemaNode();
         DataSchemaNode schemaNode = null;
@@ -110,8 +111,7 @@ public final class TestRestconfUtils {
         final String schemaNodeName = iiContext.getSchemaNode().getQName().getLocalName();
 
         if (!schemaNodeName.equalsIgnoreCase(docRootElm)) {
-            final Collection<DataSchemaNode> children = ((DataNodeContainer) schemaNode).getChildNodes();
-            for (final DataSchemaNode child : children) {
+            for (final DataSchemaNode child : ((DataNodeContainer) schemaNode).getChildNodes()) {
                 if (child.getQName().getLocalName().equalsIgnoreCase(docRootElm)) {
                     schemaNode = child;
                     break;
@@ -121,7 +121,8 @@ public final class TestRestconfUtils {
 
         final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
-        final XmlParserStream xmlParser = XmlParserStream.create(writer, iiContext.getSchemaContext(), schemaNode);
+        final XmlParserStream xmlParser = XmlParserStream.create(writer,
+            SchemaInferenceStack.ofInstantiatedPath(iiContext.getSchemaContext(), schemaNode.getPath()).toInference());
 
         if (schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode) {
             xmlParser.traverse(new DOMSource(doc.getDocumentElement()));