Pass thru error details from remote APIs
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / config / E2ManagerMockConfiguration.java
index 3df6dc7..334915c 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ========================LICENSE_START=================================
- * ORAN-OSC
+ * O-RAN-SC
  * %%
  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
  * %%
@@ -26,10 +26,10 @@ import static org.mockito.Mockito.when;
 
 import java.lang.invoke.MethodHandles;
 
-import org.oransc.ric.e2mgr.client.api.EndcSetupRequestApi;
 import org.oransc.ric.e2mgr.client.api.HealthCheckApi;
-import org.oransc.ric.e2mgr.client.api.X2SetupRequestApi;
+import org.oransc.ric.e2mgr.client.api.NodebApi;
 import org.oransc.ric.e2mgr.client.invoker.ApiClient;
+import org.oransc.ric.e2mgr.client.model.GetNodebResponse;
 import org.oransc.ric.e2mgr.client.model.SetupRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,8 +39,8 @@ import org.springframework.context.annotation.Profile;
 import org.springframework.http.HttpStatus;
 
 /**
- * Creates an implementation of the E2 manager client that answers requests with
- * mock data.
+ * Creates a mock implementation of the E2 manager client API. This version
+ * answers only status codes, no data, so the mock implementations are trivial.
  */
 @Profile("mock")
 @Configuration
@@ -48,8 +48,11 @@ public class E2ManagerMockConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+       private final GetNodebResponse nodebResponse;
+
        public E2ManagerMockConfiguration() {
                logger.info("Configuring mock E2 Manager");
+               nodebResponse = new GetNodebResponse().ip("1.2.3.4").port(123).ranName("myRan");
        }
 
        private ApiClient apiClient() {
@@ -59,32 +62,38 @@ public class E2ManagerMockConfiguration {
        }
 
        @Bean
-       public EndcSetupRequestApi endcSetupRequestApi() {
-               ApiClient apiClient = apiClient();
-               EndcSetupRequestApi mockApi = mock(EndcSetupRequestApi.class);
-               when(mockApi.getApiClient()).thenReturn(apiClient);
-               return mockApi;
-       }
-
-       @Bean
-       public HealthCheckApi healthCheckApi() {
+       // Use the same name as regular configuration
+       public HealthCheckApi e2MgrHealthCheckApi() {
                ApiClient apiClient = apiClient();
                HealthCheckApi mockApi = mock(HealthCheckApi.class);
                when(mockApi.getApiClient()).thenReturn(apiClient);
+
                doAnswer(i -> {
                        return null;
-               }).when(mockApi).healthCheck();
+               }).when(mockApi).healthGet();
+
                return mockApi;
        }
 
        @Bean
-       public X2SetupRequestApi x2SetupRequestApi() {
+       // Use the same name as regular configuration
+       public NodebApi e2MgrNodebApi() {
                ApiClient apiClient = apiClient();
-               X2SetupRequestApi mockApi = mock(X2SetupRequestApi.class);
+               NodebApi mockApi = mock(NodebApi.class);
                when(mockApi.getApiClient()).thenReturn(apiClient);
+
+               doAnswer(i -> {
+                       return nodebResponse;
+               }).when(mockApi).getNb(any(String.class));
+
                doAnswer(i -> {
                        return null;
-               }).when(mockApi).setup(any(SetupRequest.class));
+               }).when(mockApi).endcSetup(any(SetupRequest.class));
+
+               doAnswer(i -> {
+                       return null;
+               }).when(mockApi).x2Setup(any(SetupRequest.class));
+
                return mockApi;
        }