summaryrefslogtreecommitdiffstats
path: root/profiles/http
diff options
context:
space:
mode:
authorpriyanka.akhade <priyanka.akhade@huawei.com>2020-05-05 08:47:19 +0000
committerpriyanka.akhade <priyanka.akhade@huawei.com>2020-05-06 09:26:17 +0000
commit19684879f5742847e2e903d6c039de7e13fab6e3 (patch)
treec8a7a459dc4acfc5a9e3194756b8b3b572722825 /profiles/http
parent1db7e72d979afa03bca38d3008f55246f8d6a6c1 (diff)
sonar bug fix- Use the "equals" method if value comparison was intended
Signed-off-by: priyanka.akhade <priyanka.akhade@huawei.com> Issue-ID: CLI-270 Change-Id: I0c379ae2a6798303daf676c0e741aace48e673ca
Diffstat (limited to 'profiles/http')
-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");