diff options
Diffstat (limited to 'profiles/http')
4 files changed, 65 insertions, 5 deletions
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java index 2bf1eb16..53a2d042 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java @@ -242,7 +242,7 @@ public class OnapHttpCommand extends OnapCommand { this.output = this.authClient.run(this.getInput()); this.getResult().setOutput(output); - if (!this.getSuccessStatusCodes().contains(String.valueOf(output.getStatus()))) { + if (!this.getSuccessStatusCodes().contains(output.getStatus())) { throw new OnapCommandExecutionFailed(this.getName(), output.getBody(), output.getStatus()); } diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java index 182cd163..3533e92d 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java @@ -91,12 +91,12 @@ public class OnapHttpConnection { } @Override - public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { + public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { //NOSONAR // No need to implement. } @Override - public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { + public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { //NOSONAR // No need to implement. } } @@ -363,7 +363,7 @@ public class OnapHttpConnection { return entityBuilder.build(); } else { - String fileTag = input.getMultipartEntityName() != "" ? input.getMultipartEntityName() : "file"; + String fileTag = (!input.getMultipartEntityName().isEmpty()) ? input.getMultipartEntityName() : "file"; File file = new File(input.getBody().trim()); HttpEntity multipartEntity = MultipartEntityBuilder .create() diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java index a01516fb..df9c84fc 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java @@ -246,7 +246,8 @@ public class OnapCommandSchemaHttpLoader { if (validate) { validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1)); } - cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1)); + List<String> list = (ArrayList) valMap.get(key1); + cmd.setSuccessStatusCodes(list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList())); break; case OnapCommandHttpConstants.RESULT_MAP: diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java index f0115580..2860388b 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java @@ -156,6 +156,65 @@ public class OnapHttpConnectionTest { con.request(inp); } + @Test(expected = OnapCommandHttpFailure.class) + public void testGetMultipartEntityWithoutMultipartEntityName() throws OnapCommandHttpFailure { + new MockUp<CloseableHttpClient>() { + @Mock + public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) + throws IOException, ClientProtocolException { + + throw new IOException("IO Exception"); + } + }; + new MockUp<HttpInput>() { + + @Mock + public boolean isBinaryData() { + return true; + } + }; + Map<String, String> reqHeaders = new HashMap<>(); + reqHeaders.put("Content-Disposition","form-data"); + reqHeaders.put("name","upload"); + reqHeaders.put("filename","upload.txt"); + reqHeaders.put("Content-Type","application/octet-stream"); + reqHeaders.put("Content-Transfer-Encoding","binary"); + inp.setReqHeaders(reqHeaders); + inp.setMethod("post"); + con = new OnapHttpConnection(); + con.request(inp); + } + + @Test(expected = OnapCommandHttpFailure.class) + public void testGetMultipartEntityWithMultipartEntityName() throws OnapCommandHttpFailure { + new MockUp<CloseableHttpClient>() { + @Mock + public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) + throws IOException, ClientProtocolException { + + throw new IOException("IO Exception"); + } + }; + new MockUp<HttpInput>() { + + @Mock + public boolean isBinaryData() { + return true; + } + }; + Map<String, String> reqHeaders = new HashMap<>(); + reqHeaders.put("Content-Disposition","form-data"); + reqHeaders.put("name","upload"); + reqHeaders.put("filename","upload.txt"); + reqHeaders.put("Content-Type","application/octet-stream"); + reqHeaders.put("Content-Transfer-Encoding","binary"); + inp.setReqHeaders(reqHeaders); + inp.setMethod("post"); + inp.setMultipartEntityName("test"); + con = new OnapHttpConnection(); + con.request(inp); + } + @Test() public void httpUnSecuredCloseExceptionTest() throws OnapCommandHttpFailure { inp.setMethod("other"); |