use of org.opendaylight.mdsal.dom.api.DOMActionService in project mdsal by opendaylight.
the class DOMRpcRouterTest method testActionInstanceRouting.
@Test
public void testActionInstanceRouting() throws ExecutionException {
try (DOMRpcRouter rpcRouter = actionsRouter()) {
final DOMActionProviderService actionProvider = rpcRouter.getActionProviderService();
assertNotNull(actionProvider);
final DOMActionService actionConsumer = rpcRouter.getActionService();
assertNotNull(actionConsumer);
try (ObjectRegistration<?> reg = actionProvider.registerActionImplementation(IMPL, DOMActionInstance.of(Actions.BAZ_TYPE, LogicalDatastoreType.OPERATIONAL, BAZ_PATH_GOOD))) {
assertAvailable(actionConsumer, BAZ_PATH_GOOD);
assertUnavailable(actionConsumer, BAZ_PATH_BAD);
}
assertUnavailable(actionConsumer, BAZ_PATH_BAD);
assertUnavailable(actionConsumer, BAZ_PATH_GOOD);
}
}
use of org.opendaylight.mdsal.dom.api.DOMActionService in project mdsal by opendaylight.
the class DOMRpcRouterTest method testActionDatastoreRouting.
@Test
public void testActionDatastoreRouting() throws ExecutionException {
try (DOMRpcRouter rpcRouter = actionsRouter()) {
final DOMActionProviderService actionProvider = rpcRouter.getActionProviderService();
assertNotNull(actionProvider);
final DOMActionService actionConsumer = rpcRouter.getActionService();
assertNotNull(actionConsumer);
try (ObjectRegistration<?> reg = actionProvider.registerActionImplementation(IMPL, DOMActionInstance.of(Actions.BAZ_TYPE, LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty()))) {
assertAvailable(actionConsumer, BAZ_PATH_GOOD);
assertAvailable(actionConsumer, BAZ_PATH_BAD);
}
assertUnavailable(actionConsumer, BAZ_PATH_BAD);
assertUnavailable(actionConsumer, BAZ_PATH_GOOD);
}
}
use of org.opendaylight.mdsal.dom.api.DOMActionService in project netconf by opendaylight.
the class NetconfNodeActorTest method testSlaveInvokeAction.
@Test
public void testSlaveInvokeAction() throws Exception {
final List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testActionID"));
initializeMaster(sourceIdentifiers);
registerSlaveMountPoint();
ArgumentCaptor<DOMActionService> domActionServiceCaptor = ArgumentCaptor.forClass(DOMActionService.class);
verify(mockMountPointBuilder).addService(eq(DOMActionService.class), domActionServiceCaptor.capture());
final DOMActionService slaveDomActionService = domActionServiceCaptor.getValue();
assertTrue(slaveDomActionService instanceof ProxyDOMActionService);
final QName testQName = QName.create("test", "2019-08-16", "TestActionQname");
final Absolute schemaPath = Absolute.of(testQName);
final YangInstanceIdentifier yangIIdPath = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(testQName));
final DOMDataTreeIdentifier domDataTreeIdentifier = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIIdPath);
final ContainerNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName)).withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
// Action with no response output.
doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMActionService).invokeAction(any(), any(), any());
DOMActionResult result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(null, result);
// Action with response output.
doReturn(FluentFutures.immediateFluentFuture(new SimpleDOMActionResult(outputNode))).when(mockDOMActionService).invokeAction(any(), any(), any());
result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(outputNode, result.getOutput().get());
assertTrue(result.getErrors().isEmpty());
// Action failure.
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringActionException("mock"))).when(mockDOMActionService).invokeAction(any(), any(), any());
final ListenableFuture<? extends DOMActionResult> future = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode);
final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
final Throwable cause = e.getCause();
assertThat(cause, instanceOf(DOMActionException.class));
assertEquals("mock", cause.getMessage());
}
use of org.opendaylight.mdsal.dom.api.DOMActionService in project netconf by opendaylight.
the class Netconf799Test method testInvokeAction.
@Test
public void testInvokeAction() throws FileNotFoundException {
final EffectiveModelContext contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/instanceidentifier/yang"));
final DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker, mock(DOMSchemaService.class));
schemaContextHandler.onModelContextUpdated(contextRef);
final DOMActionService actionService = mock(DOMActionService.class);
doReturn(Futures.immediateFuture(new SimpleDOMActionResult(Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build()))).when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
final RestconfDataServiceImpl dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, mock(DOMMountPointService.class), mock(RestconfStreamsSubscriptionService.class), actionService, mock(Configuration.class));
final var schemaNode = loadAction(contextRef, RESET_QNAME, ACTION_YII).orElseThrow();
final var response = dataService.invokeAction(NormalizedNodePayload.of(new InstanceIdentifierContext<>(ACTION_YII, schemaNode, null, contextRef), Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(INPUT_QNAME)).withChild(ImmutableNodes.leafNode(DELAY_QNAME, Uint32.TEN)).build()));
assertEquals(204, response.getStatus());
assertNull(response.getEntity());
}
use of org.opendaylight.mdsal.dom.api.DOMActionService in project mdsal by opendaylight.
the class OSGiRpcRouterTest method testAction.
@Test
public void testAction() {
final DOMActionService delegate = mock(DOMActionService.class);
doReturn(delegate).when(router).getActionService();
new OSGiDOMActionService(router);
// FIXME: invoke something to test delegate()
}
Aggregations