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;
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 {
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
@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;
}