Deprecate NormalizedNodeContext 88/98088/5
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 23 Oct 2021 18:58:54 +0000 (20:58 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 23 Oct 2021 23:12:49 +0000 (01:12 +0200)
Create a simplistic fork of this structure, allowing us to disconnect
from bierman02 for further evolution.

JIRA: NETCONF-773
Change-Id: Ib1f79489c85a61c7f14e6d5c040dee5b7e89b129
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
17 files changed:
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/context/NormalizedNodeContext.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/legacy/NormalizedNodePayload.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestRestconfUtils.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/Netconf799Test.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtilTest.java

index a4348b458ef4ab93325697f5990d0777784f03b7..54a65b958ba986a1c2382fa42a1816b58bfa43ec 100644 (file)
@@ -13,6 +13,8 @@ import com.google.common.collect.ImmutableMap;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
+@Deprecated(forRemoval = true, since = "2.0.6")
+// Non-final for mocking
 public class NormalizedNodeContext {
     private final InstanceIdentifierContext<? extends SchemaNode> context;
     private final ImmutableMap<String, Object> headers;
index 346e6e03a285bcec8188d4df58f7dd44e01f50e7..b7884d31a5eedfc3c87de681d11da74f22bbf82a 100644 (file)
@@ -10,24 +10,30 @@ package org.opendaylight.restconf.nb.rfc8040.legacy;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableMap;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.net.URI;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
 /**
- * A RFC8040 overlay over {@link NormalizedNodeContext}. This represents a NormalizedNode along with further messy
- * details needed to deal with the payload.
+ * A RFC8040 overlay from our marriage to NormalizedNodeContext. This represents a NormalizedNode along with further
+ * messy details needed to deal with the payload.
  */
-public final class NormalizedNodePayload extends NormalizedNodeContext {
+public final class NormalizedNodePayload {
+    private final InstanceIdentifierContext<?> context;
+    private final ImmutableMap<String, Object> headers;
+    private final QueryParameters writerParameters;
+    private final NormalizedNode data;
+
     private NormalizedNodePayload(final InstanceIdentifierContext<?> context,
             final NormalizedNode data, final QueryParameters writerParameters,
             final ImmutableMap<String, Object> headers) {
-        super(context, data, writerParameters, headers);
+        this.context = context;
+        this.data = data;
+        this.writerParameters = requireNonNull(writerParameters);
+        this.headers = requireNonNull(headers);
     }
 
     public static @NonNull NormalizedNodePayload empty(final InstanceIdentifierContext<?> path) {
@@ -51,9 +57,30 @@ public final class NormalizedNodePayload extends NormalizedNodeContext {
             QueryParameters.empty(), ImmutableMap.of("Location", location));
     }
 
-    @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "Ensured via constructor")
-    @Override
+    public static Object ofReadData(final InstanceIdentifierContext<?> path, final NormalizedNode data,
+            final QueryParameters parameters) {
+        return new NormalizedNodePayload(requireNonNull(path), requireNonNull(data), parameters, ImmutableMap.of());
+    }
+
+    public InstanceIdentifierContext<?> getInstanceIdentifierContext() {
+        return context;
+    }
+
+    public NormalizedNode getData() {
+        return data;
+    }
+
+    /**
+     * Return headers response headers.
+     *
+     * @return map of headers
+     */
+    // FIXME: this is only used for redirect on subscribe
+    public ImmutableMap<String, Object> getNewHeaders() {
+        return headers;
+    }
+
     public QueryParameters getWriterParameters() {
-        return (QueryParameters) super.getWriterParameters();
+        return writerParameters;
     }
 }
index 848aa328a0f5b8c4436419c100fcbdf7727b310d..e397c78fc82ab6a207b030fe33261818a20bda86 100644 (file)
@@ -16,8 +16,8 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
@@ -97,7 +97,7 @@ final class CreateStreamUtil {
      *     }
      *     </pre>
      */
-    static DOMRpcResult createDataChangeNotifiStream(final NormalizedNodeContext payload,
+    static DOMRpcResult createDataChangeNotifiStream(final NormalizedNodePayload payload,
             final EffectiveModelContext refSchemaCtx) {
         // parsing out of container with settings and path
         final ContainerNode data = (ContainerNode) requireNonNull(payload).getData();
index 47d288ef408495745821d85b2f2963f2091dbb57..36056992fc62f6b653b28957ff45cfbd78e7b6ce 100644 (file)
@@ -48,7 +48,6 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
@@ -187,14 +186,14 @@ public class RestconfDataServiceImpl implements RestconfDataService {
             case CONFIG:
                 final QName type = node.getIdentifier().getNodeType();
                 return Response.status(Status.OK)
-                    .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
+                    .entity(NormalizedNodePayload.ofReadData(instanceIdentifier, node, parameters))
                     .header("ETag", '"' + type.getModule().getRevision().map(Revision::toString).orElse(null)
                         + "-" + type.getLocalName() + '"')
                     .header("Last-Modified", FORMATTER.format(LocalDateTime.now(Clock.systemUTC())))
                     .build();
             default:
                 return Response.status(Status.OK)
-                    .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
+                    .entity(NormalizedNodePayload.ofReadData(instanceIdentifier, node, parameters))
                     .build();
         }
     }
@@ -381,10 +380,10 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     /**
      * Invoke Action operation.
      *
-     * @param payload {@link NormalizedNodeContext} - the body of the operation
-     * @return {@link NormalizedNodeContext} wrapped in {@link Response}
+     * @param payload {@link NormalizedNodePayload} - the body of the operation
+     * @return {@link NormalizedNodePayload} wrapped in {@link Response}
      */
-    public Response invokeAction(final NormalizedNodeContext payload) {
+    public Response invokeAction(final NormalizedNodePayload payload) {
         final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
         final DOMMountPoint mountPoint = context.getMountPoint();
         final Absolute schemaPath = Absolute.of(ImmutableList.copyOf(context.getSchemaNode().getPath()
@@ -423,7 +422,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         }
 
         return Response.status(Status.OK)
-            .entity(new NormalizedNodeContext(
+            .entity(NormalizedNodePayload.ofNullable(
                 new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef),
                 resultData))
             .build();
@@ -495,7 +494,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
      * @param payload    input data
      */
     @VisibleForTesting
-    public static void validInputData(final SchemaNode schemaNode, final NormalizedNodeContext payload) {
+    public static void validInputData(final SchemaNode schemaNode, final NormalizedNodePayload payload) {
         if (schemaNode != null && payload.getData() == null) {
             throw new RestconfDocumentedException("Input is required.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
         } else if (schemaNode == null && payload.getData() != null) {
@@ -510,7 +509,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
      * @param payload data
      */
     @VisibleForTesting
-    public static void validTopLevelNodeName(final YangInstanceIdentifier path, final NormalizedNodeContext payload) {
+    public static void validTopLevelNodeName(final YangInstanceIdentifier path, final NormalizedNodePayload payload) {
         final QName dataNodeType = payload.getData().getIdentifier().getNodeType();
         if (path.isEmpty()) {
             if (!NETCONF_BASE_QNAME.equals(dataNodeType)) {
@@ -536,7 +535,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
      * @throws RestconfDocumentedException if key values or key count in payload and URI isn't equal
      */
     @VisibleForTesting
-    public static void validateListKeysEqualityInPayloadAndUri(final NormalizedNodeContext payload) {
+    public static void validateListKeysEqualityInPayloadAndUri(final NormalizedNodePayload payload) {
         final InstanceIdentifierContext<?> iiWithData = payload.getInstanceIdentifierContext();
         final PathArgument lastPathArgument = iiWithData.getInstanceIdentifier().getLastPathArgument();
         final SchemaNode schemaNode = iiWithData.getSchemaNode();
index f2c70e8e268ea0f89fb03c986413b737ed0898da..3d0e8aa9b8f2b394740ac3be97292817588259c5 100644 (file)
@@ -31,7 +31,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
@@ -116,7 +115,7 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
                 if (resultData == null || ((ContainerNode) resultData).isEmpty()) {
                     ar.resume(new WebApplicationException(Status.NO_CONTENT));
                 } else {
-                    ar.resume(new NormalizedNodeContext(new InstanceIdentifierContext<>(null, (RpcDefinition) schema,
+                    ar.resume(NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, (RpcDefinition) schema,
                         mountPoint, schemaContextRef), resultData));
                 }
             }
index 39d4292d1806e6356311ac68425cb8fb5c6b80f1..e2f408a15424c3fa341b9af8c351bee4031844b8 100644 (file)
@@ -21,7 +21,7 @@ import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -68,12 +68,8 @@ public final class TestRestconfUtils {
         return schemaContext;
     }
 
-    public static NormalizedNodeContext loadNormalizedContextFromJsonFile() {
-        throw new AbstractMethodError("Not implemented yet");
-    }
-
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile,
+    public static NormalizedNodePayload loadNormalizedContextFromXmlFile(final String pathToInputFile,
             final String uri, final EffectiveModelContext schemaContext) {
         final InstanceIdentifierContext<?> iiContext =
                 ParserIdentifier.toInstanceIdentifier(uri, schemaContext, Optional.empty());
@@ -81,7 +77,7 @@ public final class TestRestconfUtils {
         try {
             final Document doc = UntrustedXML.newDocumentBuilder().parse(inputStream);
             final NormalizedNode nn = parse(iiContext, doc);
-            return new NormalizedNodeContext(iiContext, nn);
+            return NormalizedNodePayload.of(iiContext, nn);
         } catch (final Exception e) {
             LOG.error("Load xml file " + pathToInputFile + " fail.", e);
         }
index b525ecb698bd1b08583451d27cedc483194317d9..7680495c453adbfab3c2f05325816793a96d458c 100644 (file)
@@ -20,12 +20,12 @@ import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -51,7 +51,7 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
     public XmlBodyReaderMountPointTest() throws Exception {
         super(schemaContext);
-        this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+        xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
     }
 
     @Override
@@ -71,13 +71,11 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final DataSchemaNode dataSchemaNode = schemaContext
                 .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
         final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
-        mockBodyReader(uri, this.xmlBodyReader, false);
-        final InputStream inputStream = XmlBodyReaderMountPointTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
-                null, null, this.mediaType, null, inputStream);
-        checkMountPointNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
+        mockBodyReader(uri, xmlBodyReader, false);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xmldata.xml"));
+        checkMountPointNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload);
     }
 
     @Test
@@ -85,13 +83,11 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final DataSchemaNode dataSchemaNode = schemaContext
                 .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
         final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
-        mockBodyReader(uri, this.xmlBodyReader, false);
-        final InputStream inputStream = XmlBodyReaderMountPointTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
-                null, null, this.mediaType, null, inputStream);
-        checkMountPointNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
+        mockBodyReader(uri, xmlBodyReader, false);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
+        checkMountPointNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload,
                 QName.create(dataSchemaNode.getQName(), "cont1"));
     }
 
@@ -100,13 +96,11 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final DataSchemaNode dataSchemaNode = schemaContext
                 .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
         final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderMountPointTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
-                null, null, this.mediaType, null, inputStream);
-        checkMountPointNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
+        checkMountPointNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload);
     }
 
     @Test
@@ -114,25 +108,21 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final Optional<DataSchemaNode> dataSchemaNode = schemaContext
             .findDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
         final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1/reset";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderMountPointTest.class
-            .getResourceAsStream("/instanceidentifier/xml/xml_cont_action.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
-            null, null, this.mediaType, null, inputStream);
-        checkMountPointNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode.get(), returnValue);
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload pyaload = xmlBodyReader.readFrom(null,null, null, mediaType, null,
+            XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_cont_action.xml"));
+        checkMountPointNormalizedNodePayload(pyaload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode.get(), pyaload);
     }
 
     @Test
     public void rpcModuleInputTest() throws Exception {
         final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderMountPointTest.class
-                .getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null,
-                null, null, this.mediaType, null, inputStream);
-        checkNormalizedNodeContext(returnValue);
-        final ContainerNode contNode = (ContainerNode) returnValue.getData();
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderMountPointTest.class.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml"));
+        checkNormalizedNodePayload(payload);
+        final ContainerNode contNode = (ContainerNode) payload.getData();
         final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(
             QName.create(contNode.getIdentifier().getNodeType(), "cont"));
         final Optional<DataContainerChild> contDataNodePotential =
@@ -148,12 +138,12 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
     }
 
     private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
-            final NormalizedNodeContext nnContext) {
+            final NormalizedNodePayload nnContext) {
         checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
     }
 
     private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
-            final NormalizedNodeContext nnContext, final QName qualifiedName) {
+            final NormalizedNodePayload nnContext, final QName qualifiedName) {
         YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
         final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
         final DataSchemaNode mountDataSchemaNode = modelContext(mountPoint)
@@ -176,19 +166,16 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
      */
     @Test
     public void findFooContainerUsingNamespaceTest() throws Exception {
-        mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader
-                .readFrom(null, null, null, this.mediaType, null, inputStream);
+        mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml"));
 
         // check return value
-        checkMountPointNormalizedNodeContext(returnValue);
+        checkMountPointNormalizedNodePayload(payload);
         // check if container was found both according to its name and namespace
-        assertEquals("Not correct container found, name was ignored",
-                "foo-bar-container", returnValue.getData().getIdentifier().getNodeType().getLocalName());
-        assertEquals("Not correct container found, namespace was ignored",
-                "foo:module", returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
+        final var dataNodeType = payload.getData().getIdentifier().getNodeType();
+        assertEquals("foo-bar-container", dataNodeType.getLocalName());
+        assertEquals("foo:module", dataNodeType.getNamespace().toString());
     }
 
     /**
@@ -199,18 +186,15 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
     @Test
     public void findBarContainerUsingNamespaceTest() throws Exception {
         mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
-            "/instanceidentifier/xml/xmlDataFindBarContainer.xml");
-        final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-            inputStream);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml"));
 
         // check return value
-        checkMountPointNormalizedNodeContext(returnValue);
+        checkMountPointNormalizedNodePayload(payload);
         // check if container was found both according to its name and namespace
-        assertEquals("Not correct container found, name was ignored",
-                "foo-bar-container", returnValue.getData().getIdentifier().getNodeType().getLocalName());
-        assertEquals("Not correct container found, namespace was ignored",
-                "bar:module", returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
+        final var dataNodeType = payload.getData().getIdentifier().getNodeType();
+        assertEquals("foo-bar-container", dataNodeType.getLocalName());
+        assertEquals("bar:module", dataNodeType.getNamespace().toString());
     }
 
     /**
@@ -220,12 +204,12 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
      */
     @Test
     public void wrongRootElementTest() throws Exception {
-        mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, false);
+        mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, false);
         final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
             "/instanceidentifier/xml/bug7933.xml");
 
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
-            () -> xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
+            () -> xmlBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
         final RestconfError restconfError = ex.getErrors().get(0);
         assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
         assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
index a721718d76658cb5a87c6cea45c014b93780a9b5..fe32b1c69cb4ba8e0a5160be567797c583cc1f1e 100644 (file)
@@ -28,7 +28,6 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.patch.PatchContext;
@@ -36,6 +35,7 @@ import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -90,14 +90,12 @@ public abstract class AbstractBodyReaderTest {
         normalizedNodeProvider.setRequest(request);
     }
 
-    protected static void checkMountPointNormalizedNodeContext(
-            final NormalizedNodeContext nnContext) {
-        checkNormalizedNodeContext(nnContext);
+    protected static void checkMountPointNormalizedNodePayload(final NormalizedNodePayload nnContext) {
+        checkNormalizedNodePayload(nnContext);
         assertNotNull(nnContext.getInstanceIdentifierContext().getMountPoint());
     }
 
-    protected static void checkNormalizedNodeContext(
-            final NormalizedNodeContext nnContext) {
+    protected static void checkNormalizedNodePayload(final NormalizedNodePayload nnContext) {
         assertNotNull(nnContext.getData());
         assertNotNull(nnContext.getInstanceIdentifierContext()
                 .getInstanceIdentifier());
index 8e423870803d3bf7a85c389f07ddf36b8e965281..bea7f8d017b5a9215db4c067d940597b783e728f 100644 (file)
@@ -8,9 +8,10 @@
 
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Sets;
 import java.io.ByteArrayInputStream;
@@ -23,9 +24,9 @@ import java.util.Optional;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -37,8 +38,6 @@ 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.Module;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class JsonBodyReaderTest extends AbstractBodyReaderTest {
@@ -51,7 +50,7 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
 
     public JsonBodyReaderTest() throws Exception {
         super(schemaContext);
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+        jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
     }
 
     @Override
@@ -60,8 +59,7 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
     }
 
     @BeforeClass
-    public static void initialization()
-            throws NoSuchFieldException, SecurityException, FileNotFoundException, SourceException, ReactorException {
+    public static void initialization() throws FileNotFoundException {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
@@ -73,13 +71,11 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
                 .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.jsonBodyReader, false);
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsondata.json");
-        final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, jsonBodyReader, false);
+        final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsondata.json"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
@@ -90,13 +86,11 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
         final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
         final String uri = "instance-identifier-module:cont/cont1";
-        mockBodyReader(uri, this.jsonBodyReader, false);
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
-        final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
+        mockBodyReader(uri, jsonBodyReader, false);
+        final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, payload, dataII);
     }
 
     @Test
@@ -106,13 +100,11 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.jsonBodyReader, true);
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
-        final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, jsonBodyReader, true);
+        final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
@@ -124,13 +116,11 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.get().getQName())
             .node(cont1QName).node(actionQName);
         final String uri = "instance-identifier-module:cont/cont1/reset";
-        mockBodyReader(uri, this.jsonBodyReader, true);
-        final InputStream inputStream = JsonBodyReaderTest.class
-            .getResourceAsStream("/instanceidentifier/json/json_cont_action.json");
-        final NormalizedNodeContext returnValue = this.jsonBodyReader
-            .readFrom(null, null, null, this.mediaType, null, inputStream);
-        checkNormalizedNodeContext(returnValue);
-        assertTrue(returnValue.getInstanceIdentifierContext().getSchemaNode() instanceof ActionDefinition);
+        mockBodyReader(uri, jsonBodyReader, true);
+        final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_cont_action.json"));
+        checkNormalizedNodePayload(payload);
+        assertThat(payload.getInstanceIdentifierContext().getSchemaNode(), instanceOf(ActionDefinition.class));
     }
 
     @Test
@@ -144,14 +134,11 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augII)
                 .node(contAugmentQName);
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.jsonBodyReader, true);
-        final InputStream inputStream =
-                XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/json_augment_container.json");
-        final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, jsonBodyReader, true);
+        final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_augment_container.json"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
@@ -169,18 +156,16 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augChoice1II)
                 .node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName).node(containerQName);
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.jsonBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json");
-        final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, jsonBodyReader, true);
+        final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
     public void testRangeViolation() throws Exception {
-        mockBodyReader("netconf786:foo", this.jsonBodyReader, false);
+        mockBodyReader("netconf786:foo", jsonBodyReader, false);
 
         final InputStream inputStream = new ByteArrayInputStream(("{\n"
             + "  \"netconf786:foo\": {\n"
@@ -188,11 +173,11 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
             + "  }\n"
             + "}").getBytes(StandardCharsets.UTF_8));
 
-        assertRangeViolation(() -> jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
+        assertRangeViolation(() -> jsonBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 
     private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
-            final NormalizedNodeContext nnContext, final YangInstanceIdentifier dataNodeIdent) {
+            final NormalizedNodePayload nnContext, final YangInstanceIdentifier dataNodeIdent) {
         assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());
         assertEquals(dataNodeIdent, nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
         assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
index 2a182e4205ffd5158120f643a7b3c011ee74a3c6..3c16e48adbc1f8196b5e3710ab921bf45f5d2e1e 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.Sets;
@@ -20,14 +22,13 @@ import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Optional;
 import javax.ws.rs.core.MediaType;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -55,7 +56,7 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
 
     public XmlBodyReaderTest() throws Exception {
         super(schemaContext);
-        this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+        xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
     }
 
     @Override
@@ -83,12 +84,12 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
 
     private void runXmlTest(final boolean isPost, final String path) throws Exception {
         mockBodyReader(path, xmlBodyReader, isPost);
-        final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream("/foo-xml-test/foo.xml");
-        final NormalizedNodeContext nnc = xmlBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-        assertNotNull(nnc);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/foo-xml-test/foo.xml"));
+        assertNotNull(payload);
 
-        assertTrue(nnc.getData() instanceof MapEntryNode);
-        final MapEntryNode data = (MapEntryNode) nnc.getData();
+        assertThat(payload.getData(), instanceOf(MapEntryNode.class));
+        final MapEntryNode data = (MapEntryNode) payload.getData();
         assertEquals(2, data.size());
         for (final DataContainerChild child : data.body()) {
             switch (child.getIdentifier().getNodeType().getLocalName()) {
@@ -110,13 +111,11 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
                 .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.xmlBodyReader, false);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, xmlBodyReader, false);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmldata.xml"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
@@ -127,13 +126,11 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
         final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
         final String uri = "instance-identifier-module:cont/cont1";
-        mockBodyReader(uri, this.xmlBodyReader, false);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
+        mockBodyReader(uri, xmlBodyReader, false);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, payload, dataII);
     }
 
     @Test
@@ -143,13 +140,11 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
@@ -161,13 +156,11 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.get().getQName())
             .node(cont1QName).node(actionQName);
         final String uri = "instance-identifier-module:cont/cont1/reset";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-            .getResourceAsStream("/instanceidentifier/xml/xml_cont_action.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-            inputStream);
-        checkNormalizedNodeContext(returnValue);
-        assertTrue(returnValue.getInstanceIdentifierContext().getSchemaNode() instanceof ActionDefinition);
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_cont_action.xml"));
+        checkNormalizedNodePayload(payload);
+        assertThat(payload.getInstanceIdentifierContext().getSchemaNode(), instanceOf(ActionDefinition.class));
     }
 
     @Test
@@ -181,13 +174,11 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augII)
                 .node(contAugmentQName);
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     @Test
@@ -205,17 +196,15 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augChoice1II)
                 .node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName).node(containerQName);
         final String uri = "instance-identifier-module:cont";
-        mockBodyReader(uri, this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
-        checkNormalizedNodeContext(returnValue);
-        checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+        mockBodyReader(uri, xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml"));
+        checkNormalizedNodePayload(payload);
+        checkExpectValueNormalizeNodeContext(dataSchemaNode, payload, dataII);
     }
 
     private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
-            final NormalizedNodeContext nnContext, final YangInstanceIdentifier dataNodeIdent) {
+            final NormalizedNodePayload nnContext, final YangInstanceIdentifier dataNodeIdent) {
         assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());
         assertEquals(dataNodeIdent, nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
         assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
@@ -229,19 +218,16 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void findFooContainerUsingNamespaceTest() throws Exception {
-        mockBodyReader("", this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
+        mockBodyReader("", xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml"));
 
         // check return value
-        checkNormalizedNodeContext(returnValue);
+        checkNormalizedNodePayload(payload);
         // check if container was found both according to its name and namespace
-        assertEquals("Not correct container found, name was ignored", "foo-bar-container",
-                returnValue.getData().getIdentifier().getNodeType().getLocalName());
-        assertEquals("Not correct container found, namespace was ignored", "foo:module",
-                returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
+        final var payloadNodeType = payload.getData().getIdentifier().getNodeType();
+        assertEquals("foo-bar-container", payloadNodeType.getLocalName());
+        assertEquals("foo:module", payloadNodeType.getNamespace().toString());
     }
 
     /**
@@ -252,19 +238,16 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void findBarContainerUsingNamespaceTest() throws Exception {
-        mockBodyReader("", this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
-                inputStream);
+        mockBodyReader("", xmlBodyReader, true);
+        final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml"));
 
         // check return value
-        checkNormalizedNodeContext(returnValue);
+        checkNormalizedNodePayload(payload);
         // check if container was found both according to its name and namespace
-        assertEquals("Not correct container found, name was ignored", "foo-bar-container",
-                returnValue.getData().getIdentifier().getNodeType().getLocalName());
-        assertEquals("Not correct container found, namespace was ignored", "bar:module",
-                returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
+        final var payloadNodeType = payload.getData().getIdentifier().getNodeType();
+        assertEquals("foo-bar-container", payloadNodeType.getLocalName());
+        assertEquals("bar:module", payloadNodeType.getNamespace().toString());
     }
 
     /**
@@ -274,26 +257,25 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void wrongRootElementTest() throws Exception {
-        mockBodyReader("instance-identifier-module:cont", this.xmlBodyReader, false);
+        mockBodyReader("instance-identifier-module:cont", xmlBodyReader, false);
         final InputStream inputStream =
                 XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/bug7933.xml");
-        try {
-            this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
-            Assert.fail("Test should fail due to malformed PUT operation message");
-        } catch (final RestconfDocumentedException exception) {
-            final RestconfError restconfError = exception.getErrors().get(0);
-            Assert.assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
-            Assert.assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
-        }
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+
+        final RestconfError restconfError = ex.getErrors().get(0);
+        assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
     }
 
     @Test
     public void testRangeViolation() throws Exception {
-        mockBodyReader("netconf786:foo", this.xmlBodyReader, false);
+        mockBodyReader("netconf786:foo", xmlBodyReader, false);
 
         final InputStream inputStream = new ByteArrayInputStream(
             "<foo xmlns=\"netconf786\"><bar>100</bar></foo>".getBytes(StandardCharsets.UTF_8));
 
-        assertRangeViolation(() -> xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
+        assertRangeViolation(() -> xmlBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 }
index 2de5d57bfe35d395e229ab43414237267e9be282..927455d8a9bea3ef1bb7f45af80ae7eb34402df5 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.Collections;
 import java.util.function.Function;
@@ -19,9 +20,9 @@ import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -41,24 +42,23 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 public class CreateStreamUtilTest {
     private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/streams";
 
-    private NormalizedNodeContext payload;
+    private NormalizedNodePayload payload;
     private EffectiveModelContext refSchemaCtx;
 
     @Before
     public void setUp() throws Exception {
-        this.refSchemaCtx =
-                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
+        refSchemaCtx = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
     }
 
     @Test
     public void createStreamTest() {
-        this.payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput, "toaster",
+        payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput, "toaster",
             "path");
-        final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(this.payload, this.refSchemaCtx);
+        final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
         assertEquals(result.getErrors(), Collections.emptyList());
         final NormalizedNode testedNn = result.getResult();
         assertNotNull(testedNn);
-        final NormalizedNodeContext contextRef = prepareDomPayload("create-data-change-event-subscription",
+        final NormalizedNodePayload contextRef = prepareDomPayload("create-data-change-event-subscription",
             RpcDefinition::getOutput,
             "data-change-event-subscription/toaster:toaster/datastore=CONFIGURATION/scope=BASE", "stream-name");
         assertEquals(contextRef.getData(), testedNn);
@@ -66,24 +66,24 @@ public class CreateStreamUtilTest {
 
     @Test(expected = RestconfDocumentedException.class)
     public void createStreamWrongValueTest() {
-        this.payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput,
+        payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput,
             "String value", "path");
-        final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(this.payload, this.refSchemaCtx);
+        final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
         assertEquals(result.getErrors(), Collections.emptyList());
     }
 
     @Test(expected = RestconfDocumentedException.class)
     public void createStreamWrongInputRpcTest() {
-        this.payload = prepareDomPayload("create-data-change-event-subscription2", RpcDefinition::getInput, "toaster",
+        payload = prepareDomPayload("create-data-change-event-subscription2", RpcDefinition::getInput, "toaster",
             "path2");
-        final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(this.payload, this.refSchemaCtx);
+        final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
         assertEquals(result.getErrors(), Collections.emptyList());
     }
 
-    private NormalizedNodeContext prepareDomPayload(final String rpcName,
+    private NormalizedNodePayload prepareDomPayload(final String rpcName,
             final Function<RpcDefinition, ContainerLike> rpcToContainer, final String toasterValue,
             final String inputOutputName) {
-        final EffectiveModelContext schema = this.refSchemaCtx;
+        final EffectiveModelContext schema = refSchemaCtx;
         final Module rpcModule = schema.findModules("sal-remote").iterator().next();
         final QName rpcQName = QName.create(rpcModule.getQNameModule(), rpcName);
         ContainerLike rpcInputSchemaNode = null;
@@ -101,7 +101,7 @@ public class CreateStreamUtilTest {
         final QName lfQName = QName.create(rpcModule.getQNameModule(), inputOutputName);
         final DataSchemaNode lfSchemaNode = rpcInputSchemaNode.findDataChildByName(lfQName).orElseThrow();
 
-        assertTrue(lfSchemaNode instanceof LeafSchemaNode);
+        assertThat(lfSchemaNode, instanceOf(LeafSchemaNode.class));
 
         final Object o;
         if ("toaster".equals(toasterValue)) {
@@ -114,7 +114,7 @@ public class CreateStreamUtilTest {
                 .withValue(o).build();
         container.withChild(lfNode);
 
-        return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schema),
+        return NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schema),
                 container.build());
     }
 }
index 165d3fc8405eb80eee0be09e194c8b5923e30ea7..f44a7161f7721e2bd83c7a9a0f0b53f989a4add4 100644 (file)
@@ -26,9 +26,9 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -76,7 +76,7 @@ public class Netconf799Test {
             actionService, mock(Configuration.class));
 
         final var schemaNode = loadAction(contextRef, RESET_QNAME, ACTION_YII).orElseThrow();
-        final var response = dataService.invokeAction(new NormalizedNodeContext(
+        final var response = dataService.invokeAction(NormalizedNodePayload.of(
             new InstanceIdentifierContext<>(ACTION_YII, schemaNode, null, contextRef),
             Builders.containerBuilder()
                 .withNodeIdentifier(NodeIdentifier.create(INPUT_QNAME))
index 5df787380643b0a40aa6a04f3e20201a981435bf..fde8e70ac7b7dff73ed1417736cdb2e501586338 100644 (file)
@@ -53,7 +53,6 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
@@ -224,7 +223,7 @@ public class RestconfDataServiceImplTest {
         final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
         assertNotNull(response);
         assertEquals(200, response.getStatus());
-        assertEquals(buildBaseCont, ((NormalizedNodeContext) response.getEntity()).getData());
+        assertEquals(buildBaseCont, ((NormalizedNodePayload) response.getEntity()).getData());
     }
 
     @Test
@@ -240,7 +239,7 @@ public class RestconfDataServiceImplTest {
         assertNotNull(response);
         assertEquals(200, response.getStatus());
 
-        final NormalizedNode data = ((NormalizedNodeContext) response.getEntity()).getData();
+        final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
         assertTrue(data instanceof ContainerNode);
         final Collection<DataContainerChild> rootNodes = ((ContainerNode) data).body();
         assertEquals(1, rootNodes.size());
@@ -274,7 +273,7 @@ public class RestconfDataServiceImplTest {
         assertEquals(200, response.getStatus());
 
         // response must contain all child nodes from config and operational containers merged in one container
-        final NormalizedNode data = ((NormalizedNodeContext) response.getEntity()).getData();
+        final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
         assertTrue(data instanceof ContainerNode);
         assertEquals(3, ((ContainerNode) data).size());
         assertTrue(((ContainerNode) data).findChildByArg(buildPlayerCont.getIdentifier()).isPresent());
@@ -310,7 +309,7 @@ public class RestconfDataServiceImplTest {
         assertEquals(200, response.getStatus());
 
         // response must contain only config data
-        final NormalizedNode data = ((NormalizedNodeContext) response.getEntity()).getData();
+        final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
 
         // config data present
         assertTrue(((ContainerNode) data).findChildByArg(buildPlayerCont.getIdentifier()).isPresent());
@@ -338,7 +337,7 @@ public class RestconfDataServiceImplTest {
         assertEquals(200, response.getStatus());
 
         // response must contain only operational data
-        final NormalizedNode data = ((NormalizedNodeContext) response.getEntity()).getData();
+        final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
 
         // state data present
         assertTrue(((ContainerNode) data).findChildByArg(buildPlayerCont.getIdentifier()).isPresent());
index 7d2c1de83d35dd1f788a110e43564bf0074710d7..63aa890a82f746a0c0b7332e8fc3527e0d909775 100644 (file)
@@ -10,11 +10,11 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
@@ -24,7 +24,7 @@ public class RestconfImplTest {
         final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(
             YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl")));
         final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler);
-        final NormalizedNodeContext libraryVersion = restconfImpl.getLibraryVersion();
+        final NormalizedNodePayload libraryVersion = restconfImpl.getLibraryVersion();
         final LeafNode<?> value = (LeafNode<?>) libraryVersion.getData();
         assertEquals(IetfYangLibrary.REVISION.toString(), value.body());
     }
index 5d39f5039a2093acc1fca1bee50f8be57b08061c..1eec95401fbd65b0f418eeb855b6f8c81d43e59a 100644 (file)
@@ -46,7 +46,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
@@ -103,7 +102,7 @@ public class RestconfInvokeOperationsServiceImplTest {
         doReturn(false).when(result).isEmpty();
 
         final AsyncResponse ar = mock(AsyncResponse.class);
-        final ArgumentCaptor<NormalizedNodeContext> response = ArgumentCaptor.forClass(NormalizedNodeContext.class);
+        final ArgumentCaptor<NormalizedNodePayload> response = ArgumentCaptor.forClass(NormalizedNodePayload.class);
         invokeOperationsService.invokeRpc("invoke-rpc-module:rpcTest", prepNNC(result), mock(UriInfo.class), ar);
         verify(ar).resume(response.capture());
 
index 5f0fd4d6627ecbd777f276554f5d8fa9ae3c8110..e2f3d89c9459310a218cf2803171dab72be7ba80 100644 (file)
@@ -35,11 +35,11 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.util.SimpleUriInfo;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
@@ -124,16 +124,14 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamSSE() {
         ListenersBroker.getInstance().registerDataChangeListener(
-                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", this.schemaHandler.get()),
+                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.configurationSse);
-        final NormalizedNodeContext response = streamsSubscriptionService
-                .subscribeToStream(
-                        "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
-                        this.uriInfo);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
+                        schemaHandler, configurationSse);
+        final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
+            "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
         assertEquals("http://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
                 + "/" + RestconfConstants.NOTIF
                 + "/data-change-event-subscription/toaster:toaster/toasterStatus/"
@@ -143,16 +141,14 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamWS() {
         ListenersBroker.getInstance().registerDataChangeListener(
-                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", this.schemaHandler.get()),
+                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.configurationWs);
-        final NormalizedNodeContext response = streamsSubscriptionService
-                .subscribeToStream(
-                        "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
-                        this.uriInfo);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
+                        schemaHandler, configurationWs);
+        final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
+            "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
         assertEquals("ws://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
                 + "/data-change-event-subscription/toaster:toaster/toasterStatus/"
                 + "datastore=OPERATIONAL/scope=ONE", response.getNewHeaders().get("Location").toString());
@@ -161,17 +157,17 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test(expected = RestconfDocumentedException.class)
     public void testSubscribeToStreamMissingDatastoreInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.configurationWs);
-        streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", this.uriInfo);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
+                        schemaHandler, configurationWs);
+        streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", uriInfo);
     }
 
     @Test(expected = RestconfDocumentedException.class)
     public void testSubscribeToStreamMissingScopeInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
+                        schemaHandler, configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL",
-                this.uriInfo);
+                uriInfo);
     }
 }
index ab15d93f15f20d8b05b83f6bfdab26f0e96e8bad..46960927ca518202f956c74f9c9286c51ed61572 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -30,7 +31,6 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
@@ -171,43 +171,49 @@ public class PutDataTransactionUtilTest {
     public void testValidInputData() {
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
                 new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
-        final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
-        RestconfDataServiceImpl.validInputData(iidContext.getSchemaNode(), payload);
+        RestconfDataServiceImpl.validInputData(iidContext.getSchemaNode(),
+            NormalizedNodePayload.of(iidContext, buildLeaf));
     }
 
     @Test
     public void testValidTopLevelNodeName() {
         InstanceIdentifierContext<DataSchemaNode> iidContext =
                 new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
-        NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
+        NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
         RestconfDataServiceImpl.validTopLevelNodeName(iidContext.getInstanceIdentifier(), payload);
 
         iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
-        payload = new NormalizedNodeContext(iidContext, buildBaseCont);
+        payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
         RestconfDataServiceImpl.validTopLevelNodeName(iidContext.getInstanceIdentifier(), payload);
     }
 
-    @Test(expected = RestconfDocumentedException.class)
+    @Test
     public void testValidTopLevelNodeNamePathEmpty() {
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
                 new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
-        final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
-        RestconfDataServiceImpl.validTopLevelNodeName(YangInstanceIdentifier.empty(), payload);
+        final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
+
+        // FIXME: more asserts
+        assertThrows(RestconfDocumentedException.class,
+            () -> RestconfDataServiceImpl.validTopLevelNodeName(YangInstanceIdentifier.empty(), payload));
     }
 
-    @Test(expected = RestconfDocumentedException.class)
+    @Test
     public void testValidTopLevelNodeNameWrongTopIdentifier() {
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
                 new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
-        final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
-        RestconfDataServiceImpl.validTopLevelNodeName(iid.getAncestor(1), payload);
+        final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
+
+        // FIXME: more asserts
+        assertThrows(RestconfDocumentedException.class,
+            () -> RestconfDataServiceImpl.validTopLevelNodeName(iid.getAncestor(1), payload));
     }
 
     @Test
     public void testValidateListKeysEqualityInPayloadAndUri() {
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
                 new InstanceIdentifierContext<>(iid3, schemaNode3, null, schema);
-        final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildListEntry);
+        final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildListEntry);
         RestconfDataServiceImpl.validateListKeysEqualityInPayloadAndUri(payload);
     }