*/
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;
* Creates mock implementations of Kubernetes clients that answer requests with
* sample data read from the filesystem.
*/
-@Profile("test")
@Configuration
+@Profile("test")
public class CaasIngressMockConfiguration {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@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");
}
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 {
SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class);
doAnswer(inv -> {
- logger.debug("listPods for plt");
- return pltPods;
- }).when(mockClient).listPods("ricplt");
+ String ns = inv.<String>getArgument(0);
+ logger.debug("listPods for namespace {}", ns);
+ if ("ricplt".equals(ns))
+ return pltPods;
+ else
+ throw new Exception("Fake server failure");
+ }).when(mockClient).listPods(any(String.class));
return mockClient;
}