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.jupiter.api.Assertions.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.when;
28 import com.google.common.util.concurrent.ListenableFuture;
29 import java.util.Properties;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.junit.jupiter.MockitoExtension;
36 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
37 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
38 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyInputBuilder;
39 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutput;
40 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyInputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutput;
42 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusInputBuilder;
43 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutput;
44 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeInputBuilder;
45 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutput;
46 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyInputBuilder;
47 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutput;
48 import org.opendaylight.yangtools.concepts.Builder;
49 import org.opendaylight.yangtools.yang.common.RpcResult;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
53 @ExtendWith(MockitoExtension.class)
54 class A1AdapterProviderTest {
56 private static final String RESPONSE_CODE = "response-code";
57 private static final String OK_RESPONSE = "200";
59 protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
61 private A1AdapterProvider a1AdapterProviderMock = null;
63 private NotificationPublishService mockNotificationPublishService;
65 private RpcProviderRegistry mockRpcProviderRegistry;
67 private A1AdapterClient a1AdapterClient;
68 private static String module = "A1-ADAPTER-API";
69 private static String mode = "sync";
73 a1AdapterProviderMock = Mockito.spy(new A1AdapterProvider(mockNotificationPublishService,
74 mockRpcProviderRegistry, a1AdapterClient));
78 void deleteA1PolicyType() throws Exception {
79 String rpc = "deleteA1Policy";
80 Properties respProps = new Properties();
81 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
82 DeleteA1PolicyInputBuilder inputBuilder = new DeleteA1PolicyInputBuilder();
83 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
85 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
86 .thenReturn(respProps);
87 ListenableFuture<RpcResult<DeleteA1PolicyOutput>> result =
88 a1AdapterProviderMock.deleteA1Policy(inputBuilder.build());
89 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
93 void getA1Policy() throws Exception {
94 String rpc = "getA1Policy";
95 Properties respProps = new Properties();
96 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
97 GetA1PolicyInputBuilder inputBuilder = new GetA1PolicyInputBuilder();
98 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
100 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
101 .thenReturn(respProps);
102 ListenableFuture<RpcResult<GetA1PolicyOutput>> result = a1AdapterProviderMock.getA1Policy(inputBuilder.build());
103 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
107 void getA1PolicyType() throws Exception {
108 String rpc = "getA1PolicyType";
109 Properties respProps = new Properties();
110 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
111 GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder();
112 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
114 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
115 .thenReturn(respProps);
116 ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
117 a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
118 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
122 void getA1PolicyStatus() throws Exception {
123 String rpc = "getA1PolicyStatus";
124 Properties respProps = new Properties();
125 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
126 GetA1PolicyStatusInputBuilder inputBuilder = new GetA1PolicyStatusInputBuilder();
127 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
129 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
130 .thenReturn(respProps);
131 ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> result =
132 a1AdapterProviderMock.getA1PolicyStatus(inputBuilder.build());
133 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
137 void putA1Policy() throws Exception {
138 String rpc = "putA1Policy";
139 Properties respProps = new Properties();
140 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
141 PutA1PolicyInputBuilder inputBuilder = new PutA1PolicyInputBuilder();
142 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
144 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
145 .thenReturn(respProps);
146 ListenableFuture<RpcResult<PutA1PolicyOutput>> result = a1AdapterProviderMock.putA1Policy(inputBuilder.build());
147 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));