32b507fa767dbf95118cfa196cee617edcc5c214
[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")
84                                 .neighborCellIdentifierNrpci("A123456").neighborCellIdentifierNrcgi("A12347").flagNoHo(true)
85                                 .flagNoXn(true).flagNoRemove(true);
86                 NeighborCellRelation e = new NeighborCellRelation().cellIdentifierNrcgi("E12345")
87                                 .neighborCellIdentifierNrpci("E123456").neighborCellIdentifierNrcgi("E12347").flagNoHo(true)
88                                 .flagNoXn(true).flagNoRemove(true);
89                 NeighborCellRelationTable ncrt = new NeighborCellRelationTable().addNcrtRelationsItem(a)
90                                 .addNcrtRelationsItem(e);
91
92                 when(mockApi.getNcrtInfo(any(String.class), any(String.class), any(Integer.class))).thenReturn(ncrt);
93                 when(mockApi.getCellNcrtInfo(any(String.class), any(String.class), any(Integer.class), any(String.class),
94                                 any(String.class))).thenReturn(ncrt);
95
96                 doAnswer(i -> {
97                         return null;
98                 }).when(mockApi).deleteNcrt(any(String.class), any(NeighborCellRelationDelTable.class), any(String.class),
99                                 any(Integer.class), any(String.class), any(String.class));
100
101                 doAnswer(i -> {
102                         return null;
103                 }).when(mockApi).modifyNCRT(any(String.class), any(NeighborCellRelationModTable.class), any(String.class),
104                                 any(Integer.class), any(String.class), any(String.class));
105
106                 return mockApi;
107         }
108
109 }