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.GetA1PolicyTypeInputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutput;
42 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
43 import org.opendaylight.yangtools.yang.common.RpcResult;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * This class Tests all the methods in A1AdapterProvider
52 @RunWith(MockitoJUnitRunner.Silent.class)
53 public class A1AdapterProviderTest {
55 protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
57 class A1AdapterProviderMock extends A1AdapterProvider {
59 A1AdapterProviderMock(final DataBroker dataBroker,
60 final NotificationPublishService notificationPublishService,
61 final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient A1AdapterClient) {
62 super(dataBroker, mockNotificationPublishService, mockRpcProviderRegistry, a1AdapterClient);
67 private A1AdapterProviderMock a1AdapterProviderMock = null;
69 private DataBroker dataBroker;
71 private NotificationPublishService mockNotificationPublishService;
73 private RpcProviderRegistry mockRpcProviderRegistry;
75 private A1AdapterClient a1AdapterClient;
76 private static String module = "A1-ADAPTER-API";
77 private static String mode = "sync";
80 public void setUp() throws Exception {
82 a1AdapterProviderMock = new A1AdapterProviderMock(dataBroker, mockNotificationPublishService,
83 mockRpcProviderRegistry, a1AdapterClient);
84 a1AdapterProviderMock = Mockito.spy(a1AdapterProviderMock);
89 public void test_getA1PolicyType()
90 throws SvcLogicException, InterruptedException, ExecutionException {
91 String rpc = "getA1PolicyType";
92 Properties respProps = new Properties();
93 GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder();
94 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
95 when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode),
96 any(GetA1PolicyTypeOutputBuilder.class), any(Properties.class))).thenReturn(respProps);
97 ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
98 a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
99 assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));