Revise front-end buildPath support
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / E2ManagerMockConfiguration.java
index 3f33f40..16d2486 100644 (file)
@@ -40,6 +40,7 @@ import org.oransc.ric.e2mgr.client.model.ResetRequest;
 import org.oransc.ric.e2mgr.client.model.SetupRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -55,34 +56,16 @@ public class E2ManagerMockConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-       // Simulate remote method delay for UI testing
-       @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<NodebIdentity> nodebIdList;
-       private final Map<String, GetNodebResponse> nodebResponseMap;
-       private final NodebIdentityGlobalNbId globalNbId;
+       // Simulate remote method delay for UI testing
+       private int delayMs;
 
-       public E2ManagerMockConfiguration() {
-               logger.info("Configuring mock E2 Manager");
-               globalNbId = new NodebIdentityGlobalNbId().nbId("mockNbId").plmnId("mockPlmId");
-               nodebIdList = new ArrayList<>();
-               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));
+       @Autowired
+       public E2ManagerMockConfiguration(@Value("${mock.config.delay:0}") int delayMs) {
+               logger.debug("ctor: configured with delay {}", delayMs);
+               this.delayMs = delayMs;
        }
 
        private ApiClient apiClient() {
@@ -99,7 +82,32 @@ public class E2ManagerMockConfiguration {
                return mockApi;
        }
 
-       private NodebApi nodebApi() {
+       /**
+        * Builds a mock NodebApi object.
+        * 
+        * @param instanceKey
+        *                        RIC instance
+        * @return Object that returns instance-specific results
+        */
+       private NodebApi nodebApi(String instanceKey) {
+
+               final NodebIdentityGlobalNbId globalNbId = new NodebIdentityGlobalNbId().nbId("mockNbId-" + instanceKey)
+                               .plmnId("mockPlmId");
+               final List<NodebIdentity> nodebIdList = new ArrayList<>();
+               final Map<String, GetNodebResponse> 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));
+
                ApiClient apiClient = apiClient();
                NodebApi mockApi = mock(NodebApi.class);
                when(mockApi.getApiClient()).thenReturn(apiClient);
@@ -166,8 +174,10 @@ public class E2ManagerMockConfiguration {
                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);
+               for (final String key : RICInstanceMockConfiguration.INSTANCE_KEYS) {
+                       final NodebApi mockNodebApi = nodebApi(key);
+                       when(mockBuilder.getNodebApi(key)).thenReturn(mockNodebApi);
+               }
                return mockBuilder;
        }