1 package org.onap.crud.test.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;
12 * Helper methods for locating and reading test data files.
15 public class TestUtil {
17 public static Path getPath(String resourceFilename) throws URISyntaxException {
18 URL resource = ClassLoader.getSystemResource(resourceFilename);
19 if (resource != null) {
20 return Paths.get(resource.toURI());
23 // If the resource is not found relative to the classpath, try to get it from the file system directly.
24 File file = new File(resourceFilename);
26 throw new RuntimeException("Resource does not exist: " + resourceFilename);
31 public static String getContentUtf8(Path filePath) throws IOException {
32 return new String(Files.readAllBytes(filePath));
35 public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException {
36 return getContentUtf8(getPath(resourceFilename));