Update published event to include header and body
[aai/gizmo.git] / src / test / java / org / onap / crud / test / util / TestUtil.java
1 package org.onap.crud.test.util;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.net.URISyntaxException;
6 import java.net.URL;
7 import java.nio.file.Files;
8 import java.nio.file.Path;
9 import java.nio.file.Paths;
10
11 /**
12  * Helper methods for locating and reading test data files.
13  *
14  */
15 public class TestUtil {
16
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());
21         }
22
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);
25         if (!file.exists()) {
26             throw new RuntimeException("Resource does not exist: " + resourceFilename);
27         }
28         return file.toPath();
29     }
30
31     public static String getContentUtf8(Path filePath) throws IOException {
32         return new String(Files.readAllBytes(filePath));
33     }
34
35     public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException {
36         return getContentUtf8(getPath(resourceFilename));
37     }
38 }