1 package org.onap.aai.sparky.util;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
7 import java.nio.file.Files;
9 import com.fasterxml.jackson.core.JsonParseException;
10 import com.fasterxml.jackson.databind.JsonMappingException;
12 public class TestResourceLoader {
14 public static String getTestResourceDataJson(String resourcePath)
15 throws JsonParseException, JsonMappingException, IOException {
17 // will look for resource using "src/test/resources" as the base folder
18 URL url = TestResourceLoader.class.getResource(resourcePath);
19 File file = new File(url.getFile());
21 byte[] payload = Files.readAllBytes(file.toPath());
23 if (payload.length == 0) {
24 throw new FileNotFoundException("Could not load '" + resourcePath + "' test data");
27 return new String(payload);