diff options
author | 2017-09-07 10:52:29 +0300 | |
---|---|---|
committer | 2017-09-07 13:53:33 +0000 | |
commit | b7375b2488df93ba9df57ad13ec628bbff663819 (patch) | |
tree | e8d372535ab98aa76814e16d301ac32efbeb0c75 /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json | |
parent | 8bd8cee7d620406036e197f540439b1e226506d5 (diff) |
Fixed a few static analysis violations
Fixed mostly not closing resources (InputStream, ResultSet) and catching
Throwable instead of Exception in some modules.
Issue-ID: SDC-291
Change-Id: I34e331cc3b45c4bb3a71c301f50e1706a7b623fd
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json')
2 files changed, 28 insertions, 16 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java index ba34d07034..9b21f632cc 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java @@ -28,14 +28,17 @@ import org.testng.annotations.Test; public class JsonSchemaDataGeneratorTest { - public static final String SCHEMA_WITHOUT_DEFAULTS = new String( - FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json"))); - public static final String SCHEMA_WITH_REFS_AND_DEFAULTS = new String(FileUtils.toByteArray( - FileUtils.getFileInputStream("jsonUtil/json_schema/schemaWithRefsAndDefaults.json"))); - public static final String SCHEMA_WITH_INVALID_DEFAULT = new String(FileUtils.toByteArray( - FileUtils.getFileInputStream("jsonUtil/json_schema/schemaWithInvalidDefault.json"))); - public static final String SCHEMA_NIC = new String( - FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/nicSchema.json"))); + public static final String SCHEMA_WITHOUT_DEFAULTS = + readFromFile("jsonUtil/json_schema/aSchema.json"); + + public static final String SCHEMA_WITH_REFS_AND_DEFAULTS = + readFromFile("jsonUtil/json_schema/schemaWithRefsAndDefaults.json"); + + public static final String SCHEMA_WITH_INVALID_DEFAULT = + readFromFile("jsonUtil/json_schema/schemaWithInvalidDefault.json"); + + public static final String SCHEMA_NIC = + readFromFile("jsonUtil/json_schema/nicSchema.json"); @Test public void testSchemaWithoutDefaults() { @@ -67,4 +70,8 @@ public class JsonSchemaDataGeneratorTest { JSONObject dataJson = new JSONObject(data); Assert.assertTrue(expectedData.similar(dataJson)); } + + private static String readFromFile(String filename) { + return FileUtils.readViaInputStream(filename, stream -> new String(FileUtils.toByteArray(stream))); + } } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java index 6b8805797a..d89019baec 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java @@ -31,10 +31,14 @@ public class JsonUtilTest { @Test public void testValidJsonValidate() throws Exception { - String json = - new String(FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json/a.json"))); - String jsonSchema = new String( - FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json"))); + + + + String json = FileUtils.readViaInputStream("jsonUtil/json/a.json", + stream -> new String(FileUtils.toByteArray(stream))); + + String jsonSchema = FileUtils.readViaInputStream("jsonUtil/json_schema/aSchema.json", + stream -> new String(FileUtils.toByteArray(stream))); List<String> validationErrors = JsonUtil.validate(json, jsonSchema); Assert.assertNull(validationErrors); @@ -42,10 +46,11 @@ public class JsonUtilTest { @Test public void testInValidJsonValidate() throws Exception { - String json = new String( - FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json/a_invalid.json"))); - String jsonSchema = new String( - FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json"))); + + String json = FileUtils.readViaInputStream("jsonUtil/json/a_invalid.json", + stream -> new String(FileUtils.toByteArray(stream))); + String jsonSchema = FileUtils.readViaInputStream("jsonUtil/json_schema/aSchema.json", + stream -> new String(FileUtils.toByteArray(stream))); List<String> validationErrors = JsonUtil.validate(json, jsonSchema); Assert.assertNotNull(validationErrors); |