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.databind.DatabindProvider;
33 import org.opendaylight.yangtools.yang.common.QName;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
35 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
36 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
38 @RunWith(MockitoJUnitRunner.StrictStubs.class)
39 public class Netconf799Test extends AbstractInstanceIdentifierTest {
40 private static final QName OUTPUT_QNAME = QName.create(CONT_QNAME, "output");
43 private DOMDataBroker dataBroker;
45 private DOMActionService actionService;
47 private DOMRpcService rpcService;
49 private DOMMountPointService mountPointService;
51 private AsyncResponse asyncResponse;
53 private ArgumentCaptor<Response> captor;
56 public void testInvokeAction() {
57 doReturn(Futures.immediateFuture(new SimpleDOMActionResult(
58 Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build())))
59 .when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
61 final DatabindProvider databindProvider = () -> DatabindContext.ofModel(IID_SCHEMA);
62 final var dataService = new RestconfDataServiceImpl(databindProvider,
63 new MdsalRestconfServer(databindProvider, dataBroker, rpcService, mountPointService), actionService);
65 doReturn(true).when(asyncResponse).resume(captor.capture());
66 dataService.postDataJSON("instance-identifier-module:cont/cont1/reset",
69 "instance-identifier-module:input": {
72 }"""), null, asyncResponse);
73 final var response = captor.getValue();
74 assertEquals(204, response.getStatus());
75 assertNull(response.getEntity());