Search in sources :

Example 56 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class JSONRestconfServiceImplTest method testInvokeRpcWithInput.

@SuppressWarnings("rawtypes")
@Test
public void testInvokeRpcWithInput() throws Exception {
    final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode) null);
    doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(eq(MAKE_TOAST_QNAME), any(NormalizedNode.class));
    final String uriPath = "toaster:make-toast";
    final String input = loadData("/full-versions/make-toast-rpc-input.json");
    final Optional<String> output = this.service.invokeRpc(uriPath, Optional.of(input));
    assertEquals("Output present", false, output.isPresent());
    final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
    verify(brokerFacade).invokeRpc(eq(MAKE_TOAST_QNAME), capturedNode.capture());
    assertTrue("Expected ContainerNode. Actual " + capturedNode.getValue().getClass(), capturedNode.getValue() instanceof ContainerNode);
    final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
    verifyLeafNode(actualNode, TOASTER_DONENESS_QNAME, Uint32.valueOf(10));
    verifyLeafNode(actualNode, TOASTER_TYPE_QNAME, WHEAT_BREAD_QNAME);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 57 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class JSONRestconfServiceImplTest method testInvokeRpcWithOutput.

@Test
public void testInvokeRpcWithOutput() throws Exception {
    final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_OUTPUT_QNAME)).withChild(ImmutableNodes.leafNode(TEXT_OUT_QNAME, "foo")).build();
    final DOMRpcResult expResult = new DefaultDOMRpcResult(outputNode);
    doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(any(QName.class), any());
    final String uriPath = "toaster:testOutput";
    final Optional<String> output = this.service.invokeRpc(uriPath, Optional.empty());
    assertEquals("Output present", true, output.isPresent());
    assertNotNull("Returned null response", output.get());
    assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
    verify(brokerFacade).invokeRpc(eq(TEST_OUTPUT_QNAME), any());
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 58 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class CreateStreamUtilTest method createStreamWrongValueTest.

@Test(expected = RestconfDocumentedException.class)
public void createStreamWrongValueTest() {
    payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput, "String value", "path");
    final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
    assertEquals(result.getErrors(), Collections.emptyList());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) Test(org.junit.Test)

Example 59 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class BrokerFacadeTest method testInvokeRpc.

@Test
public void testInvokeRpc() throws Exception {
    final DOMRpcResult expResult = mock(DOMRpcResult.class);
    doReturn(immediateFluentFuture(expResult)).when(this.mockRpcService).invokeRpc(this.qname, this.dummyNode);
    final ListenableFuture<? extends DOMRpcResult> actualFuture = this.brokerFacade.invokeRpc(this.qname, this.dummyNode);
    assertNotNull("Future is null", actualFuture);
    final DOMRpcResult actualResult = actualFuture.get();
    assertSame("invokeRpc", expResult, actualResult);
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) Test(org.junit.Test)

Example 60 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class RestconfInvokeOperationsServiceImpl method invokeRpc.

@Override
public void invokeRpc(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo, final AsyncResponse ar) {
    final SchemaNode schema = payload.getInstanceIdentifierContext().getSchemaNode();
    final QName rpcName = schema.getQName();
    final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
    final ListenableFuture<? extends DOMRpcResult> future;
    final EffectiveModelContext schemaContextRef;
    if (mountPoint == null) {
        schemaContextRef = schemaContextHandler.get();
        // FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS
        if (SAL_REMOTE_NAMESPACE.equals(rpcName.getNamespace())) {
            if (identifier.contains("create-data-change-event-subscription")) {
                future = Futures.immediateFuture(CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContextRef));
            } else {
                future = Futures.immediateFailedFuture(new RestconfDocumentedException("Unsupported operation", ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED));
            }
        } else {
            future = invokeRpc(payload.getData(), rpcName, rpcService);
        }
    } else {
        schemaContextRef = modelContext(mountPoint);
        future = invokeRpc(payload.getData(), rpcName, mountPoint);
    }
    Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {

        @Override
        public void onSuccess(final DOMRpcResult response) {
            final var errors = response.getErrors();
            if (!errors.isEmpty()) {
                LOG.debug("RpcError message {}", response.getErrors());
                ar.resume(new RestconfDocumentedException("RPCerror message ", null, response.getErrors()));
                return;
            }
            final NormalizedNode resultData = response.getResult();
            if (resultData == null || ((ContainerNode) resultData).isEmpty()) {
                ar.resume(new WebApplicationException(Status.NO_CONTENT));
            } else {
                ar.resume(NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, (RpcDefinition) schema, mountPoint, schemaContextRef), resultData));
            }
        }

        @Override
        public void onFailure(final Throwable failure) {
            ar.resume(failure);
        }
    }, MoreExecutors.directExecutor());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) WebApplicationException(javax.ws.rs.WebApplicationException) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)61 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)39 Test (org.junit.Test)38 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 QName (org.opendaylight.yangtools.yang.common.QName)18 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)10 RpcError (org.opendaylight.yangtools.yang.common.RpcError)8 ExecutionException (java.util.concurrent.ExecutionException)7 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)6 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 InvokeRpcMessageReply (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)5 DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)4 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3