5c4b285747d68052235c84921c8d2169fde736e0
[ccsdk/oran.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.features.a1.adapter;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.when;
27 import java.util.Properties;
28 import java.util.concurrent.ExecutionException;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
36 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
38 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
39 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
40 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * This class Tests all the methods in A1AdapterClientTest
46  *
47  */
48
49 @RunWith(MockitoJUnitRunner.Silent.class)
50 public class A1AdapterClientTest {
51
52     protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterClientTest.class);
53
54     @Mock
55     private SvcLogicService svcLogicService = null;
56     private A1AdapterClient a1AdapterClient;
57     private static String module = "A1-ADAPTER-API";
58     private static String mode = "sync";
59
60     @Before
61     public void setUp() throws Exception {
62         a1AdapterClient = new A1AdapterClient(svcLogicService);
63     }
64
65     @Test
66     public void test_execute_getPolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
67         String rpc = "deleteA1Policy";
68         Properties params = new Properties();
69         Properties respProps = new Properties();
70         GetA1PolicyTypeOutputBuilder serviceData = new GetA1PolicyTypeOutputBuilder();
71         when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
72                 .thenReturn(respProps);
73         Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
74         assertNotNull(response);
75     }
76
77     @Test
78     public void test_execute_getPolicyStatus() throws SvcLogicException, InterruptedException, ExecutionException {
79         String rpc = "getA1PolicyStatus";
80         Properties params = new Properties();
81         Properties respProps = new Properties();
82         GetA1PolicyStatusOutputBuilder serviceData = new GetA1PolicyStatusOutputBuilder();
83         when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
84                 .thenReturn(respProps);
85         Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
86         assertNotNull(response);
87     }
88
89     @Test
90     public void test_execute_getPolicy() throws SvcLogicException, InterruptedException, ExecutionException {
91         String rpc = "getA1Policy";
92         Properties params = new Properties();
93         Properties respProps = new Properties();
94         GetA1PolicyOutputBuilder serviceData = new GetA1PolicyOutputBuilder();
95         when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
96                 .thenReturn(respProps);
97         Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
98         assertNotNull(response);
99     }
100
101     @Test
102     public void test_execute_deletePolicy() throws SvcLogicException, InterruptedException, ExecutionException {
103         String rpc = "deleteA1Policy";
104         Properties params = new Properties();
105         Properties respProps = new Properties();
106         DeleteA1PolicyOutputBuilder serviceData = new DeleteA1PolicyOutputBuilder();
107         when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
108                 .thenReturn(respProps);
109         Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
110         assertNotNull(response);
111     }
112
113     @Test
114     public void test_execute_putPolicy() throws SvcLogicException, InterruptedException, ExecutionException {
115         String rpc = "putA1Policy";
116         Properties params = new Properties();
117         Properties respProps = new Properties();
118         PutA1PolicyOutputBuilder serviceData = new PutA1PolicyOutputBuilder();
119         when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
120                 .thenReturn(respProps);
121         Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
122         assertNotNull(response);
123     }
124 }