2 * Copyright (c) 2021 PANTHEON.tech s.r.o. All Rights Reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.Mockito.doReturn;
16 import com.google.common.util.concurrent.Futures;
17 import javax.ws.rs.container.AsyncResponse;
18 import javax.ws.rs.core.Response;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.ArgumentCaptor;
22 import org.mockito.Captor;
23 import org.mockito.Mock;
24 import org.mockito.junit.MockitoJUnitRunner;
25 import org.opendaylight.mdsal.dom.api.DOMActionService;
26 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
27 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
28 import org.opendaylight.mdsal.dom.api.DOMRpcService;
29 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
30 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
31 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
32 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
33 import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
34 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
35 import org.opendaylight.yangtools.yang.common.QName;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
37 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
38 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
40 @RunWith(MockitoJUnitRunner.StrictStubs.class)
41 public class Netconf799Test extends AbstractInstanceIdentifierTest {
42 private static final QName OUTPUT_QNAME = QName.create(CONT_QNAME, "output");
45 private DOMDataBroker dataBroker;
47 private DOMActionService actionService;
49 private DOMRpcService rpcService;
51 private DOMMountPointService mountPointService;
53 private RestconfStreamsSubscriptionService restconfStreamSubService;
55 private AsyncResponse asyncResponse;
57 private ArgumentCaptor<Response> captor;
60 public void testInvokeAction() {
61 doReturn(Futures.immediateFuture(new SimpleDOMActionResult(
62 Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build())))
63 .when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
65 final var dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(IID_SCHEMA),
66 new MdsalRestconfServer(dataBroker, rpcService, mountPointService), dataBroker, restconfStreamSubService,
67 actionService, new ListenersBroker(), new StreamsConfiguration(0, 1, 0, false));
69 doReturn(true).when(asyncResponse).resume(captor.capture());
70 dataService.postDataJSON("instance-identifier-module:cont/cont1/reset",
73 "instance-identifier-module:input": {
76 }"""), null, asyncResponse);
77 final var response = captor.getValue();
78 assertEquals(204, response.getStatus());
79 assertNull(response.getEntity());