use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class RestconfDataServiceImplTest method testReadDataConfigTest.
/**
* Read data from config datastore according to content parameter.
*/
@Test
public void testReadDataConfigTest() {
final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
parameters.put("content", List.of("config"));
doReturn(parameters).when(uriInfo).getQueryParameters();
doReturn(immediateFluentFuture(Optional.of(buildBaseContConfig))).when(read).read(LogicalDatastoreType.CONFIGURATION, iidBase);
final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
// response must contain only config data
final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
// config data present
assertTrue(((ContainerNode) data).findChildByArg(buildPlayerCont.getIdentifier()).isPresent());
assertTrue(((ContainerNode) data).findChildByArg(buildLibraryCont.getIdentifier()).isPresent());
// state data absent
assertFalse(((ContainerNode) data).findChildByArg(buildPlaylistList.getIdentifier()).isPresent());
}
use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class RestconfDataServiceImplTest method testPutData.
@Test
public void testPutData() {
final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
doReturn(immediateTrueFluentFuture()).when(read).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iidBase, payload.getData());
final Response response = dataService.putData(null, payload, uriInfo);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class RestconfImplTest method restImplTest.
@Test
public void restImplTest() throws Exception {
final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl")));
final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler);
final NormalizedNodePayload libraryVersion = restconfImpl.getLibraryVersion();
final LeafNode<?> value = (LeafNode<?>) libraryVersion.getData();
assertEquals(IetfYangLibrary.REVISION.toString(), value.body());
}
use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method testInvokeRpcWithNonEmptyOutput.
@Test
public void testInvokeRpcWithNonEmptyOutput() {
final ContainerNode result = mock(ContainerNode.class);
doReturn(false).when(result).isEmpty();
final AsyncResponse ar = mock(AsyncResponse.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());
assertSame(result, response.getValue().getData());
}
use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class XmlBodyReaderTest method runXmlTest.
private void runXmlTest(final boolean isPost, final String path) throws Exception {
mockBodyReader(path, xmlBodyReader, isPost);
final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, mediaType, null, XmlBodyReaderTest.class.getResourceAsStream("/foo-xml-test/foo.xml"));
assertNotNull(payload);
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()) {
case "key-leaf":
assertEquals("key-value", child.body());
break;
case "ordinary-leaf":
assertEquals("leaf-value", child.body());
break;
default:
fail();
}
}
}
Aggregations