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;
32 import java.util.HashMap;
35 import org.apache.http.HttpStatus;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.rules.ExpectedException;
39 import org.onap.so.cloudify.v3.client.DeploymentsResource.CreateDeployment;
40 import org.onap.so.cloudify.v3.client.DeploymentsResource.DeleteDeployment;
41 import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeployment;
42 import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs;
43 import org.onap.so.cloudify.v3.client.DeploymentsResource.ListDeployments;
44 import org.onap.so.cloudify.v3.model.CreateDeploymentParams;
45 import org.onap.so.cloudify.v3.model.Deployment;
46 import org.onap.so.cloudify.v3.model.Deployments;
47 import org.onap.so.cloudify.v3.model.DeploymentOutputs;
49 import com.github.tomakehurst.wiremock.junit.WireMockRule;
51 public class DeploymentsResourceTest {
53 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
56 public ExpectedException thrown = ExpectedException.none();
59 public void cloudifyDeploymentsCreate() {
60 wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
61 .withBody("{ \"id\": \"123\" }")
62 .withStatus(HttpStatus.SC_OK)));
64 int port = wireMockRule.port();
66 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
67 DeploymentsResource br = c.deployments();
69 CreateDeploymentParams cdp = new CreateDeploymentParams();
70 cdp.setBlueprintId("123");
71 Map<String, Object> inputs = new HashMap<String, Object>();
72 cdp.setInputs(inputs);
73 CreateDeployment cd = br.create("123", cdp);
74 Deployment d = cd.execute();
75 assertEquals("123", d.getId());
79 public void cloudifyDeploymentsList() {
80 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")).willReturn(aResponse().withHeader("Content-Type", "application/json")
81 .withBody("{ \"items\": {\"id\": \"123\" } } ")
82 .withStatus(HttpStatus.SC_OK)));
84 int port = wireMockRule.port();
86 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
87 DeploymentsResource br = c.deployments();
88 ListDeployments ld = br.list();
89 Deployments d = ld.execute();
90 assertEquals("123", d.getItems().get(0).getId());
94 public void cloudifyDeploymentsGet() {
95 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
96 .withBody("{ \"id\": \"123\" }")
97 .withStatus(HttpStatus.SC_OK)));
99 int port = wireMockRule.port();
101 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
102 DeploymentsResource br = c.deployments();
103 GetDeployment gd = br.byId("123");
104 Deployment d = gd.execute();
105 assertEquals("123", d.getId());
109 public void cloudifyDeploymentsGetOutputs() {
110 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs")).willReturn(aResponse().withHeader("Content-Type", "application/json")
111 .withBody("{ \"deployment_id\": \"123\" }")
112 .withStatus(HttpStatus.SC_OK)));
114 int port = wireMockRule.port();
116 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
117 DeploymentsResource br = c.deployments();
118 GetDeploymentOutputs gdo = br.outputsById("123");
119 DeploymentOutputs d = gdo.execute();
120 assertEquals("123", d.getDeploymentId());
122 Map<String, Object> map = new HashMap<String, Object>();
123 map.put("test", "answer");
124 assertEquals("answer", d.getMapValue(map, "test", String.class));
126 Integer i = d.getMapValue(map, "nil", Integer.class);
129 i = d.getMapValue(map, "test", Integer.class);
134 public void cloudifyDeploymentsDelete() {
135 wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name")).willReturn(aResponse().withHeader("Content-Type", "application/json")
136 .withBody("{ \"id\": \"123\" }")
137 .withStatus(HttpStatus.SC_OK)));
139 int port = wireMockRule.port();
141 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
142 DeploymentsResource br = c.deployments();
143 DeleteDeployment cd = br.deleteByName("name");
144 Deployment d = cd.execute();
145 assertEquals("123", d.getId());