Cloudify REST Client unit tests 97/41497/1
authorArthur Martella <amartell@research.att.com>
Sat, 7 Apr 2018 02:34:10 +0000 (22:34 -0400)
committerArthur Martella <amartell@research.att.com>
Sat, 7 Apr 2018 02:34:10 +0000 (22:34 -0400)
Change-Id: I8a9c50a08106f51b867598265bce3993e0ea1af9
Issue-ID: SO-489
Signed-off-by: Arthur Martella <amartell@research.att.com>
cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java [new file with mode: 0644]
cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java [new file with mode: 0644]
cloudify-client/src/test/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnectorTest.java
cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java [new file with mode: 0644]
cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java [new file with mode: 0644]

diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java
new file mode 100644 (file)
index 0000000..1836bc5
--- /dev/null
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.cloudify.base.client;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.openecomp.mso.cloudify.v3.model.Execution;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class CloudifyClientTest {
+       @Rule
+       public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+       
+       @Rule
+       public ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void clientCreate(){
+               wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+               CloudifyClient cc = new CloudifyClient("http://localhost:"+port);
+               cc.setToken("token");
+               CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class);
+               Execution x = crx.execute();
+               assertEquals("123", x.getId());
+       }
+
+       @Test
+       public void clientCreateWithBadConnector(){
+               thrown.expect(CloudifyResponseException.class);
+               wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+               CloudifyClientConnector ccc = new CloudifyClientConnector(){
+                       @Override
+                       public <T> CloudifyResponse request(CloudifyRequest<T> request) {
+                               throw new CloudifyResponseException("test case", 401);
+                       }}; 
+               CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc);
+//             cc.setToken("token");
+               CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class);
+               Execution x = crx.execute();
+       }
+
+       @Test
+       public void clientCreateWithBadConnectorAndToken(){
+               thrown.expect(CloudifyResponseException.class);
+               wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+               CloudifyClientConnector ccc = new CloudifyClientConnector(){
+                       @Override
+                       public <T> CloudifyResponse request(CloudifyRequest<T> request) {
+                               throw new CloudifyResponseException("test case", 401);
+                       }}; 
+               CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc);
+               cc.setToken("token");
+               CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class);
+               Execution x = crx.execute();
+       }
+
+       @Test
+       public void clientCreateWithTenant(){
+               wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+               CloudifyClient cc = new CloudifyClient("http://localhost:"+port, "other_tenant");
+               cc.setToken("token");
+               cc.property("property", "value");
+               CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class);
+               Execution x = crx.execute();
+               assertEquals("123", x.getId());
+       }
+
+}
diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java
new file mode 100644 (file)
index 0000000..c28b6b9
--- /dev/null
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.cloudify.base.client;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class CloudifyClientTokenProviderTest {
+       @Rule
+       public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+       
+       @Rule
+       public ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void createTokenProvider() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("{\"role\": \"user\", \"value\": \"tokenVal\"}").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+
+               CloudifyClientTokenProvider cctp = new CloudifyClientTokenProvider("http://localhost:"+port+"/testUrl", "user", "pswd");
+               String token = cctp.getToken();
+               assertEquals("tokenVal", token);
+               token = cctp.getToken();
+               assertEquals("tokenVal", token);
+               cctp.expireToken();
+       }
+}
index b768c93..72d2de6 100644 (file)
@@ -25,6 +25,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.post;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
 
+import com.github.tomakehurst.wiremock.http.Fault;
 import com.github.tomakehurst.wiremock.junit.WireMockRule;
 import static com.github.tomakehurst.wiremock.client.WireMock.get;
 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
@@ -41,8 +42,16 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.openecomp.mso.cloudify.base.client.CloudifyConnectException;
 import org.openecomp.mso.cloudify.base.client.CloudifyRequest;
 import org.openecomp.mso.cloudify.base.client.CloudifyResponseException;
+import org.openecomp.mso.cloudify.base.client.Entity;
 import org.openecomp.mso.cloudify.base.client.HttpMethod;
 import org.openecomp.mso.cloudify.v3.model.Deployment;
 
@@ -53,7 +62,7 @@ public class HttpClientConnectorTest {
        
        @Rule
        public ExpectedException thrown = ExpectedException.none();
-       
+
        @Test
        public void sunnyDay_POST(){                    
                wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse()
@@ -71,8 +80,8 @@ public class HttpClientConnectorTest {
                conector.request(request);
                verify(postRequestedFor(urlEqualTo("/testUrl")));
        }
-       
-       
+
+
        @Test
        public void sunnyDay_GET(){                     
                wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
@@ -118,7 +127,7 @@ public class HttpClientConnectorTest {
        
        
        @Test
-       public void rainydDay_PATCH(){                   
+       public void rainyDay_PATCH(){                    
                thrown.expect(HttpClientException.class);
                thrown.expectMessage("Unrecognized HTTP Method: PATCH");
                HttpClientConnector conector = new HttpClientConnector();
@@ -130,9 +139,8 @@ public class HttpClientConnectorTest {
        
        }
        
-       
        @Test
-       public void rainydDay_RunTimeException(){       
+       public void rainyDayRunTimeException(){ 
                wireMockRule.stubFor(post(urlEqualTo("/503")).willReturn(
                 aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure")));
                thrown.expect(RuntimeException.class);
@@ -145,6 +153,99 @@ public class HttpClientConnectorTest {
                conector.request(request);
        
        }
+       
+       @Test
+       public void rainyDayBadUri() {
+               wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK)));
+               thrown.expect(HttpClientException.class);
+               int port = wireMockRule.port();
+               HttpClientConnector conector = new HttpClientConnector();
+               CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>();
+               Deployment deployment = new Deployment();
+               deployment.setId("id");
+               request.entity(deployment, "application/json");
+               request.endpoint("(@#$@(#*$&asfasdf");
+               request.setBasicAuthentication("USER","PASSWORD");
+               request.header("Content-Type","application/json");
+               request.method(HttpMethod.POST);
+               conector.request(request);
+       }
+
+       @Test
+       public void sunnyDayWithJsonEntity_POST(){                      
+               wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+               HttpClientConnector conector = new HttpClientConnector();
+               
+               Deployment deployment = new Deployment();
+               deployment.setId("id");
+
+               CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/", Entity.json(deployment), null);
+
+               request.endpoint("http://localhost:"+port);
+               request.path("testUrl");
+               request.header("Content-Type","application/json");
+               request.header("Content-Type",  null);
+               
+               request.returnType(Deployment.class);
+               assertEquals(Deployment.class, request.returnType());
+               
+               Entity<Deployment> t = request.json(deployment);
+               assertEquals(t.getEntity().getId(), "id");
+
+               request.queryParam("test", "one").queryParam("test",  "two");
+               
+               conector.request(request);
+
+               verify(postRequestedFor(urlEqualTo("/testUrl?test=two")));
+       }
+
+       @Test
+       public void sunnyDayWithStreamEntity_POST() {                   
+               wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+                               .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK)));
+               int port = wireMockRule.port();
+               HttpClientConnector conector = new HttpClientConnector();
+
+               InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8));
 
+               CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/testUrl", Entity.stream(is), null);
+               
+               request.endpoint("http://localhost:"+port);
+               request.setBasicAuthentication("USER","PASSWORD");
+               request.header("Content-Type","application/json");
+
+               conector.request(request);
+               verify(postRequestedFor(urlEqualTo("/testUrl")));
+       }
+
+       @Test
+       public void rainyDayGarbageData(){                      
+               wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(
+                               aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE)));
+               thrown.expect(CloudifyConnectException.class);
+               int port = wireMockRule.port();
+               HttpClientConnector conector = new HttpClientConnector();
+               CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>();
+               request.endpoint("http://localhost:"+port+"/testUrl");
+               request.setBasicAuthentication("USER","PASSWORD");
+               request.method(HttpMethod.GET);
+               conector.request(request);
+       }
+
+       @Test
+       public void rainyDayEmptyResponse(){                    
+               thrown.expect(HttpClientException.class);
+               int port = wireMockRule.port();
+               HttpClientConnector conector = new HttpClientConnector();
+               CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>();
+               request.endpoint("http://localhost:"+port+"/testUrl");
+               request.setBasicAuthentication("USER","PASSWORD");
+               request.method(HttpMethod.GET);
+               conector.request(request);  // gets down to "Get here on an error response (4XX-5XX)", then tries to throw a CloudifyResponseException, which calls getEntity, which tries to parse an HTML error page as a JSON, which causes the HttpClientException.
+       }
+       
 
 }
\ No newline at end of file
diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java
new file mode 100644 (file)
index 0000000..ec7435f
--- /dev/null
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.cloudify.v3.client;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.delete;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.DeleteBlueprint;
+import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.GetBlueprint;
+import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.ListBlueprints;
+import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.UploadBlueprint;
+import org.openecomp.mso.cloudify.v3.model.Blueprint;
+import org.openecomp.mso.cloudify.v3.model.Blueprints;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class BlueprintsResourceTest {
+       @Rule
+       public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+       
+       @Rule
+       public ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void cloudifyClientBlueprintFromStream() {
+               wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"id\": \"123\"}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               BlueprintsResource br = c.blueprints();
+               InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8));
+               UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is);
+               Blueprint b = ub.execute();
+               assertEquals("123", b.getId());
+       }
+
+       @Test
+       public void cloudifyClientBlueprintFromUrl() {
+               wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"id\": \"123\"}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               BlueprintsResource br = c.blueprints();
+               UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:"+port+"/blueprint");
+               Blueprint b = ub.execute();
+               assertEquals("123", b.getId());
+       }
+
+       @Test
+       public void cloudifyClientBlueprintDelete() {
+               wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"id\": \"123\"}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               BlueprintsResource br = c.blueprints();
+               DeleteBlueprint db = br.deleteById("123");
+               Blueprint b = db.execute();
+               assertEquals("123", b.getId());
+       }
+
+       @Test
+       public void cloudifyClientBlueprintList() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"items\": [{\"id\": \"123\"}]}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               BlueprintsResource br = c.blueprints();
+               ListBlueprints lb = br.list();
+               Blueprints b = lb.execute();
+               assertEquals("123", b.getItems().get(0).getId());
+       }
+
+       @Test
+       public void cloudifyClientBlueprintGetById() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"id\": \"123\"}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               BlueprintsResource br = c.blueprints();
+               GetBlueprint gb = br.getById("123");
+               Blueprint b = gb.execute();
+               assertEquals("123", b.getId());
+       }
+
+
+}
diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java
new file mode 100644 (file)
index 0000000..93f5473
--- /dev/null
@@ -0,0 +1,170 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.cloudify.v3.client;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.patch;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.openecomp.mso.cloudify.connector.http.HttpClientException;
+import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.CancelExecution;
+import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.GetExecution;
+import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.ListExecutions;
+import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.StartExecution;
+import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.UpdateExecution;
+import org.openecomp.mso.cloudify.v3.model.CancelExecutionParams;
+import org.openecomp.mso.cloudify.v3.model.Execution;
+import org.openecomp.mso.cloudify.v3.model.Executions;
+import org.openecomp.mso.cloudify.v3.model.StartExecutionParams;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class ExecutionsResourceTest {
+       @Rule
+       public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+       
+       @Rule
+       public ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void cloudifyClientExecutions() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"items\": [{ \"id\": \"345\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+               ListExecutions lx = xr.list();
+               Executions x = lx.execute();
+               assertEquals("123", x.getItems().get(1).getId());
+       }
+
+       @Test
+       public void cloudifyClientExecutionsSorted() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"items\": [{ \"id\": \"123\" }, { \"id\": \"345\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+               ListExecutions lx = xr.listSorted("id");
+               Executions x = lx.execute();
+               assertEquals("345", x.getItems().get(1).getId());
+       }
+
+       @Test
+       public void cloudifyClientExecutionsFilter() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{\"items\": [{ \"id\": \"121\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+               ListExecutions lx = xr.listFiltered("a=b", "id");
+               Executions x = lx.execute();
+               assertEquals("123", x.getItems().get(1).getId());
+       }
+
+       @Test
+       public void cloudifyClientExecutionById() {
+               wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{ \"id\": \"123\" }")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+               GetExecution gx = xr.byId("123");
+               Execution x = gx.execute();
+               assertEquals("123", x.getId());
+       }
+
+       @Test
+       public void cloudifyClientStartExecution() {
+               wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{ \"id\": \"123\" }")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+
+               StartExecutionParams params = new StartExecutionParams();
+               StartExecution sx = xr.start(params);
+               Execution x = sx.execute();
+               assertEquals("123", x.getId());
+       }
+
+       @Test
+       public void cloudifyClientUpdateExecution() {
+               thrown.expect(HttpClientException.class);
+               thrown.expectMessage("Unrecognized HTTP Method: PATCH");
+               
+               wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{ \"id\": \"123\" }")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+
+               UpdateExecution ux = xr.updateStatus("123", "good");
+               Execution x = ux.execute();
+               assertEquals("123", x.getId());
+       }
+
+       @Test
+       public void cloudifyClientCancelExecution() {
+               wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+                               .withBody("{ \"id\": \"123\" }")
+                               .withStatus(HttpStatus.SC_OK)));
+               
+               int port = wireMockRule.port();
+
+               Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+               ExecutionsResource xr = c.executions();
+
+               CancelExecutionParams params = new CancelExecutionParams();
+               CancelExecution cx = xr.cancel("123", params);
+               Execution x = cx.execute();
+               assertEquals("123", x.getId());
+       }
+
+       
+
+}