Require RIC instance key in controller methods
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / CaasIngressMockConfiguration.java
index bd94c2e..1420086 100644 (file)
@@ -22,6 +22,7 @@ package org.oransc.ric.portal.dashboard.config;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -50,13 +51,11 @@ public class CaasIngressMockConfiguration {
        @Value("${mock.config.delay:0}")
        private int delayMs;
 
-       private final String auxPods;
        private final String pltPods;
 
        public CaasIngressMockConfiguration() throws IOException {
                logger.info("Configuring mock CAAS-Ingres clients");
                // Files in src/test/resources
-               auxPods = readDataFromPath("caas-ingress-ricaux-pods.json");
                pltPods = readDataFromPath("caas-ingress-ricplt-pods.json");
        }
 
@@ -78,20 +77,7 @@ public class CaasIngressMockConfiguration {
                return sb.toString();
        }
 
-       @Bean
-       // Use the same name as regular configuration
-       public SimpleKubernetesClient ciAuxApi() throws IOException {
-               SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class);
-               doAnswer(inv -> {
-                       logger.debug("listPods for aux");
-                       return auxPods;
-               }).when(mockClient).listPods("ricaux");
-               return mockClient;
-       }
-
-       @Bean
-       // Use the same name as regular configuration
-       public SimpleKubernetesClient ciPltApi() throws IOException {
+       private SimpleKubernetesClient simpleKubernetesClient() {
                SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class);
                doAnswer(inv -> {
                        String ns = inv.<String>getArgument(0);
@@ -99,9 +85,18 @@ public class CaasIngressMockConfiguration {
                        if ("ricplt".equals(ns))
                                return pltPods;
                        else
-                               throw new Exception("Fake server failure");
+                               throw new IllegalArgumentException("Fake server failure");
                }).when(mockClient).listPods(any(String.class));
                return mockClient;
        }
 
+       @Bean
+       // The bean (method) name must be globally unique
+       public SimpleKubernetesClientBuilder simpleKubernetesClientBuilder() {
+               final SimpleKubernetesClientBuilder mockBuilder = mock(SimpleKubernetesClientBuilder.class);
+               SimpleKubernetesClient client = simpleKubernetesClient();
+               when(mockBuilder.getSimpleKubernetesClient(any(String.class))).thenReturn(client);
+               return mockBuilder;
+       }
+
 }