use of org.opendaylight.mdsal.dom.api.DOMRpcService in project netconf by opendaylight.
the class NetconfBaseOpsTest method setUp.
@Before
public void setUp() throws Exception {
final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
callback = new NetconfRpcFutureCallback("prefix", id);
baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
use of org.opendaylight.mdsal.dom.api.DOMRpcService in project controller by opendaylight.
the class AbstractInvokableServiceMetadata method retrievedDOMRpcService.
private void retrievedDOMRpcService(final Object service) {
log.debug("{}: retrievedDOMRpcService {}", logName(), service);
final DOMRpcService domRpcService = (DOMRpcService) service;
setDependencyDesc("Available DOM RPC for binding RPC: " + rpcInterface);
rpcListenerReg = domRpcService.registerRpcListener(new DOMRpcAvailabilityListener() {
@Override
public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
onRpcsAvailable(rpcs);
}
@Override
public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
}
});
}
use of org.opendaylight.mdsal.dom.api.DOMRpcService in project netconf by opendaylight.
the class NetconfDeviceSalFacadeTest method testOnDeviceConnected.
@Test
public void testOnDeviceConnected() {
final EffectiveModelContext schemaContext = mock(EffectiveModelContext.class);
final NetconfSessionPreferences netconfSessionPreferences = NetconfSessionPreferences.fromStrings(getCapabilities());
final DOMRpcService deviceRpc = mock(DOMRpcService.class);
deviceFacade.onDeviceConnected(new EmptyMountPointContext(schemaContext), netconfSessionPreferences, deviceRpc, null);
verify(mountInstance, times(1)).onTopologyDeviceConnected(eq(schemaContext), any(DOMDataBroker.class), any(NetconfDataTreeService.class), eq(deviceRpc), any(NetconfDeviceNotificationService.class), isNull());
verify(netconfDeviceTopologyAdapter, times(1)).updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcService in project netconf by opendaylight.
the class NetconfNodeActorTest method testSlaveInvokeRpc.
@Test
public void testSlaveInvokeRpc() throws Exception {
final List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
initializeMaster(sourceIdentifiers);
registerSlaveMountPoint();
ArgumentCaptor<DOMRpcService> domRPCServiceCaptor = ArgumentCaptor.forClass(DOMRpcService.class);
verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), domRPCServiceCaptor.capture());
final DOMRpcService slaveDomRPCService = domRPCServiceCaptor.getValue();
assertTrue(slaveDomRPCService instanceof ProxyDOMRpcService);
final QName testQName = QName.create("", "TestQname");
final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName)).withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, null, "Rpc invocation failed.");
// RPC with no response output.
doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMRpcService).invokeRpc(any(), any());
DOMRpcResult result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(null, result);
// RPC with response output.
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode))).when(mockDOMRpcService).invokeRpc(any(), any());
result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(outputNode, result.getResult());
assertTrue(result.getErrors().isEmpty());
// RPC with response error.
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertNull(result.getResult());
assertEquals(rpcError, result.getErrors().iterator().next());
// RPC with response output and error.
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode, rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
final DOMRpcResult resultOutputError = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(outputNode, resultOutputError.getResult());
assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
// RPC failure.
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock"))).when(mockDOMRpcService).invokeRpc(any(), any());
final ListenableFuture<? extends DOMRpcResult> future = slaveDomRPCService.invokeRpc(testQName, outputNode);
final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
final Throwable cause = e.getCause();
assertThat(cause, instanceOf(DOMRpcException.class));
assertEquals("mock", cause.getMessage());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcService in project mdsal by opendaylight.
the class OSGiRpcRouterTest method testRpc.
@Test
public void testRpc() {
final DOMRpcService delegate = mock(DOMRpcService.class);
doReturn(delegate).when(router).getRpcService();
new OSGiDOMRpcService(router);
// FIXME: invoke something to test delegate()
}
Aggregations