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 static final String GNODEB1 = "001EF5:0045FE50";
55 private static final String GNODEB2 = "001EF6:0045FE51";
56 private static final String GNODEB3 = "001EF7:0045FE52";
57 // Sonar wants separate declarations
58 private final NeighborCellRelationTable ncrt;
59 private final NeighborCellRelationTable ncrtNodeB1;
60 private final NeighborCellRelationTable ncrtNodeB2;
61 private final NeighborCellRelationTable ncrtNodeB3;
62 private final GgNodeBTable gNodebTable;
63 // Simulate remote method delay for UI testing
64 private final int delayMs = 500;
66 public AnrXappMockConfiguration() {
67 logger.info("Configuring mock ANR xApp client");
68 gNodebTable = new GgNodeBTable();
69 gNodebTable.addGNodeBIdsItem(GNODEB1).addGNodeBIdsItem(GNODEB2).addGNodeBIdsItem(GNODEB3);
70 ncrtNodeB1 = new NeighborCellRelationTable();
71 ncrtNodeB2 = new NeighborCellRelationTable();
72 ncrtNodeB3 = new NeighborCellRelationTable();
73 ncrt = new NeighborCellRelationTable();
74 String[] neighbors1 = { "1104", "1105", "1106" };
75 for (String n : neighbors1)
76 ncrtNodeB1.addNcrtRelationsItem(
77 new NeighborCellRelation().servingCellNrcgi(GNODEB1 + ":1100").neighborCellNrpci(n)
78 .neighborCellNrcgi(GNODEB1 + ":" + n).flagNoHo(true).flagNoXn(true).flagNoRemove(true));
79 String[] neighbors2 = { "1471", "1472", "1473" };
80 for (String n : neighbors2)
81 ncrtNodeB2.addNcrtRelationsItem(
82 new NeighborCellRelation().servingCellNrcgi(GNODEB2 + ":1400").neighborCellNrpci(n)
83 .neighborCellNrcgi(GNODEB2 + ":" + n).flagNoHo(false).flagNoXn(false).flagNoRemove(false));
84 String[] neighbors3 = { "3601", "3601", "3602" };
85 for (String n : neighbors3)
86 ncrtNodeB3.addNcrtRelationsItem(
87 new NeighborCellRelation().servingCellNrcgi(GNODEB3 + ":3600").neighborCellNrpci(n)
88 .neighborCellNrcgi(GNODEB3 + ":" + n).flagNoHo(true).flagNoXn(true).flagNoRemove(true));
89 for (NeighborCellRelation ncr : ncrtNodeB1.getNcrtRelations())
90 ncrt.addNcrtRelationsItem(ncr);
91 for (NeighborCellRelation ncr : ncrtNodeB2.getNcrtRelations())
92 ncrt.addNcrtRelationsItem(ncr);
93 for (NeighborCellRelation ncr : ncrtNodeB3.getNcrtRelations())
94 ncrt.addNcrtRelationsItem(ncr);
97 private ApiClient apiClient() {
98 ApiClient mockClient = mock(ApiClient.class);
99 when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
104 // Use the same name as regular configuration
105 public HealthApi anrHealthApi() {
106 ApiClient apiClient = apiClient();
107 HealthApi mockApi = mock(HealthApi.class);
108 when(mockApi.getApiClient()).thenReturn(apiClient);
109 doAnswer(i -> null).when(mockApi).getHealthAlive();
110 doAnswer(i -> null).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);
121 logger.debug("getgNodeB sleeping {}", delayMs);
122 Thread.sleep(delayMs);
124 }).when(mockApi).getgNodeB();
125 // Swagger sends nulls; front end sends empty strings
127 logger.debug("getNcrt (1) sleeping {}", delayMs);
128 Thread.sleep(delayMs);
130 }).when(mockApi).getNcrt((String) isNull(), (String) isNull(), (String) isNull());
132 logger.debug("getNcrt (2) sleeping {}", delayMs);
133 Thread.sleep(delayMs);
135 }).when(mockApi).getNcrt(eq(""), any(String.class), any(String.class));
137 logger.debug("getNcrt (3) sleeping {}", delayMs);
138 Thread.sleep(delayMs);
140 }).when(mockApi).getNcrt(eq(GNODEB1), any(String.class), any(String.class));
142 logger.debug("getNcrt (4) sleeping {}", delayMs);
143 Thread.sleep(delayMs);
145 }).when(mockApi).getNcrt(eq(GNODEB2), any(String.class), any(String.class));
147 logger.debug("getNcrt (5) sleeping {}", delayMs);
148 Thread.sleep(delayMs);
150 }).when(mockApi).getNcrt(eq(GNODEB3), any(String.class), any(String.class));
152 logger.debug("deleteNcrt sleeping {}", delayMs);
153 Thread.sleep(delayMs);
155 }).when(mockApi).deleteNcrt(any(String.class), any(String.class));
157 logger.debug("modifyNcrt sleeping {}", delayMs);
158 Thread.sleep(delayMs);
160 }).when(mockApi).modifyNcrt(any(String.class), any(String.class), any(NeighborCellRelationMod.class));