Update ANR API to version 0.0.5
[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.Mockito.doAnswer;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26
27 import java.lang.invoke.MethodHandles;
28
29 import org.oransc.ric.anrxapp.client.api.HealthApi;
30 import org.oransc.ric.anrxapp.client.api.NcrtApi;
31 import org.oransc.ric.anrxapp.client.invoker.ApiClient;
32 import org.oransc.ric.anrxapp.client.model.NeighborCellRelation;
33 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationDelTable;
34 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationModTable;
35 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Configuration;
40 import org.springframework.context.annotation.Profile;
41 import org.springframework.http.HttpStatus;
42
43 /**
44  * Creates a mock implementation of the ANR xApp client APIs.
45  */
46 @Profile("mock")
47 @Configuration
48 public class AnrXappMockConfiguration {
49
50         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
51
52         public AnrXappMockConfiguration() {
53                 logger.info("Configuring mock ANR xApp client");
54         }
55
56         private ApiClient apiClient() {
57                 ApiClient mockClient = mock(ApiClient.class);
58                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
59                 return mockClient;
60         }
61
62         @Bean
63         public HealthApi anrHealthMockApi() {
64                 ApiClient mockClient = mock(ApiClient.class);
65                 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
66                 HealthApi mockApi = mock(HealthApi.class);
67                 when(mockApi.getApiClient()).thenReturn(mockClient);
68                 doAnswer(i -> {
69                         return null;
70                 }).when(mockApi).getHealthAlive();
71                 doAnswer(i -> {
72                         return null;
73                 }).when(mockApi).getHealthReady();
74                 return mockApi;
75         }
76
77         @Bean
78         public NcrtApi ncrtPapi() {
79                 ApiClient apiClient = apiClient();
80                 NcrtApi mockApi = mock(NcrtApi.class);
81                 when(mockApi.getApiClient()).thenReturn(apiClient);
82
83                 NeighborCellRelation a = new NeighborCellRelation().cellIdentifierNrcgi("A12345").neighborCellNrpci("A123456")
84                                 .neighborCellNrcgi("A12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true);
85                 NeighborCellRelation e = new NeighborCellRelation().cellIdentifierNrcgi("E12345").neighborCellNrpci("E123456")
86                                 .neighborCellNrcgi("E12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true);
87                 NeighborCellRelationTable ncrt = new NeighborCellRelationTable().addNcrtRelationsItem(a)
88                                 .addNcrtRelationsItem(e);
89
90                 when(mockApi.getNcrtInfo(any(String.class), any(String.class), any(Integer.class))).thenReturn(ncrt);
91                 when(mockApi.getCellNcrtInfo(any(String.class), any(String.class), any(Integer.class), any(String.class),
92                                 any(String.class))).thenReturn(ncrt);
93
94                 doAnswer(i -> {
95                         return null;
96                 }).when(mockApi).deleteNcrt(any(String.class), any(NeighborCellRelationDelTable.class));
97
98                 doAnswer(i -> {
99                         return null;
100                 }).when(mockApi).modifyNcrt(any(String.class), any(NeighborCellRelationModTable.class));
101
102                 return mockApi;
103         }
104
105 }