Introduce restconf.server.{api,spi,mdsal}
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / 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.rfc8040.rests.services.impl;
9
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;
15
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;
37
38 @RunWith(MockitoJUnitRunner.StrictStubs.class)
39 public class Netconf799Test extends AbstractInstanceIdentifierTest {
40     private static final QName OUTPUT_QNAME = QName.create(CONT_QNAME, "output");
41
42     @Mock
43     private DOMDataBroker dataBroker;
44     @Mock
45     private DOMActionService actionService;
46     @Mock
47     private DOMRpcService rpcService;
48     @Mock
49     private DOMMountPointService mountPointService;
50     @Mock
51     private AsyncResponse asyncResponse;
52     @Captor
53     private ArgumentCaptor<Response> captor;
54
55     @Test
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());
60
61         final DatabindProvider databindProvider = () -> DatabindContext.ofModel(IID_SCHEMA);
62         final var dataService = new RestconfDataServiceImpl(databindProvider,
63             new MdsalRestconfServer(databindProvider, dataBroker, rpcService, mountPointService), actionService);
64
65         doReturn(true).when(asyncResponse).resume(captor.capture());
66         dataService.postDataJSON("instance-identifier-module:cont/cont1/reset",
67             stringInputStream("""
68             {
69               "instance-identifier-module:input": {
70                 "delay": 600
71               }
72             }"""), null, asyncResponse);
73         final var response = captor.getValue();
74         assertEquals(204, response.getStatus());
75         assertNull(response.getEntity());
76     }
77 }