X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-backend%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fconfig%2FCaasIngressMockConfiguration.java;h=b10dcc8300cbb150b68129a4fe47d56c3390868b;hb=refs%2Fchanges%2F58%2F2258%2F2;hp=96ccbb8e0b386a603c026c4afcec33c1f82d5899;hpb=c1c667f0a1aa289655b5309aff4c1c748733f4d2;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/CaasIngressMockConfiguration.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/CaasIngressMockConfiguration.java index 96ccbb8e..b10dcc83 100644 --- a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/CaasIngressMockConfiguration.java +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/CaasIngressMockConfiguration.java @@ -25,10 +25,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; +import org.oransc.ric.portal.dashboard.TestUtils; import org.oransc.ric.portal.dashboard.k8sapi.SimpleKubernetesClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,31 +56,12 @@ public class CaasIngressMockConfiguration { this.delayMs = delayMs; } - private String readDataFromPath(String path) throws IOException { - InputStream is = MethodHandles.lookup().lookupClass().getClassLoader().getResourceAsStream(path); - if (is == null) { - String msg = "Failed to find resource on classpath: " + path; - logger.error(msg); - throw new RuntimeException(msg); - } - InputStreamReader reader = new InputStreamReader(is, "UTF-8"); - StringBuilder sb = new StringBuilder(); - char[] buf = new char[8192]; - int i; - while ((i = reader.read(buf)) > 0) - sb.append(buf, 0, i); - reader.close(); - is.close(); - return sb.toString(); - } - 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"); + String podFile = RICInstanceMockConfiguration.INSTANCE_KEY_1.equals(instanceKey) + ? "caas-ingress-ricplt-pods-1.json" + : "caas-ingress-ricplt-pods-2.json"; + String pltPods = TestUtils.readDataFromPath(podFile); SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class); doAnswer(inv -> { String ns = inv.getArgument(0);