Convert Sparky to Spring-Boot
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / util / TestResourceLoader.java
1 package org.onap.aai.sparky.util;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.net.URL;
7 import java.nio.file.Files;
8
9 import com.fasterxml.jackson.core.JsonParseException;
10 import com.fasterxml.jackson.databind.JsonMappingException;
11
12 public class TestResourceLoader {
13
14         public static String getTestResourceDataJson(String resourcePath)
15                         throws JsonParseException, JsonMappingException, IOException {
16
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());
20
21                 byte[] payload = Files.readAllBytes(file.toPath());
22
23                 if (payload.length == 0) {
24                         throw new FileNotFoundException("Could not load '" + resourcePath + "' test data");
25                 }
26
27                 return new String(payload);
28
29         }
30
31 }