diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-29 10:50:04 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-29 16:13:12 +0000 |
commit | 60457e41054465e9fa10c8e6bfdbfa62a45d1f0a (patch) | |
tree | 009055c484b0f7c69cf2a3ee25f2779c7541aa47 /src/test | |
parent | 5f1b6e4eb654639de6aaae9b7d862eb01b991f55 (diff) |
Additional null checks and comments
Add defensive coding to check for possible null pointer values, thus
preventing certain potential runtime exceptions.
Fix some minor spelling inconsistencies.
Refactor some method signatures and update the Javadoc.
Reformat Resource toString() method to avoid lengthy String
concatenation and duplicated separators.
Change-Id: I4b01eb844700e00d0c909bcc5fa2dbc91d5149e4
Issue-ID: AAI-2281
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test')
3 files changed, 11 insertions, 8 deletions
diff --git a/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java b/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java index 5bb7763..20c3434 100644 --- a/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java +++ b/src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,7 +91,7 @@ public class YamlExtractorTest { @Test public void testInvalidContentSupplied() { invalidArgumentsTest("This is a piece of nonsense and not a zip file".getBytes(), FOO, FOO, - "An error occurred trying to create a ZipFile. Is the content being converted really a csar file?"); + "An error occurred trying to create a ZipFile. Is the content being converted really a CSAR file?"); } @Test @@ -102,7 +102,7 @@ public class YamlExtractorTest { } catch (Exception e) { assertTrue("An instance of InvalidArchiveException should have been thrown.", e instanceof InvalidArchiveException); - assertEquals("Incorrect message was returned", "No valid YAML files were found in the csar file.", + assertEquals("Incorrect message was returned", "No valid YAML files were found in the CSAR file.", e.getMessage()); } } diff --git a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java index 0673d04..55311a6 100644 --- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java +++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java @@ -152,8 +152,7 @@ public class TestGenerateArtifactsServiceImpl { * if the resource cannot be loaded */ private Response processJsonRequest(CsarTest csar) throws IOException, URISyntaxException { - String jsonString = csar.getJsonRequest(); - return invokeService(jsonString); + return invokeService(csar.getJsonRequest()); } /** diff --git a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java index 066911e..a98b7c2 100644 --- a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java +++ b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java @@ -65,7 +65,7 @@ public class ArtifactTestUtils { /** * Load the Widget type mappings (resource). - * + * * @throws IOException * if the configuration file is not loaded */ @@ -127,7 +127,11 @@ public class ArtifactTestUtils { } public String loadResourceAsString(String resourceName) throws IOException { + try { return IOUtils.toString(getResource(resourceName), Charset.defaultCharset()); + } catch (NullPointerException e) { + throw new IllegalArgumentException("No such resource " + resourceName); + } } public String getRequestJson(String resource) throws IOException { @@ -144,7 +148,7 @@ public class ArtifactTestUtils { /** * Create Properties from the content of the named resource (e.g. a file on the classpath). - * + * * @param resourceName * the resource name * @return Properties loaded from the named resource |