Add configurable delay to mock endpoints
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / config / AppManagerMockConfiguration.java
index 2dfb814..ef1e9d5 100644 (file)
@@ -60,6 +60,9 @@ public class AppManagerMockConfiguration {
        private final AllDeployableXapps availXapps;
        private final AllDeployedXapps deployedXapps;
        private final AllXappConfig allXappConfigs;
+       private final SubscriptionResponse subRes;
+       // Simulate remote method delay for UI testing
+       private final int delayMs = 500;
 
        public AppManagerMockConfiguration() {
                logger.info("Configuring mock xApp Manager");
@@ -75,10 +78,11 @@ public class AppManagerMockConfiguration {
                        allXappConfigs.add(config);
                        availXapps.add(n);
                        Xapp xapp = new Xapp().name(n).version("version").status(StatusEnum.UNKNOWN);
-                       xapp.addInstancesItem(new XappInstance().name("abcd-1234").ip("1.2.3.4").port(200)
+                       xapp.addInstancesItem(new XappInstance().name("abcd-1234").ip("127.0.0.1").port(200)
                                        .status(XappInstance.StatusEnum.RUNNING));
                        deployedXapps.add(xapp);
                }
+               subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL).id("subid").version(1);
        }
 
        @Bean
@@ -88,12 +92,8 @@ public class AppManagerMockConfiguration {
                when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
                HealthApi mockApi = mock(HealthApi.class);
                when(mockApi.getApiClient()).thenReturn(mockClient);
-               doAnswer(i -> {
-                       return null;
-               }).when(mockApi).getHealthAlive();
-               doAnswer(i -> {
-                       return null;
-               }).when(mockApi).getHealthReady();
+               doAnswer(i -> null).when(mockApi).getHealthAlive();
+               doAnswer(i -> null).when(mockApi).getHealthReady();
                return mockApi;
        }
 
@@ -102,40 +102,63 @@ public class AppManagerMockConfiguration {
        public XappApi xappMgrXappApi() {
                ApiClient mockClient = mock(ApiClient.class);
                when(mockClient.getStatusCode()).thenReturn(HttpStatus.OK);
-
                XappApi mockApi = mock(XappApi.class);
                when(mockApi.getApiClient()).thenReturn(mockClient);
-
-               when(mockApi.getAllXappConfig()).thenReturn(allXappConfigs);
-
-               when(mockApi.createXappConfig(any(XAppConfig.class))).thenReturn(allXappConfigs.get(0));
-
-               when(mockApi.modifyXappConfig(any(XAppConfig.class))).thenReturn(allXappConfigs.get(0));
-
-               doAnswer(i -> {
+               doAnswer(inv -> {
+                       logger.debug("getAllXappConfig sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
+                       return allXappConfigs;
+               }).when(mockApi).getAllXappConfig();
+               doAnswer(inv -> {
+                       logger.debug("createXappConfig sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
+                       return allXappConfigs.get(0);
+               }).when(mockApi).createXappConfig(any(XAppConfig.class));
+               doAnswer(inv -> {
+                       logger.debug("modifyXappConfig sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
+                       return allXappConfigs.get(0);
+               }).when(mockApi).modifyXappConfig(any(XAppConfig.class));
+               doAnswer(inv -> {
+                       logger.debug("deleteXappConfig sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
                        return null;
                }).when(mockApi).deleteXappConfig(any(ConfigMetadata.class));
-
-               when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(deployedXapps.get(0));
-
-               when(mockApi.listAllXapps()).thenReturn(availXapps);
-
-               when(mockApi.getAllXapps()).thenReturn(deployedXapps);
-
-               when(mockApi.getXappByName(any(String.class))).thenReturn(deployedXapps.get(0));
-
-               doAnswer(i -> {
+               doAnswer(inv -> {
+                       logger.debug("deployXapp of {} sleeping {}", inv.getArgument(0), delayMs);
+                       Thread.sleep(delayMs);
+                       return deployedXapps.get(0);
+               }).when(mockApi).deployXapp(any(XAppInfo.class));
+               doAnswer(inv -> {
+                       logger.debug("listAllXapps sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
+                       return availXapps;
+               }).when(mockApi).listAllXapps();
+               doAnswer(inv -> {
+                       logger.debug("getAllXapps sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
+                       return deployedXapps;
+               }).when(mockApi).getAllXapps();
+               doAnswer(inv -> {
+                       logger.debug("getXappByName of {} sleeping {}", inv.getArgument(0), delayMs);
+                       Thread.sleep(delayMs);
+                       return deployedXapps.get(0);
+               }).when(mockApi).getXappByName(any(String.class));
+               doAnswer(inv -> {
+                       logger.debug("undeployXapp of {} sleeping {}", inv.getArgument(0), delayMs);
+                       Thread.sleep(delayMs);
                        return null;
                }).when(mockApi).undeployXapp(any(String.class));
-
-               SubscriptionResponse subRes = new SubscriptionResponse().eventType(SubscriptionResponse.EventTypeEnum.ALL)
-                               .id("subid").version(1);
-               when(mockApi.addSubscription(any(SubscriptionRequest.class))).thenReturn(subRes);
-
-               doAnswer(i -> {
+               doAnswer(inv -> {
+                       logger.debug("addSubscription sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
+                       return subRes;
+               }).when(mockApi).addSubscription(any(SubscriptionRequest.class));
+               doAnswer(inv -> {
+                       logger.debug("deleteSubscription sleeping {}", delayMs);
+                       Thread.sleep(delayMs);
                        return null;
                }).when(mockApi).deleteSubscription(any(String.class));
-
                return mockApi;
        }