2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.features.a1.adapter;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.when;
27 import com.google.common.util.concurrent.ListenableFuture;
28 import java.util.Properties;
29 import java.util.concurrent.ExecutionException;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
38 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
39 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
40 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyInputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutput;
42 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
43 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyInputBuilder;
44 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutput;
45 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
46 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusInputBuilder;
47 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutput;
48 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
49 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeInputBuilder;
50 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutput;
51 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
52 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyInputBuilder;
53 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutput;
54 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
55 import org.opendaylight.yangtools.yang.common.RpcResult;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
60 * This class Tests all the methods in A1AdapterProvider
64 @RunWith(MockitoJUnitRunner.Silent.class)
65 public class A1AdapterProviderTest {
67 protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
69 class A1AdapterProviderMock extends A1AdapterProvider {
71 A1AdapterProviderMock(final DataBroker dataBroker, final NotificationPublishService notificationPublishService,
72 final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient A1AdapterClient) {
73 super(dataBroker, mockNotificationPublishService, mockRpcProviderRegistry, a1AdapterClient);
78 private A1AdapterProviderMock a1AdapterProviderMock = null;
80 private DataBroker dataBroker;
82 private NotificationPublishService mockNotificationPublishService;
84 private RpcProviderRegistry mockRpcProviderRegistry;
86 private A1AdapterClient a1AdapterClient;
87 private static String module = "A1-ADAPTER-API";
88 private static String mode = "sync";
91 public void setUp() throws Exception {
93 a1AdapterProviderMock = new A1AdapterProviderMock(dataBroker, mockNotificationPublishService,
94 mockRpcProviderRegistry, a1AdapterClient);
95 a1AdapterProviderMock = Mockito.spy(a1AdapterProviderMock);
100 public void test_deleteA1PolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
101 String rpc = "deleteA1Policy";
102 Properties respProps = new Properties();
103 respProps.setProperty("response-code", "200");
104 DeleteA1PolicyInputBuilder inputBuilder = new DeleteA1PolicyInputBuilder();
105 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
106 when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(DeleteA1PolicyOutputBuilder.class),
107 any(Properties.class))).thenReturn(respProps);
108 ListenableFuture<RpcResult<DeleteA1PolicyOutput>> result =
109 a1AdapterProviderMock.deleteA1Policy(inputBuilder.build());
110 assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
114 public void test_getA1Policy() throws SvcLogicException, InterruptedException, ExecutionException {
115 String rpc = "getA1Policy";
116 Properties respProps = new Properties();
117 respProps.setProperty("response-code", "200");
118 GetA1PolicyInputBuilder inputBuilder = new GetA1PolicyInputBuilder();
119 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
120 when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyOutputBuilder.class),
121 any(Properties.class))).thenReturn(respProps);
122 ListenableFuture<RpcResult<GetA1PolicyOutput>> result = a1AdapterProviderMock.getA1Policy(inputBuilder.build());
123 assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
127 public void test_getA1PolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
128 String rpc = "getA1PolicyType";
129 Properties respProps = new Properties();
130 respProps.setProperty("response-code", "200");
131 GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder();
132 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
133 when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyTypeOutputBuilder.class),
134 any(Properties.class))).thenReturn(respProps);
135 ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
136 a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
137 assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
141 public void test_getA1PolicyStatus() throws SvcLogicException, InterruptedException, ExecutionException {
142 String rpc = "getA1PolicyStatus";
143 Properties respProps = new Properties();
144 respProps.setProperty("response-code", "200");
145 GetA1PolicyStatusInputBuilder inputBuilder = new GetA1PolicyStatusInputBuilder();
146 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
147 when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyStatusOutputBuilder.class),
148 any(Properties.class))).thenReturn(respProps);
149 ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> result =
150 a1AdapterProviderMock.getA1PolicyStatus(inputBuilder.build());
151 assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
155 public void test_putA1Policy() throws SvcLogicException, InterruptedException, ExecutionException {
156 String rpc = "putA1Policy";
157 Properties respProps = new Properties();
158 respProps.setProperty("response-code", "200");
159 PutA1PolicyInputBuilder inputBuilder = new PutA1PolicyInputBuilder();
160 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
161 when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(PutA1PolicyOutputBuilder.class),
162 any(Properties.class))).thenReturn(respProps);
163 ListenableFuture<RpcResult<PutA1PolicyOutput>> result = a1AdapterProviderMock.putA1Policy(inputBuilder.build());
164 assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));