.getService(DOMSchemaService.class);
}
- protected static void mockBodyReader(final String identifier,
- final AbstractNormalizedNodeBodyReader normalizedNodeProvider, final boolean isPost) {
+ protected static void mockPostBodyReader(final String identifier, final AbstractNormalizedNodeBodyReader reader) {
+ mockBodyReader(identifier, reader, HttpMethod.POST);
+ }
+
+ protected static void mockPutBodyReader(final String identifier, final AbstractNormalizedNodeBodyReader reader) {
+ mockBodyReader(identifier, reader, HttpMethod.PUT);
+ }
+
+ private static void mockBodyReader(final String identifier, final AbstractNormalizedNodeBodyReader reader,
+ final String method) {
final var pathParm = new MultivaluedHashMap<String, String>(2);
if (!identifier.isEmpty()) {
pathParm.put("identifier", List.of(identifier));
doReturn(pathParm).when(uriInfoMock).getPathParameters();
doReturn(pathParm).when(uriInfoMock).getPathParameters(false);
doReturn(pathParm).when(uriInfoMock).getPathParameters(true);
- normalizedNodeProvider.setUriInfo(uriInfoMock);
+ reader.setUriInfo(uriInfoMock);
final var request = mock(Request.class);
- doReturn(isPost ? HttpMethod.POST : HttpMethod.PUT).when(request).getMethod();
- normalizedNodeProvider.setRequest(request);
+ doReturn(method).when(request).getMethod();
+ reader.setRequest(request);
}
protected static void checkMountPointNormalizedNodePayload(final NormalizedNodePayload nnContext) {
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
import static org.hamcrest.CoreMatchers.instanceOf;
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, false);
+ mockPutBodyReader(uri, jsonBodyReader);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsondata.json"));
checkNormalizedNodePayload(payload);
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, jsonBodyReader, false);
+ mockPutBodyReader(uri, jsonBodyReader);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json"));
checkNormalizedNodePayload(payload);
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, jsonBodyReader, true);
+ mockPostBodyReader(uri, jsonBodyReader);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json"));
checkNormalizedNodePayload(payload);
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(cont1QName).node(actionQName);
final String uri = "instance-identifier-module:cont/cont1/reset";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockPostBodyReader(uri, jsonBodyReader);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_cont_action.json"));
checkNormalizedNodePayload(payload);
final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName(), contAugmentQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockPostBodyReader(uri, jsonBodyReader);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_augment_container.json"));
checkNormalizedNodePayload(payload);
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(augmentChoice1QName).node(augmentChoice2QName).node(containerQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, jsonBodyReader, true);
+ mockPostBodyReader(uri, jsonBodyReader);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json"));
checkNormalizedNodePayload(payload);
@Test
public void testRangeViolation() throws Exception {
- mockBodyReader("netconf786:foo", jsonBodyReader, false);
+ mockPutBodyReader("netconf786:foo", jsonBodyReader);
final InputStream inputStream = new ByteArrayInputStream(("{\n"
+ " \"netconf786:foo\": {\n"
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, xmlBodyReader, false);
+ mockPutBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xmldata.xml"));
checkMountPointNormalizedNodePayload(payload);
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, xmlBodyReader, false);
+ mockPutBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
checkMountPointNormalizedNodePayload(payload);
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, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
checkMountPointNormalizedNodePayload(payload);
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/reset";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload pyaload = xmlBodyReader.readFrom(null,null, null, MEDIA_TYPE, null,
XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_cont_action.xml"));
checkMountPointNormalizedNodePayload(pyaload);
@Test
public void rpcModuleInputTest() throws Exception {
final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderMountPointTest.class.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml"));
checkNormalizedNodePayload(payload);
*/
@Test
public void findFooContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+ mockPostBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml"));
*/
@Test
public void findBarContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+ mockPostBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml"));
*/
@Test
public void wrongRootElementTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, false);
+ mockPutBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader);
final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/bug7933.xml");
@Test
public void putXmlTest() throws Exception {
- runXmlTest(false, "foo:top-level-list=key-value");
+ mockPutBodyReader("foo:top-level-list=key-value", xmlBodyReader);
+ runXmlTest();
}
@Test
public void postXmlTest() throws Exception {
- runXmlTest(true, "");
+ mockPostBodyReader("", xmlBodyReader);
+ runXmlTest();
}
- private void runXmlTest(final boolean isPost, final String path) throws Exception {
- mockBodyReader(path, xmlBodyReader, isPost);
+ private void runXmlTest() throws Exception {
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/foo-xml-test/foo.xml"));
assertNotNull(payload);
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, false);
+ mockPutBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmldata.xml"));
checkNormalizedNodePayload(payload);
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, xmlBodyReader, false);
+ mockPutBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
checkNormalizedNodePayload(payload);
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, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
checkNormalizedNodePayload(payload);
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
.node(cont1QName).node(actionQName);
final String uri = "instance-identifier-module:cont/cont1/reset";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_cont_action.xml"));
checkNormalizedNodePayload(payload);
final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName(), contAugmentQName);
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml"));
checkNormalizedNodePayload(payload);
.node(augmentChoice2QName)
.node(QName.create(augmentChoice1QName, "case-choice-case-container1"));
final String uri = "instance-identifier-module:cont";
- mockBodyReader(uri, xmlBodyReader, true);
+ mockPostBodyReader(uri, xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml"));
checkNormalizedNodePayload(payload);
*/
@Test
public void findFooContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("", xmlBodyReader, true);
+ mockPostBodyReader("", xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml"));
*/
@Test
public void findBarContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("", xmlBodyReader, true);
+ mockPostBodyReader("", xmlBodyReader);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml"));
*/
@Test
public void wrongRootElementTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont", xmlBodyReader, false);
+ mockPutBodyReader("instance-identifier-module:cont", xmlBodyReader);
final InputStream inputStream =
XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/bug7933.xml");
@Test
public void testRangeViolation() throws Exception {
- mockBodyReader("netconf786:foo", xmlBodyReader, false);
+ mockPutBodyReader("netconf786:foo", xmlBodyReader);
final InputStream inputStream = new ByteArrayInputStream(
"<foo xmlns=\"netconf786\"><bar>100</bar></foo>".getBytes(StandardCharsets.UTF_8));