Search in sources :

Example 16 with NormalizedNodePayload

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());
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Response(javax.ws.rs.core.Response) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 17 with NormalizedNodePayload

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());
}
Also used : Response(javax.ws.rs.core.Response) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Example 18 with NormalizedNodePayload

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());
}
Also used : SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Example 19 with NormalizedNodePayload

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());
}
Also used : ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) AsyncResponse(javax.ws.rs.container.AsyncResponse) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 20 with NormalizedNodePayload

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();
        }
    }
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Aggregations

NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)57 Test (org.junit.Test)53 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)33 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)24 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)21 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)13 QName (org.opendaylight.yangtools.yang.common.QName)13 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)12 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)12 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)12 Response (javax.ws.rs.core.Response)10 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)10 AbstractBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)7 XmlBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest)7 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)6 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)5 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)5 ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)5 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)5 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)5