diff options
author | Michal Kabaj <michal.kabaj@nokia.com> | 2018-05-04 15:30:42 +0200 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-06-01 22:06:26 +0000 |
commit | f4f29f37b74d707c4a45523dce6aee3a7bf90ce2 (patch) | |
tree | 4e72387fb44f14a362de92039a81facda24d907e /appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test | |
parent | 6f44e217b73e2eca6abd00ffabb67e1aa4fca237 (diff) |
Unit test for ChefApiClientImplTest
-Add new JUnits to ChefApiClientImplTest to check if body is properly
set for put/post http requests.
Change-Id: Ie9ea2de7a1c68fa12815586a4f85646b06ce69a9
Issue-ID: APPC-879
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test')
-rw-r--r-- | appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java index f1e215aa4..d3f117747 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java @@ -35,6 +35,7 @@ import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.StringEntity; import org.junit.Before; @@ -197,17 +198,28 @@ public class ChefApiClientImplTest { public boolean matches(Object argument) { HttpRequestBase httpRequestBase = (HttpRequestBase) argument; - boolean headersMatch = checkIfHeadersMatch(httpRequestBase); try { return methodName.equals(httpRequestBase.getMethod()) - && new URI(END_POINT + "/organizations/" + ORGANIZATIONS_PATH + REQUEST_PATH).equals(httpRequestBase.getURI()) - && headersMatch; + && new URI(END_POINT + "/organizations/" + ORGANIZATIONS_PATH + REQUEST_PATH) + .equals(httpRequestBase.getURI()) + && checkIfBodyMatches(httpRequestBase) + && checkIfHeadersMatch(httpRequestBase); } catch (URISyntaxException e) { e.printStackTrace(); return false; } } + public boolean checkIfBodyMatches(HttpRequestBase httpRequestBase) { + if (httpRequestBase instanceof HttpEntityEnclosingRequestBase) { + HttpEntityEnclosingRequestBase requestBaseWithBody = (HttpEntityEnclosingRequestBase) httpRequestBase; + StringEntity stringEntity = new StringEntity(BODY, "UTF-8"); + stringEntity.setContentType("application/json"); + return stringEntity.toString().equals(requestBaseWithBody.getEntity().toString()); + } + return true; + } + private boolean checkIfHeadersMatch(HttpRequestBase httpRequestBase) { Header[] generatedHeaders = httpRequestBase.getAllHeaders(); return generatedHeaders.length > 0 |