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.MultivaluedHashMap;
19 import javax.ws.rs.core.Response;
20 import javax.ws.rs.core.UriInfo;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.ArgumentCaptor;
24 import org.mockito.Captor;
25 import org.mockito.Mock;
26 import org.mockito.junit.MockitoJUnitRunner;
27 import org.opendaylight.mdsal.dom.api.DOMActionService;
28 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
29 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
30 import org.opendaylight.mdsal.dom.api.DOMRpcService;
31 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
32 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
33 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
34 import org.opendaylight.restconf.server.mdsal.MdsalRestconfServer;
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 UriInfo uriInfo;
47 private DOMDataBroker dataBroker;
49 private DOMActionService actionService;
51 private DOMRpcService rpcService;
53 private DOMMountPointService mountPointService;
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 restconf = new RestconfImpl(new MdsalRestconfServer(
66 () -> DatabindContext.ofModel(IID_SCHEMA), dataBroker, rpcService, actionService, mountPointService));
67 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
68 doReturn(true).when(asyncResponse).resume(captor.capture());
69 restconf.postDataJSON("instance-identifier-module:cont/cont1/reset",
72 "instance-identifier-module:input": {
75 }"""), uriInfo, asyncResponse);
76 final var response = captor.getValue();
77 assertEquals(204, response.getStatus());
78 assertNull(response.getEntity());