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.Mockito.doAnswer;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.lang.invoke.MethodHandles;
31 import org.oransc.ric.anrxapp.client.api.HealthApi;
32 import org.oransc.ric.anrxapp.client.api.NcrtApi;
33 import org.oransc.ric.anrxapp.client.invoker.ApiClient;
34 import org.oransc.ric.anrxapp.client.model.GgNodeBTable;
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, ncrtNodeB3;
55 private final GgNodeBTable gNodebTable;
57 private static final String gnodeb1 = "001EF5:0045FE50";
58 private static final String gnodeb2 = "001EF6:0045FE51";
59 private static final String gnodeb3 = "001EF7:0045FE52";
61 public AnrXappMockConfiguration() {
63 logger.info("Configuring mock ANR xApp client");
64 gNodebTable = new GgNodeBTable();
65 gNodebTable.addGNodeBIdsItem(gnodeb1).addGNodeBIdsItem(gnodeb2).addGNodeBIdsItem(gnodeb3);
66 ncrtNodeB1 = new NeighborCellRelationTable();
67 ncrtNodeB2 = new NeighborCellRelationTable();
68 ncrtNodeB3 = new NeighborCellRelationTable();
69 ncrt = new NeighborCellRelationTable();
70 String[] neighbors1 = { "1104", "1105", "1106" };
71 for (String n : neighbors1)
72 ncrtNodeB1.addNcrtRelationsItem(
73 new NeighborCellRelation().servingCellNrcgi(gnodeb1 + ":1100").neighborCellNrpci(n)
74 .neighborCellNrcgi(gnodeb1 + ":" + n).flagNoHo(true).flagNoXn(true).flagNoRemove(true));
75 String[] neighbors2 = { "1471", "1472", "1473" };
76 for (String n : neighbors2)
77 ncrtNodeB2.addNcrtRelationsItem(
78 new NeighborCellRelation().servingCellNrcgi(gnodeb2 + ":1400").neighborCellNrpci(n)
79 .neighborCellNrcgi(gnodeb2 + ":" + n).flagNoHo(false).flagNoXn(false).flagNoRemove(false));
80 String[] neighbors3 = { "3601", "3601", "3602" };
81 for (String n : neighbors3)
82 ncrtNodeB3.addNcrtRelationsItem(
83 new NeighborCellRelation().servingCellNrcgi(gnodeb3 + ":3600").neighborCellNrpci(n)
84 .neighborCellNrcgi(gnodeb3 + ":" + n).flagNoHo(true).flagNoXn(true).flagNoRemove(true));
85 for (NeighborCellRelation ncr : ncrtNodeB1.getNcrtRelations())
86 ncrt.addNcrtRelationsItem(ncr);
87 for (NeighborCellRelation ncr : ncrtNodeB2.getNcrtRelations())
88 ncrt.addNcrtRelationsItem(ncr);
89 for (NeighborCellRelation ncr : ncrtNodeB3.getNcrtRelations())
90 ncrt.addNcrtRelationsItem(ncr);
93 private ApiClient apiClient() {
94 ApiClient mockClient = mock(ApiClient.class);
95 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
100 // Use the same name as regular configuration
101 public HealthApi anrHealthApi() {
102 ApiClient apiClient = apiClient();
103 HealthApi mockApi = mock(HealthApi.class);
104 when(mockApi.getApiClient()).thenReturn(apiClient);
107 }).when(mockApi).getHealthAlive();
110 }).when(mockApi).getHealthReady();
115 // Use the same name as regular configuration
116 public NcrtApi anrNcrtApi() {
117 ApiClient apiClient = apiClient();
118 NcrtApi mockApi = mock(NcrtApi.class);
119 when(mockApi.getApiClient()).thenReturn(apiClient);
120 when(mockApi.getgNodeB()).thenReturn(gNodebTable);
121 // Swagger sends nulls; front end sends empty strings
122 when(mockApi.getNcrt((String) isNull(), (String) isNull(), (String) isNull())).thenReturn(ncrt);
123 when(mockApi.getNcrt(eq(""), any(String.class), any(String.class))).thenReturn(ncrt);
124 when(mockApi.getNcrt(eq(gnodeb1), any(String.class), any(String.class))).thenReturn(ncrtNodeB1);
125 when(mockApi.getNcrt(eq(gnodeb2), any(String.class), any(String.class))).thenReturn(ncrtNodeB2);
126 when(mockApi.getNcrt(eq(gnodeb3), any(String.class), any(String.class))).thenReturn(ncrtNodeB3);
129 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
132 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));