Revise front-end buildPath support
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / CaasIngressMockConfiguration.java
index 1420086..96ccbb8 100644 (file)
@@ -32,6 +32,7 @@ import java.lang.invoke.MethodHandles;
 import org.oransc.ric.portal.dashboard.k8sapi.SimpleKubernetesClient;
 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;
@@ -48,15 +49,12 @@ public class CaasIngressMockConfiguration {
        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;
 
-       private final String pltPods;
-
-       public CaasIngressMockConfiguration() throws IOException {
-               logger.info("Configuring mock CAAS-Ingres clients");
-               // Files in src/test/resources
-               pltPods = readDataFromPath("caas-ingress-ricplt-pods.json");
+       @Autowired
+       public CaasIngressMockConfiguration(@Value("${mock.config.delay:0}") int delayMs) {
+               logger.debug("ctor: configured with delay {}", delayMs);
+               this.delayMs = delayMs;
        }
 
        private String readDataFromPath(String path) throws IOException {
@@ -77,11 +75,21 @@ public class CaasIngressMockConfiguration {
                return sb.toString();
        }
 
-       private SimpleKubernetesClient simpleKubernetesClient() {
+       private SimpleKubernetesClient simpleKubernetesClient(String instanceKey) throws IOException {
+               // File in src/test/resources
+               String pltPods;
+               if (RICInstanceMockConfiguration.INSTANCE_KEY_1.equals(instanceKey))
+                       pltPods = readDataFromPath("caas-ingress-ricplt-pods-1.json");
+               else
+                       pltPods = readDataFromPath("caas-ingress-ricplt-pods-2.json");
                SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class);
                doAnswer(inv -> {
                        String ns = inv.<String>getArgument(0);
                        logger.debug("listPods for namespace {}", ns);
+                       if (delayMs > 0) {
+                               logger.debug("listPods sleeping {}", delayMs);
+                               Thread.sleep(delayMs);
+                       }
                        if ("ricplt".equals(ns))
                                return pltPods;
                        else
@@ -92,10 +100,12 @@ public class CaasIngressMockConfiguration {
 
        @Bean
        // The bean (method) name must be globally unique
-       public SimpleKubernetesClientBuilder simpleKubernetesClientBuilder() {
+       public SimpleKubernetesClientBuilder simpleKubernetesClientBuilder() throws IOException {
                final SimpleKubernetesClientBuilder mockBuilder = mock(SimpleKubernetesClientBuilder.class);
-               SimpleKubernetesClient client = simpleKubernetesClient();
-               when(mockBuilder.getSimpleKubernetesClient(any(String.class))).thenReturn(client);
+               for (final String key : RICInstanceMockConfiguration.INSTANCE_KEYS) {
+                       SimpleKubernetesClient client = simpleKubernetesClient(key);
+                       when(mockBuilder.getSimpleKubernetesClient(key)).thenReturn(client);
+               }
                return mockBuilder;
        }