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.GgNodeBTable;
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;
56 private final GgNodeBTable gNodebTable;
58 public AnrXappMockConfiguration() {
59 logger.info("Configuring mock ANR xApp client");
60 gNodebTable = new GgNodeBTable();
61 gNodebTable.addGNodeBIdsItem("A").addGNodeBIdsItem("B");
62 ncrtNodeB1 = new NeighborCellRelationTable();
63 ncrtNodeB2 = new NeighborCellRelationTable();
64 ncrt = new NeighborCellRelationTable();
65 String[] cells1 = { "A", "B", "C", "D" };
66 for (String s : cells1)
67 ncrtNodeB1.addNcrtRelationsItem(
68 new NeighborCellRelation().servingCellNrcgi(s + "12345").neighborCellNrpci(s + "12346")
69 .neighborCellNrcgi(s + "12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true));
70 String[] cells2 = { "E", "F", "G", "H" };
71 for (String s : cells2)
72 ncrtNodeB2.addNcrtRelationsItem(
73 new NeighborCellRelation().servingCellNrcgi(s + "12345").neighborCellNrpci(s + "12346")
74 .neighborCellNrcgi(s + "12347").flagNoHo(true).flagNoXn(true).flagNoRemove(true));
75 for (NeighborCellRelation ncr : ncrtNodeB1.getNcrtRelations())
76 ncrt.addNcrtRelationsItem(ncr);
77 for (NeighborCellRelation ncr : ncrtNodeB2.getNcrtRelations())
78 ncrt.addNcrtRelationsItem(ncr);
81 private ApiClient apiClient() {
82 ApiClient mockClient = mock(ApiClient.class);
83 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
88 public HealthApi anrHealthApi() {
89 ApiClient apiClient = apiClient();
90 HealthApi mockApi = mock(HealthApi.class);
91 when(mockApi.getApiClient()).thenReturn(apiClient);
94 }).when(mockApi).getHealthAlive();
97 }).when(mockApi).getHealthReady();
102 public NcrtApi ncrtMockApi() {
103 ApiClient apiClient = apiClient();
104 NcrtApi mockApi = mock(NcrtApi.class);
105 when(mockApi.getApiClient()).thenReturn(apiClient);
106 when(mockApi.getgNodeB()).thenReturn(gNodebTable);
107 // Swagger sends nulls; front end sends empty strings
108 when(mockApi.getNcrt((String) isNull(), (String) isNull(), (String) isNull())).thenReturn(ncrt);
109 when(mockApi.getNcrt(eq(""), any(String.class), any(String.class))).thenReturn(ncrt);
110 when(mockApi.getNcrt(startsWith("A"), any(String.class), any(String.class))).thenReturn(ncrtNodeB1);
111 when(mockApi.getNcrt(startsWith("B"), any(String.class), any(String.class))).thenReturn(ncrtNodeB2);
114 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
117 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));