2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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.beans.factory.annotation.Value;
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 // Simulate remote method delay for UI testing
56 @Value("${mock.config.delay:0}")
59 private static final String GNODEB1 = "001EF5:0045FE50";
60 private static final String GNODEB2 = "001EF6:0045FE51";
61 private static final String GNODEB3 = "001EF7:0045FE52";
63 // Sonar wants separate declarations
64 private final NeighborCellRelationTable ncrt;
65 private final NeighborCellRelationTable ncrtNodeB1;
66 private final NeighborCellRelationTable ncrtNodeB2;
67 private final NeighborCellRelationTable ncrtNodeB3;
68 private final GgNodeBTable gNodebTable;
70 public AnrXappMockConfiguration() {
71 logger.info("Configuring mock ANR xApp client");
72 gNodebTable = new GgNodeBTable();
73 gNodebTable.addGNodeBIdsItem(GNODEB1).addGNodeBIdsItem(GNODEB2).addGNodeBIdsItem(GNODEB3);
74 ncrtNodeB1 = new NeighborCellRelationTable();
75 ncrtNodeB2 = new NeighborCellRelationTable();
76 ncrtNodeB3 = new NeighborCellRelationTable();
77 ncrt = new NeighborCellRelationTable();
78 String[] neighbors1 = { "1104", "1105", "1106" };
79 for (String n : neighbors1)
80 ncrtNodeB1.addNcrtRelationsItem(
81 new NeighborCellRelation().servingCellNrcgi(GNODEB1 + ":1100").neighborCellNrpci(n)
82 .neighborCellNrcgi(GNODEB1 + ":" + n).flagNoHo(true).flagNoXn(true).flagNoRemove(true));
83 String[] neighbors2 = { "1471", "1472", "1473" };
84 for (String n : neighbors2)
85 ncrtNodeB2.addNcrtRelationsItem(
86 new NeighborCellRelation().servingCellNrcgi(GNODEB2 + ":1400").neighborCellNrpci(n)
87 .neighborCellNrcgi(GNODEB2 + ":" + n).flagNoHo(false).flagNoXn(false).flagNoRemove(false));
88 String[] neighbors3 = { "3601", "3601", "3602" };
89 for (String n : neighbors3)
90 ncrtNodeB3.addNcrtRelationsItem(
91 new NeighborCellRelation().servingCellNrcgi(GNODEB3 + ":3600").neighborCellNrpci(n)
92 .neighborCellNrcgi(GNODEB3 + ":" + n).flagNoHo(true).flagNoXn(true).flagNoRemove(true));
93 for (NeighborCellRelation ncr : ncrtNodeB1.getNcrtRelations())
94 ncrt.addNcrtRelationsItem(ncr);
95 for (NeighborCellRelation ncr : ncrtNodeB2.getNcrtRelations())
96 ncrt.addNcrtRelationsItem(ncr);
97 for (NeighborCellRelation ncr : ncrtNodeB3.getNcrtRelations())
98 ncrt.addNcrtRelationsItem(ncr);
101 private ApiClient apiClient() {
102 ApiClient mockClient = mock(ApiClient.class);
103 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
108 // Use the same name as regular configuration
109 public HealthApi anrHealthApi() {
110 ApiClient apiClient = apiClient();
111 HealthApi mockApi = mock(HealthApi.class);
112 when(mockApi.getApiClient()).thenReturn(apiClient);
113 doAnswer(i -> null).when(mockApi).getHealthAlive();
114 doAnswer(i -> null).when(mockApi).getHealthReady();
119 // Use the same name as regular configuration
120 public NcrtApi anrNcrtApi() {
121 ApiClient apiClient = apiClient();
122 NcrtApi mockApi = mock(NcrtApi.class);
123 when(mockApi.getApiClient()).thenReturn(apiClient);
126 logger.debug("getgNodeB sleeping {}", delayMs);
127 Thread.sleep(delayMs);
130 }).when(mockApi).getgNodeB();
131 // Swagger sends nulls; front end sends empty strings
134 logger.debug("getNcrt (1) sleeping {}", delayMs);
135 Thread.sleep(delayMs);
138 }).when(mockApi).getNcrt((String) isNull(), (String) isNull(), (String) isNull());
141 logger.debug("getNcrt (2) sleeping {}", delayMs);
142 Thread.sleep(delayMs);
145 }).when(mockApi).getNcrt(eq(""), any(String.class), any(String.class));
148 logger.debug("getNcrt (3) sleeping {}", delayMs);
149 Thread.sleep(delayMs);
152 }).when(mockApi).getNcrt(eq(GNODEB1), any(String.class), any(String.class));
155 logger.debug("getNcrt (4) sleeping {}", delayMs);
156 Thread.sleep(delayMs);
159 }).when(mockApi).getNcrt(eq(GNODEB2), any(String.class), any(String.class));
162 logger.debug("getNcrt (5) sleeping {}", delayMs);
163 Thread.sleep(delayMs);
166 }).when(mockApi).getNcrt(eq(GNODEB3), any(String.class), any(String.class));
169 logger.debug("deleteNcrt sleeping {}", delayMs);
170 Thread.sleep(delayMs);
172 String servCellNrcgi = inv.<String>getArgument(0);
173 String neighCellNrpci = inv.<String>getArgument(1);
174 for (NeighborCellRelation ncr : ncrt.getNcrtRelations()) {
175 if (servCellNrcgi.equals(ncr.getServingCellNrcgi())
176 && neighCellNrpci.equals(ncr.getNeighborCellNrpci())) {
177 logger.debug("deleteNcrt: removing {}", ncr);
178 ncrt.getNcrtRelations().remove(ncr);
183 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
186 logger.debug("modifyNcrt sleeping {}", delayMs);
187 Thread.sleep(delayMs);
189 String servCellNrcgi = inv.<String>getArgument(0);
190 String neighCellNrpci = inv.<String>getArgument(1);
191 NeighborCellRelationMod mod = inv.<NeighborCellRelationMod>getArgument(2);
192 for (NeighborCellRelation ncr : ncrt.getNcrtRelations()) {
193 if (servCellNrcgi.equals(ncr.getServingCellNrcgi())
194 && neighCellNrpci.equals(ncr.getNeighborCellNrpci())) {
195 logger.debug("modifyNcrt: modifying {} to {}", ncr, mod);
196 ncr.setFlagNoHo(mod.isFlagNoHo());
197 ncr.setFlagNoRemove(mod.isFlagNoRemove());
198 ncr.setFlagNoXn(mod.isFlagNoXn());
203 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));