1 package org.onap.champ.util;
4 import java.io.IOException;
5 import java.net.URISyntaxException;
7 import java.nio.file.Files;
8 import java.nio.file.Path;
9 import java.nio.file.Paths;
11 public class TestUtil {
13 public static Path getPath(String resourceFilename) throws URISyntaxException {
14 URL resource = ClassLoader.getSystemResource(resourceFilename);
15 if (resource != null) {
16 return Paths.get(resource.toURI());
19 // If the resource is not found relative to the classpath, try to get it from the file system directly.
20 File file = new File(resourceFilename);
22 throw new RuntimeException("Resource does not exist: " + resourceFilename);
27 public static String getContentUtf8(Path filePath) throws IOException {
28 return new String(Files.readAllBytes(filePath));
31 public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException {
32 return getContentUtf8(getPath(resourceFilename));