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.HealthApi;
33 import org.oransc.ric.anrxapp.client.api.NcrtApi;
34 import org.oransc.ric.anrxapp.client.invoker.ApiClient;
35 import org.oransc.ric.anrxapp.client.model.NeighborCellRelation;
36 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationMod;
37 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.context.annotation.Bean;
41 import org.springframework.context.annotation.Configuration;
42 import org.springframework.context.annotation.Profile;
43 import org.springframework.http.HttpStatus;
46 * Creates a mock implementation of the ANR xApp client APIs.
50 public class AnrXappMockConfiguration {
52 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
54 private final NeighborCellRelationTable ncrt, ncrtNodeB1, ncrtNodeB2;
56 public AnrXappMockConfiguration() {
57 logger.info("Configuring mock ANR xApp client");
58 ncrtNodeB1 = new NeighborCellRelationTable();
59 ncrtNodeB2 = new NeighborCellRelationTable();
60 ncrt = new NeighborCellRelationTable();
61 String[] cells1 = { "A", "B", "C", "D" };
62 for (String s : cells1)
63 ncrtNodeB1.addNcrtRelationsItem(
64 new NeighborCellRelation().servingCellNrcgi(s + "12345").neighborCellNrpci(s + "12346")
65 .neighborCellNrcgi(s + "12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true));
66 String[] cells2 = { "E", "F", "G", "H" };
67 for (String s : cells2)
68 ncrtNodeB2.addNcrtRelationsItem(
69 new NeighborCellRelation().servingCellNrcgi(s + "12345").neighborCellNrpci(s + "12346")
70 .neighborCellNrcgi(s + "12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true));
71 for (NeighborCellRelation ncr : ncrtNodeB1.getNcrtRelations())
72 ncrt.addNcrtRelationsItem(ncr);
73 for (NeighborCellRelation ncr : ncrtNodeB2.getNcrtRelations())
74 ncrt.addNcrtRelationsItem(ncr);
77 private ApiClient apiClient() {
78 ApiClient mockClient = mock(ApiClient.class);
79 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
84 public HealthApi anrHealthMockApi() {
85 ApiClient mockClient = mock(ApiClient.class);
86 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
87 HealthApi mockApi = mock(HealthApi.class);
88 when(mockApi.getApiClient()).thenReturn(mockClient);
91 }).when(mockApi).getHealthAlive();
94 }).when(mockApi).getHealthReady();
99 public NcrtApi ncrtMockApi() {
100 ApiClient apiClient = apiClient();
101 NcrtApi mockApi = mock(NcrtApi.class);
102 when(mockApi.getApiClient()).thenReturn(apiClient);
103 // Swagger sends nulls; front end sends empty strings
104 when(mockApi.getNcrt((String) isNull(), (String) isNull(), (String) isNull())).thenReturn(ncrt);
105 when(mockApi.getNcrt(eq(""), any(String.class), any(String.class))).thenReturn(ncrt);
106 when(mockApi.getNcrt(startsWith("A"), any(String.class), any(String.class))).thenReturn(ncrtNodeB1);
107 when(mockApi.getNcrt(startsWith("B"), any(String.class), any(String.class))).thenReturn(ncrtNodeB2);
110 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
113 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));