Update to consume and publish events in new format
[aai/champ.git] / champ-service / src / test / java / org / onap / champ / util / TestUtil.java
1 package org.onap.champ.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 public class TestUtil {
12
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());
17                 }
18
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);
21                 if (!file.exists()) {
22                         throw new RuntimeException("Resource does not exist: " + resourceFilename);
23                 }
24                 return file.toPath();
25         }
26
27         public static String getContentUtf8(Path filePath) throws IOException {
28                 return new String(Files.readAllBytes(filePath));
29         }
30
31         public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException {
32                 return getContentUtf8(getPath(resourceFilename));
33         }
34 }