Add missing @Bean method to create ggNodebsApi
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / config / AnrXappMockConfiguration.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 package org.oransc.ric.portal.dashboard.config;
21
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.ArgumentMatchers.isNull;
25 import static org.mockito.ArgumentMatchers.startsWith;
26 import static org.mockito.Mockito.doAnswer;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29
30 import java.lang.invoke.MethodHandles;
31
32 import org.oransc.ric.anrxapp.client.api.GnodebsApi;
33 import org.oransc.ric.anrxapp.client.api.HealthApi;
34 import org.oransc.ric.anrxapp.client.api.NcrtApi;
35 import org.oransc.ric.anrxapp.client.invoker.ApiClient;
36 import org.oransc.ric.anrxapp.client.model.NeighborCellRelation;
37 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationMod;
38 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Profile;
44 import org.springframework.http.HttpStatus;
45
46 /**
47  * Creates a mock implementation of the ANR xApp client APIs.
48  */
49 @Profile("mock")
50 @Configuration
51 public class AnrXappMockConfiguration {
52
53         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
54
55         private final NeighborCellRelationTable ncrt, ncrtNodeB1, ncrtNodeB2;
56         
57         public AnrXappMockConfiguration() {
58                 logger.info("Configuring mock ANR xApp client");
59                 ncrtNodeB1 = new NeighborCellRelationTable();
60                 ncrtNodeB2 = new NeighborCellRelationTable();
61                 ncrt = new NeighborCellRelationTable();
62                 String[] cells1 = { "A", "B", "C", "D" };
63                 for (String s : cells1)
64                         ncrtNodeB1.addNcrtRelationsItem(
65                                         new NeighborCellRelation().servingCellNrcgi(s + "12345").neighborCellNrpci(s + "12346")
66                                                         .neighborCellNrcgi(s + "12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true));
67                 String[] cells2 = { "E", "F", "G", "H" };
68                 for (String s : cells2)
69                         ncrtNodeB2.addNcrtRelationsItem(
70                                         new NeighborCellRelation().servingCellNrcgi(s + "12345").neighborCellNrpci(s + "12346")
71                                                         .neighborCellNrcgi(s + "12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true));
72                 for (NeighborCellRelation ncr : ncrtNodeB1.getNcrtRelations())
73                         ncrt.addNcrtRelationsItem(ncr);
74                 for (NeighborCellRelation ncr : ncrtNodeB2.getNcrtRelations())
75                         ncrt.addNcrtRelationsItem(ncr);
76         }
77
78         private ApiClient apiClient() {
79                 ApiClient mockClient = mock(ApiClient.class);
80                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
81                 return mockClient;
82         }
83
84         @Bean
85         public HealthApi anrHealthMockApi() {
86                 ApiClient mockClient = mock(ApiClient.class);
87                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
88                 HealthApi mockApi = mock(HealthApi.class);
89                 when(mockApi.getApiClient()).thenReturn(mockClient);
90                 doAnswer(i -> {
91                         return null;
92                 }).when(mockApi).getHealthAlive();
93                 doAnswer(i -> {
94                         return null;
95                 }).when(mockApi).getHealthReady();
96                 return mockApi;
97         }
98         
99         @Bean
100         public GnodebsApi anrGnodebsMockApi() {
101                 ApiClient mockClient = mock(ApiClient.class);
102                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
103                 GnodebsApi mockApi = mock(GnodebsApi.class);
104                 
105                 return mockApi;
106         }
107
108         @Bean
109         public NcrtApi ncrtMockApi() {
110                 ApiClient apiClient = apiClient();
111                 NcrtApi mockApi = mock(NcrtApi.class);
112                 when(mockApi.getApiClient()).thenReturn(apiClient);
113                 // Swagger sends nulls; front end sends empty strings
114                 when(mockApi.getNcrtInfo((String) isNull(), (String) isNull(), (String) isNull())).thenReturn(ncrt);
115                 when(mockApi.getNcrtInfo(eq(""), any(String.class), any(String.class))).thenReturn(ncrt);
116                 when(mockApi.getNcrtInfo(startsWith("A"), any(String.class), any(String.class))).thenReturn(ncrtNodeB1);
117                 when(mockApi.getNcrtInfo(startsWith("B"), any(String.class), any(String.class))).thenReturn(ncrtNodeB2);
118                 doAnswer(i -> {
119                         return null;
120                 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
121                 doAnswer(i -> {
122                         return null;
123                 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));
124                 return mockApi;
125         }
126
127 }