Unit test for ChefApiClientImplTest
[appc.git] / appc-adapters / appc-chef-adapter / appc-chef-adapter-bundle / src / test / java / org / onap / appc / adapter / chef / chefclient / impl / ChefApiClientImplTest.java
index f1e215a..d3f1177 100644 (file)
@@ -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