Require RIC instance key in controller methods
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / AppManagerMockConfiguration.java
index f4cd495..6b0517e 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.
@@ -52,8 +52,8 @@ import org.springframework.http.HttpStatus;
  * Creates an implementation of the xApp manager client that answers requests
  * with mock data.
  */
-@Profile("test")
 @Configuration
+@Profile("test")
 public class AppManagerMockConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -62,24 +62,24 @@ public class AppManagerMockConfiguration {
        @Value("${mock.config.delay:0}")
        private int delayMs;
 
-       private final AllDeployableXapps availXapps;
+       private final AllDeployableXapps deployableApps;
        private final AllDeployedXapps deployedXapps;
        private final AllXappConfig allXappConfigs;
        private final SubscriptionResponse subRes;
 
        public AppManagerMockConfiguration() {
                logger.info("Configuring mock xApp Manager");
-               final String[] appNames = { "AdmissionControl", "Automatic Neighbor Relation", "Dual Connectivity" };
+               final String[] appNames = { "AdmissionControl", "UE Event Collector" };
                final String configJson = " { \"config\" : \"example\" }";
                final String descriptorJson = " { \"descriptor\" : \"example\" }";
                allXappConfigs = new AllXappConfig();
-               availXapps = new AllDeployableXapps();
+               deployableApps = new AllDeployableXapps();
                deployedXapps = new AllDeployedXapps();
                for (String n : appNames) {
                        ConfigMetadata metadata = new ConfigMetadata().configName("config-" + n).name(n).namespace("namespace");
                        XAppConfig config = new XAppConfig().config(configJson).descriptor(descriptorJson).metadata(metadata);
                        allXappConfigs.add(config);
-                       availXapps.add(n);
+                       deployableApps.add(n);
                        Xapp xapp = new Xapp().name(n).version("version").status(StatusEnum.UNKNOWN);
                        xapp.addInstancesItem(new XappInstance().name("abcd-1234").ip("127.0.0.1").port(200)
                                        .status(XappInstance.StatusEnum.RUNNING));
@@ -88,9 +88,7 @@ public class AppManagerMockConfiguration {
                subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL).id("subid").version(1);
        }
 
-       @Bean
-       // Use the same name as regular configuration
-       public HealthApi xappMgrHealthApi() {
+       private HealthApi healthApi() {
                ApiClient mockClient = mock(ApiClient.class);
                when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
                HealthApi mockApi = mock(HealthApi.class);
@@ -100,9 +98,7 @@ public class AppManagerMockConfiguration {
                return mockApi;
        }
 
-       @Bean
-       // Use the same name as regular configuration
-       public XappApi xappMgrXappApi() {
+       private XappApi xappApi() {
                ApiClient mockClient = mock(ApiClient.class);
                when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
                XappApi mockApi = mock(XappApi.class);
@@ -144,11 +140,11 @@ public class AppManagerMockConfiguration {
                }).when(mockApi).deployXapp(any(XAppInfo.class));
                doAnswer(inv -> {
                        if (delayMs > 0) {
-                               logger.debug("listAllXapps sleeping {}", delayMs);
+                               logger.debug("listAllDeployableXapps sleeping {}", delayMs);
                                Thread.sleep(delayMs);
                        }
-                       return availXapps;
-               }).when(mockApi).listAllXapps();
+                       return deployableApps;
+               }).when(mockApi).listAllDeployableXapps();
                doAnswer(inv -> {
                        if (delayMs > 0) {
                                logger.debug("getAllXapps sleeping {}", delayMs);
@@ -187,4 +183,15 @@ public class AppManagerMockConfiguration {
                return mockApi;
        }
 
+       @Bean
+       // Must use the same name as the non-mock configuration
+       public AppManagerApiBuilder appManagerApiBuilder() {
+               final AppManagerApiBuilder mockBuilder = mock(AppManagerApiBuilder.class);
+               final HealthApi mockHealthApi = healthApi();
+               when(mockBuilder.getHealthApi(any(String.class))).thenReturn(mockHealthApi);
+               final XappApi mockXappApi = xappApi();
+               when(mockBuilder.getXappApi(any(String.class))).thenReturn(mockXappApi);
+               return mockBuilder;
+       }
+
 }