diff options
author | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2020-12-15 19:16:15 +0100 |
---|---|---|
committer | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2020-12-17 08:11:42 +0000 |
commit | 5337a5f3f75de945b612068fd441bfa416084440 (patch) | |
tree | db83f8a918823fdc3732224d96243d41cb44ffed /cps-service/src/test/java/org/onap | |
parent | 7b72ea0713dbfededd1a773e9d9b90ea0b08e045 (diff) |
Decouple YangUtils test
from YangTextSchemaSourceSet test responsabilities.
- Remove deprecated YangUtils method for handle files
Issue-ID: CPS-21
Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech>
Change-Id: I971f818a55efd9659481bb13476dd67106cecab7
Diffstat (limited to 'cps-service/src/test/java/org/onap')
-rw-r--r-- | cps-service/src/test/java/org/onap/cps/TestUtils.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/cps-service/src/test/java/org/onap/cps/TestUtils.java b/cps-service/src/test/java/org/onap/cps/TestUtils.java index 3a2a4e3a55..4ec4e4a004 100644 --- a/cps-service/src/test/java/org/onap/cps/TestUtils.java +++ b/cps-service/src/test/java/org/onap/cps/TestUtils.java @@ -19,14 +19,28 @@ package org.onap.cps; +import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.Map; /** * Common convenience methods for testing. */ public class TestUtils { + + /** + * Convert a file in the test resource folder to file. + * + * @param filename to name of the file in test/resources + * @return the file + * @throws IOException when there is an IO issue + */ + public static File readFile(final String filename) { + return new File(ClassLoader.getSystemClassLoader().getResource(filename).getFile()); + } + /** * Convert a file in the test resource folder to a string. * @@ -35,7 +49,24 @@ public class TestUtils { * @throws IOException when there is an IO issue */ public static String getResourceFileContent(final String filename) throws IOException { - final File file = new File(ClassLoader.getSystemClassLoader().getResource(filename).getFile()); + final File file = readFile(filename); return new String(Files.readAllBytes(file.toPath())); } + + /** + * Reads yang resources into map. + * + * @param resources list of file paths + * @return yang resource map where key is filename and value is file content + * @throws IOException when there an I/O issue + */ + public static Map<String, String> getYangResourcesAsMap(final String... resources) throws IOException { + final ImmutableMap.Builder<String, String> yangResourceNameToContentBuilder = new ImmutableMap.Builder<>(); + for (final String resourcePath : resources) { + final File file = readFile(resourcePath); + final String content = new String(Files.readAllBytes(file.toPath())); + yangResourceNameToContentBuilder.put(file.getName(), content); + } + return yangResourceNameToContentBuilder.build(); + } } |