Require RIC instance key in controller methods
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / E2ManagerMockConfiguration.java
index 02b2ba4..3f33f40 100644 (file)
@@ -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.
@@ -49,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());
@@ -59,7 +59,8 @@ public class E2ManagerMockConfiguration {
        @Value("${mock.config.delay:0}")
        private int delayMs;
 
-       public static final String MOCK_RAN_NAME = "Mock RAN";
+       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;
@@ -70,10 +71,18 @@ public class E2ManagerMockConfiguration {
                globalNbId = new NodebIdentityGlobalNbId().nbId("mockNbId").plmnId("mockPlmId");
                nodebIdList = new ArrayList<>();
                nodebResponseMap = new HashMap<>();
-               nodebIdList.add(new NodebIdentity().inventoryName(MOCK_RAN_NAME).globalNbId(globalNbId));
-               nodebResponseMap.put(MOCK_RAN_NAME,
-                               new GetNodebResponse().connectionStatus("mockConnectionStatus").failureType("mockFailureType")
-                                               .ip("127.0.0.1").nodeType("mockNodeType").port(123).ranName(MOCK_RAN_NAME));
+               // 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() {
@@ -82,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);
@@ -92,9 +99,7 @@ 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);
@@ -155,4 +160,15 @@ public class E2ManagerMockConfiguration {
                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;
+       }
+
 }