2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 package org.oransc.ric.portal.dashboard.config;
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;
30 import java.lang.invoke.MethodHandles;
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;
47 * Creates a mock implementation of the ANR xApp client APIs.
51 public class AnrXappMockConfiguration {
53 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
55 private final NeighborCellRelationTable ncrt, ncrtNodeB1, ncrtNodeB2;
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);
78 private ApiClient apiClient() {
79 ApiClient mockClient = mock(ApiClient.class);
80 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
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);
92 }).when(mockApi).getHealthAlive();
95 }).when(mockApi).getHealthReady();
100 public GnodebsApi anrGnodebsMockApi() {
101 ApiClient mockClient = mock(ApiClient.class);
102 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
103 GnodebsApi mockApi = mock(GnodebsApi.class);
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);
120 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
123 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));