summaryrefslogtreecommitdiffstats
path: root/cloudify-client/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'cloudify-client/src/test/java/org/onap')
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java63
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java103
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java56
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java254
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java147
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java148
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java170
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java98
8 files changed, 1039 insertions, 0 deletions
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java
new file mode 100644
index 0000000000..d38c7468db
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.onap.so.cloudify;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.PojoClassFilter;
+import com.openpojo.reflection.filters.FilterEnum;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+public class BeanMultiTest {
+
+ Validator validator;
+ PojoClassFilter enumFilter;
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Before
+ public void setup(){
+ enumFilter = new FilterEnum();
+ validator = ValidatorBuilder.create()
+ .with(new SetterMustExistRule(),
+ new GetterMustExistRule())
+ .with(new SetterTester(),
+ new GetterTester())
+ .build();
+ }
+ @Test
+ public void validateBeansMsoApihandlerBeans() {
+
+ validator.validate("org.onap.so.cloudify.v3.model",enumFilter);
+ }
+
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/src/test/java");
+ }
+ }
+}
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java
new file mode 100644
index 0000000000..fc55eaf19c
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java
@@ -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.onap.so.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.onap.so.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/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java
new file mode 100644
index 0000000000..ba43dc9e78
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java
@@ -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.onap.so.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/api/v3/tokens")).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();
+ }
+}
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java
new file mode 100644
index 0000000000..4475fff093
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java
@@ -0,0 +1,254 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.onap.so.cloudify.connector.http;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+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;
+import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.verify;
+import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.deleteRequestedFor;
+import org.apache.http.HttpStatus;
+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.onap.so.cloudify.base.client.CloudifyConnectException;
+import org.onap.so.cloudify.base.client.CloudifyRequest;
+import org.onap.so.cloudify.base.client.CloudifyResponseException;
+import org.onap.so.cloudify.base.client.Entity;
+import org.onap.so.cloudify.base.client.HttpMethod;
+import org.onap.so.cloudify.v3.model.Deployment;
+
+public class HttpClientConnectorTest {
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void sunnyDay_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();
+ CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>();
+ Deployment deployment = new Deployment();
+ deployment.setId("id");
+ request.entity(deployment, "application/json");
+ request.endpoint("http://localhost:"+port+"/testUrl");
+ request.setBasicAuthentication("USER","PASSWORD");
+ request.header("Content-Type","application/json");
+ request.method(HttpMethod.POST);
+ conector.request(request);
+ verify(postRequestedFor(urlEqualTo("/testUrl")));
+ }
+
+
+ @Test
+ public void sunnyDay_GET(){
+ wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK)));
+ 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);
+ verify(getRequestedFor(urlEqualTo("/testUrl")));
+ }
+
+ @Test
+ public void sunnyDay_PUT(){
+ wireMockRule.stubFor(put(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK)));
+ 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.PUT);
+ conector.request(request);
+ verify(putRequestedFor(urlEqualTo("/testUrl")));
+ }
+
+
+ @Test
+ public void sunnyDay_DELETE(){
+ wireMockRule.stubFor(delete(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK)));
+ 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.DELETE);
+ conector.request(request);
+ verify(deleteRequestedFor(urlEqualTo("/testUrl")));
+ }
+
+
+ @Test
+ public void rainyDay_PATCH(){
+ thrown.expect(HttpClientException.class);
+ thrown.expectMessage("Unrecognized HTTP Method: PATCH");
+ HttpClientConnector conector = new HttpClientConnector();
+ CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>();
+ request.endpoint("http://localhost:123123/testUrl");
+ request.setBasicAuthentication("USER","PASSWORD");
+ request.method(HttpMethod.PATCH);
+ conector.request(request);
+
+ }
+
+ @Test
+ public void rainyDayRunTimeException(){
+ wireMockRule.stubFor(post(urlEqualTo("/503")).willReturn(
+ aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure")));
+ thrown.expect(RuntimeException.class);
+ thrown.expectMessage("Unexpected client exception");
+ HttpClientConnector conector = new HttpClientConnector();
+ CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>();
+ request.endpoint("http://localhost:123123/503");
+ request.setBasicAuthentication("USER","PASSWORD");
+ request.method(HttpMethod.POST);
+ 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(){
+ wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_NOT_FOUND)));
+
+ 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/onap/so/cloudify/v3/client/BlueprintsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java
new file mode 100644
index 0000000000..6155cf287c
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java
@@ -0,0 +1,147 @@
+/*-
+ * ============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.onap.so.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.onap.so.cloudify.v3.client.BlueprintsResource.DeleteBlueprint;
+import org.onap.so.cloudify.v3.client.BlueprintsResource.GetBlueprint;
+import org.onap.so.cloudify.v3.client.BlueprintsResource.ListBlueprints;
+import org.onap.so.cloudify.v3.client.BlueprintsResource.UploadBlueprint;
+import org.onap.so.cloudify.v3.model.Blueprint;
+import org.onap.so.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/123")).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/123")).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/123")).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/123")).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());
+ }
+
+ @Test
+ public void cloudifyClientBlueprintGetMetadataById() {
+ wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).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.getMetadataById("123");
+ Blueprint b = gb.execute();
+ assertEquals("123", b.getId());
+ }
+
+
+}
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java
new file mode 100644
index 0000000000..071b7638e6
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java
@@ -0,0 +1,148 @@
+/*-
+ * ============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.onap.so.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 static org.junit.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.cloudify.v3.client.DeploymentsResource.CreateDeployment;
+import org.onap.so.cloudify.v3.client.DeploymentsResource.DeleteDeployment;
+import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeployment;
+import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs;
+import org.onap.so.cloudify.v3.client.DeploymentsResource.ListDeployments;
+import org.onap.so.cloudify.v3.model.CreateDeploymentParams;
+import org.onap.so.cloudify.v3.model.Deployment;
+import org.onap.so.cloudify.v3.model.Deployments;
+import org.onap.so.cloudify.v3.model.DeploymentOutputs;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class DeploymentsResourceTest {
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void cloudifyDeploymentsCreate() {
+ wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123")).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");
+ DeploymentsResource br = c.deployments();
+
+ CreateDeploymentParams cdp = new CreateDeploymentParams();
+ cdp.setBlueprintId("123");
+ Map<String, Object> inputs = new HashMap<String, Object>();
+ cdp.setInputs(inputs);
+ CreateDeployment cd = br.create("123", cdp);
+ Deployment d = cd.execute();
+ assertEquals("123", d.getId());
+ }
+
+ @Test
+ public void cloudifyDeploymentsList() {
+ wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")).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");
+ DeploymentsResource br = c.deployments();
+ ListDeployments ld = br.list();
+ Deployments d = ld.execute();
+ assertEquals("123", d.getItems().get(0).getId());
+ }
+
+ @Test
+ public void cloudifyDeploymentsGet() {
+ wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123")).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");
+ DeploymentsResource br = c.deployments();
+ GetDeployment gd = br.byId("123");
+ Deployment d = gd.execute();
+ assertEquals("123", d.getId());
+ }
+
+ @Test
+ public void cloudifyDeploymentsGetOutputs() {
+ wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody("{ \"deployment_id\": \"123\" }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ int port = wireMockRule.port();
+
+ Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+ DeploymentsResource br = c.deployments();
+ GetDeploymentOutputs gdo = br.outputsById("123");
+ DeploymentOutputs d = gdo.execute();
+ assertEquals("123", d.getDeploymentId());
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("test", "answer");
+ assertEquals("answer", d.getMapValue(map, "test", String.class));
+
+ Integer i = d.getMapValue(map, "nil", Integer.class);
+ assertNull( i );
+
+ i = d.getMapValue(map, "test", Integer.class);
+ assertNull( i );
+ }
+
+ @Test
+ public void cloudifyDeploymentsDelete() {
+ wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name")).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");
+ DeploymentsResource br = c.deployments();
+ DeleteDeployment cd = br.deleteByName("name");
+ Deployment d = cd.execute();
+ assertEquals("123", d.getId());
+ }
+
+}
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java
new file mode 100644
index 0000000000..098b5cf387
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java
@@ -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.onap.so.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.onap.so.cloudify.connector.http.HttpClientException;
+import org.onap.so.cloudify.v3.client.ExecutionsResource.CancelExecution;
+import org.onap.so.cloudify.v3.client.ExecutionsResource.GetExecution;
+import org.onap.so.cloudify.v3.client.ExecutionsResource.ListExecutions;
+import org.onap.so.cloudify.v3.client.ExecutionsResource.StartExecution;
+import org.onap.so.cloudify.v3.client.ExecutionsResource.UpdateExecution;
+import org.onap.so.cloudify.v3.model.CancelExecutionParams;
+import org.onap.so.cloudify.v3.model.Execution;
+import org.onap.so.cloudify.v3.model.Executions;
+import org.onap.so.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/123")).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/123")).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());
+ }
+
+
+
+}
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java
new file mode 100644
index 0000000000..c5f3be4ce2
--- /dev/null
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java
@@ -0,0 +1,98 @@
+/*-
+ * ============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.onap.so.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.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.onap.so.cloudify.connector.http.HttpClientException;
+import org.onap.so.cloudify.v3.client.NodeInstancesResource.GetNodeInstance;
+import org.onap.so.cloudify.v3.client.NodeInstancesResource.ListNodeInstances;
+import org.onap.so.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance;
+import org.onap.so.cloudify.v3.model.NodeInstance;
+import org.onap.so.cloudify.v3.model.NodeInstances;
+import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class NodeInstancesResourceTest {
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void nodeInstanceGet() {
+ wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody("{ \"node_instance\": { \"id\": \"123\" } }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ int port = wireMockRule.port();
+
+ Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+ NodeInstancesResource nir = c.nodeInstances();
+ GetNodeInstance gni = nir.byId("123");
+ NodeInstance ni = gni.execute();
+ assertEquals("123", ni.getId());
+ }
+
+ @Test
+ public void nodeInstanceList() {
+ wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+// .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ")
+ .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ")
+ .withStatus(HttpStatus.SC_OK)));
+
+ int port = wireMockRule.port();
+
+ Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+ NodeInstancesResource nir = c.nodeInstances();
+ ListNodeInstances lni = nir.list();
+ NodeInstances ni = lni.execute();
+ assertEquals("123", ni.getItems().get(0).getId());
+ }
+
+ @Test
+ public void nodeInstanceUpdate() {
+ wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody("{ \"node_instance\": { \"id\": \"123\" } }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ int port = wireMockRule.port();
+
+ Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
+ NodeInstancesResource nir = c.nodeInstances();
+ UpdateNodeInstanceParams params = new UpdateNodeInstanceParams();
+
+ UpdateNodeInstance uni = nir.update("123", params);
+ thrown.expect(HttpClientException.class); /// ???????
+ NodeInstance ni = uni.execute();
+ }
+}