Further warnings mitigation
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / jaxrs / Netconf799Test.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech s.r.o. All Rights Reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.jaxrs;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNull;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.Mockito.doReturn;
15
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.jupiter.api.Test;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.mockito.ArgumentCaptor;
24 import org.mockito.Captor;
25 import org.mockito.Mock;
26 import org.mockito.junit.jupiter.MockitoExtension;
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.FixedDOMSchemaService;
32 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
33 import org.opendaylight.restconf.api.ApiPath;
34 import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest;
35 import org.opendaylight.restconf.server.mdsal.MdsalRestconfServer;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
38 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
39 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
40
41 @ExtendWith(MockitoExtension.class)
42 class Netconf799Test extends AbstractInstanceIdentifierTest {
43     private static final QName OUTPUT_QNAME = QName.create(CONT_QNAME, "output");
44
45     @Mock
46     private UriInfo uriInfo;
47     @Mock
48     private DOMDataBroker dataBroker;
49     @Mock
50     private DOMActionService actionService;
51     @Mock
52     private DOMRpcService rpcService;
53     @Mock
54     private DOMMountPointService mountPointService;
55     @Mock
56     private AsyncResponse asyncResponse;
57     @Captor
58     private ArgumentCaptor<Response> captor;
59
60     @Test
61     void testInvokeAction() throws Exception {
62         doReturn(Futures.immediateFuture(new SimpleDOMActionResult(
63             ImmutableNodes.newContainerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build())))
64             .when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
65
66         final var restconf = new JaxRsRestconf(new MdsalRestconfServer(new FixedDOMSchemaService(IID_SCHEMA),
67             dataBroker, rpcService, actionService, mountPointService));
68         doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
69         doReturn(true).when(asyncResponse).resume(captor.capture());
70         restconf.postDataJSON(ApiPath.parse("instance-identifier-module:cont/cont1/reset"),
71             stringInputStream("""
72             {
73               "instance-identifier-module:input": {
74                 "delay": 600
75               }
76             }"""), uriInfo, asyncResponse);
77         final var response = captor.getValue();
78         assertEquals(204, response.getStatus());
79         assertNull(response.getEntity());
80     }
81 }