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.mdsal.binding.api.NotificationPublishService;
37 import org.opendaylight.mdsal.binding.api.RpcProviderService;
38 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.*;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 @ExtendWith(MockitoExtension.class)
44 class A1AdapterProviderTest {
46 private static final String RESPONSE_CODE = "response-code";
47 private static final String OK_RESPONSE = "200";
49 protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
51 private A1AdapterProvider a1AdapterProviderMock = null;
53 private NotificationPublishService mockNotificationPublishService;
55 private RpcProviderService mockRpcService;
57 private A1AdapterClient a1AdapterClient;
58 private static String module = "A1-ADAPTER-API";
59 private static String mode = "sync";
63 a1AdapterProviderMock = Mockito.spy(new A1AdapterProvider(mockNotificationPublishService,
64 mockRpcService, a1AdapterClient));
68 void deleteA1PolicyType() throws Exception {
69 String rpc = "deleteA1Policy";
70 Properties respProps = new Properties();
71 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
72 DeleteA1PolicyInputBuilder inputBuilder = new DeleteA1PolicyInputBuilder();
73 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
75 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(DeleteA1PolicyOutputBuilder.class), any(Properties.class)))
76 .thenReturn(respProps);
77 ListenableFuture<RpcResult<DeleteA1PolicyOutput>> result =
78 a1AdapterProviderMock.deleteA1Policy(inputBuilder.build());
79 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
83 void getA1Policy() throws Exception {
84 String rpc = "getA1Policy";
85 Properties respProps = new Properties();
86 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
87 GetA1PolicyInputBuilder inputBuilder = new GetA1PolicyInputBuilder();
88 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
90 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyOutputBuilder.class), any(Properties.class)))
91 .thenReturn(respProps);
92 ListenableFuture<RpcResult<GetA1PolicyOutput>> result = a1AdapterProviderMock.getA1Policy(inputBuilder.build());
93 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
97 void getA1PolicyType() throws Exception {
98 String rpc = "getA1PolicyType";
99 Properties respProps = new Properties();
100 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
101 GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder();
102 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
104 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyTypeOutputBuilder.class), any(Properties.class)))
105 .thenReturn(respProps);
106 ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
107 a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
108 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
112 void getA1PolicyStatus() throws Exception {
113 String rpc = "getA1PolicyStatus";
114 Properties respProps = new Properties();
115 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
116 GetA1PolicyStatusInputBuilder inputBuilder = new GetA1PolicyStatusInputBuilder();
117 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
119 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyStatusOutputBuilder.class), any(Properties.class)))
120 .thenReturn(respProps);
121 ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> result =
122 a1AdapterProviderMock.getA1PolicyStatus(inputBuilder.build());
123 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
127 void putA1Policy() throws Exception {
128 String rpc = "putA1Policy";
129 Properties respProps = new Properties();
130 respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
131 PutA1PolicyInputBuilder inputBuilder = new PutA1PolicyInputBuilder();
132 when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
134 a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(PutA1PolicyOutputBuilder.class), any(Properties.class)))
135 .thenReturn(respProps);
136 ListenableFuture<RpcResult<PutA1PolicyOutput>> result = a1AdapterProviderMock.putA1Policy(inputBuilder.build());
137 assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));