aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java2
-rw-r--r--profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java59
2 files changed, 60 insertions, 1 deletions
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..eae0113a 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
@@ -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/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");