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;
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) {
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;
}
}
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;
* }
* </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();
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;
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();
}
}
/**
* 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()
}
return Response.status(Status.OK)
- .entity(new NormalizedNodeContext(
+ .entity(NormalizedNodePayload.ofNullable(
new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef),
resultData))
.build();
* @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) {
* @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)) {
* @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();
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;
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));
}
}
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;
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());
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);
}
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;
public XmlBodyReaderMountPointTest() throws Exception {
super(schemaContext);
- this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+ xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
}
@Override
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
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"));
}
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
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 =
}
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)
*/
@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());
}
/**
@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());
}
/**
*/
@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());
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;
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;
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());
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;
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;
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 {
public JsonBodyReaderTest() throws Exception {
super(schemaContext);
- this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+ jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
}
@Override
}
@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);
.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
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
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
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
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
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"
+ " }\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));
*/
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;
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;
public XmlBodyReaderTest() throws Exception {
super(schemaContext);
- this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
+ xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
}
@Override
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()) {
.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
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
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
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
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
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));
*/
@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());
}
/**
*/
@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());
}
/**
*/
@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));
}
}
*/
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;
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;
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);
@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;
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)) {
.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());
}
}
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;
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))
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;
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
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());
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());
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());
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());
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;
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());
}
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;
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());
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;
@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/"
@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());
@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);
}
}
*/
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;
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;
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);
}