X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fconfig%2FE2ManagerMockConfiguration.java;h=3f33f40be460ec88ac03a625061e89ab7a445b66;hb=53f1fcf033e3a166d7203e0a1c5e0971f9c6bc16;hp=02d7f4987af22e942868c00c6e2c4a3c20a3ea33;hpb=4343a59bf8db708600c9c6a712aa01bbb437db00;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java index 02d7f498..3f33f40b 100644 --- a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,9 @@ import static org.mockito.Mockito.when; import java.lang.invoke.MethodHandles; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.oransc.ric.e2mgr.client.api.HealthCheckApi; import org.oransc.ric.e2mgr.client.api.NodebApi; @@ -47,8 +49,8 @@ import org.springframework.http.HttpStatus; /** * Creates a mock implementation of the E2 Manager client API. */ -@Profile("test") @Configuration +@Profile("test") public class E2ManagerMockConfiguration { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -57,17 +59,30 @@ public class E2ManagerMockConfiguration { @Value("${mock.config.delay:0}") private int delayMs; + public static final String RAN_NAME_1 = "Connected-RAN"; + public static final String RAN_NAME_2 = "Unknown-RAN"; + private final List nodebIdList; - private final GetNodebResponse nodebResponse; + private final Map nodebResponseMap; + private final NodebIdentityGlobalNbId globalNbId; public E2ManagerMockConfiguration() { logger.info("Configuring mock E2 Manager"); - NodebIdentityGlobalNbId globalNbId = new NodebIdentityGlobalNbId().nbId("mockNbId").plmnId("mockPlmId"); - NodebIdentity nbid = new NodebIdentity().inventoryName("mockInvName").globalNbId(globalNbId); + globalNbId = new NodebIdentityGlobalNbId().nbId("mockNbId").plmnId("mockPlmId"); nodebIdList = new ArrayList<>(); - nodebIdList.add(nbid); - nodebResponse = new GetNodebResponse().connectionStatus("mockConnectionStatus").failureType("mockFailureType") - .ip("127.0.0.1").nodeType("mockNodeType").port(123).ranName("mockRanName"); + nodebResponseMap = new HashMap<>(); + // Complete entry + nodebIdList.add(new NodebIdentity().inventoryName(RAN_NAME_1).globalNbId(globalNbId)); + nodebResponseMap.put(RAN_NAME_1, new GetNodebResponse().connectionStatus("CONNECTED").failureType("") + .ip("127.0.0.1").nodeType("mockNodeType").port(123).ranName(RAN_NAME_1)); + // Partial entry + // [{"nodebIdentity":{"globalNbId":null,"inventoryName":"AAAA123456"}, + // "nodebStatus":{"connectionStatus":"CONNECTING","enb":null,"failureType":null, + // "globalNbId":null,"gnb":null,"ip":"10.2.0.6","nodeType":null,"port":36444, + // "ranName":"AAAA123456","setupFailure":null}}] + nodebIdList.add(new NodebIdentity().inventoryName(RAN_NAME_2)); + nodebResponseMap.put(RAN_NAME_2, + new GetNodebResponse().connectionStatus("CONNECTING").ip("127.0.0.2").port(456).ranName(RAN_NAME_2)); } private ApiClient apiClient() { @@ -76,9 +91,7 @@ public class E2ManagerMockConfiguration { return mockClient; } - @Bean - // Use the same name as regular configuration - public HealthCheckApi e2MgrHealthCheckApi() { + private HealthCheckApi healthCheckApi() { ApiClient apiClient = apiClient(); HealthCheckApi mockApi = mock(HealthCheckApi.class); when(mockApi.getApiClient()).thenReturn(apiClient); @@ -86,17 +99,16 @@ public class E2ManagerMockConfiguration { return mockApi; } - @Bean - // Use the same name as regular configuration - public NodebApi e2MgrNodebApi() { + private NodebApi nodebApi() { ApiClient apiClient = apiClient(); NodebApi mockApi = mock(NodebApi.class); when(mockApi.getApiClient()).thenReturn(apiClient); doAnswer(inv -> { if (delayMs > 0) { - logger.debug("nodebDelete sleeping {}", delayMs); + logger.debug("nodebShutdownPut sleeping {}", delayMs); Thread.sleep(delayMs); } + nodebIdList.clear(); return null; }).when(mockApi).nodebShutdownPut(); doAnswer(inv -> { @@ -111,7 +123,8 @@ public class E2ManagerMockConfiguration { logger.debug("getNb sleeping {}", delayMs); Thread.sleep(delayMs); } - return nodebResponse; + String invName = inv.getArgument(0); + return nodebResponseMap.get(invName); }).when(mockApi).getNb(any(String.class)); doAnswer(inv -> { if (delayMs > 0) { @@ -125,6 +138,11 @@ public class E2ManagerMockConfiguration { logger.debug("endcSetup sleeping {}", delayMs); Thread.sleep(delayMs); } + SetupRequest sr = inv.getArgument(0); + nodebIdList.add(new NodebIdentity().inventoryName(sr.getRanName()).globalNbId(globalNbId)); + nodebResponseMap.put(sr.getRanName(), + new GetNodebResponse().connectionStatus("mockConnectionStatus").failureType("mockFailureType") + .ip(sr.getRanIp()).nodeType("ENDC").port(sr.getRanPort()).ranName(sr.getRanName())); return null; }).when(mockApi).endcSetup(any(SetupRequest.class)); doAnswer(inv -> { @@ -132,9 +150,25 @@ public class E2ManagerMockConfiguration { logger.debug("x2Setup sleeping {}", delayMs); Thread.sleep(delayMs); } + SetupRequest sr = inv.getArgument(0); + nodebIdList.add(new NodebIdentity().inventoryName(sr.getRanName()).globalNbId(globalNbId)); + nodebResponseMap.put(sr.getRanName(), + new GetNodebResponse().connectionStatus("mockConnectionStatus").failureType("mockFailureType") + .ip(sr.getRanIp()).nodeType("X2").port(sr.getRanPort()).ranName(sr.getRanName())); return null; }).when(mockApi).x2Setup(any(SetupRequest.class)); return mockApi; } + @Bean + // Must use the same name as the non-mock configuration + public E2ManagerApiBuilder e2ManagerApiBuilder() { + final E2ManagerApiBuilder mockBuilder = mock(E2ManagerApiBuilder.class); + final HealthCheckApi mockHealthCheckApi = healthCheckApi(); + when(mockBuilder.getHealthCheckApi(any(String.class))).thenReturn(mockHealthCheckApi); + final NodebApi mockNodebApi = nodebApi(); + when(mockBuilder.getNodebApi(any(String.class))).thenReturn(mockNodebApi); + return mockBuilder; + } + }