From f4f29f37b74d707c4a45523dce6aee3a7bf90ce2 Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Fri, 4 May 2018 15:30:42 +0200 Subject: 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 --- .../chef/chefclient/impl/ChefApiClientImplTest.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'appc-adapters') 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 -- cgit 1.2.3-korg