2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.cloudify.v3.client;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.put;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
28 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNull;
31 import java.util.HashMap;
33 import org.apache.http.HttpStatus;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.onap.so.cloudify.v3.client.DeploymentsResource.CreateDeployment;
38 import org.onap.so.cloudify.v3.client.DeploymentsResource.DeleteDeployment;
39 import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeployment;
40 import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs;
41 import org.onap.so.cloudify.v3.client.DeploymentsResource.ListDeployments;
42 import org.onap.so.cloudify.v3.model.CreateDeploymentParams;
43 import org.onap.so.cloudify.v3.model.Deployment;
44 import org.onap.so.cloudify.v3.model.Deployments;
45 import org.onap.so.cloudify.v3.model.DeploymentOutputs;
46 import com.github.tomakehurst.wiremock.junit.WireMockRule;
48 public class DeploymentsResourceTest {
50 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
53 public ExpectedException thrown = ExpectedException.none();
56 public void cloudifyDeploymentsCreate() {
57 wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123"))
58 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }")
59 .withStatus(HttpStatus.SC_OK)));
61 int port = wireMockRule.port();
63 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
64 DeploymentsResource br = c.deployments();
66 CreateDeploymentParams cdp = new CreateDeploymentParams();
67 cdp.setBlueprintId("123");
68 Map<String, Object> inputs = new HashMap<String, Object>();
69 cdp.setInputs(inputs);
70 CreateDeployment cd = br.create("123", cdp);
71 Deployment d = cd.execute();
72 assertEquals("123", d.getId());
76 public void cloudifyDeploymentsList() {
77 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments"))
78 .willReturn(aResponse().withHeader("Content-Type", "application/json")
79 .withBody("{ \"items\": {\"id\": \"123\" } } ").withStatus(HttpStatus.SC_OK)));
81 int port = wireMockRule.port();
83 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
84 DeploymentsResource br = c.deployments();
85 ListDeployments ld = br.list();
86 Deployments d = ld.execute();
87 assertEquals("123", d.getItems().get(0).getId());
91 public void cloudifyDeploymentsGet() {
92 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123"))
93 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }")
94 .withStatus(HttpStatus.SC_OK)));
96 int port = wireMockRule.port();
98 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
99 DeploymentsResource br = c.deployments();
100 GetDeployment gd = br.byId("123");
101 Deployment d = gd.execute();
102 assertEquals("123", d.getId());
106 public void cloudifyDeploymentsGetOutputs() {
107 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs"))
108 .willReturn(aResponse().withHeader("Content-Type", "application/json")
109 .withBody("{ \"deployment_id\": \"123\" }").withStatus(HttpStatus.SC_OK)));
111 int port = wireMockRule.port();
113 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
114 DeploymentsResource br = c.deployments();
115 GetDeploymentOutputs gdo = br.outputsById("123");
116 DeploymentOutputs d = gdo.execute();
117 assertEquals("123", d.getDeploymentId());
119 Map<String, Object> map = new HashMap<String, Object>();
120 map.put("test", "answer");
121 assertEquals("answer", d.getMapValue(map, "test", String.class));
123 Integer i = d.getMapValue(map, "nil", Integer.class);
126 i = d.getMapValue(map, "test", Integer.class);
131 public void cloudifyDeploymentsDelete() {
132 wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name"))
133 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }")
134 .withStatus(HttpStatus.SC_OK)));
136 int port = wireMockRule.port();
138 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
139 DeploymentsResource br = c.deployments();
140 DeleteDeployment cd = br.deleteByName("name");
141 Deployment d = cd.execute();
142 assertEquals("123", d.getId());