Replaced all tabs with spaces in java and pom.xml
[so.git] / cloudify-client / src / test / java / org / onap / so / cloudify / v3 / client / DeploymentsResourceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.cloudify.v3.client;
22
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;
32 import java.util.Map;
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;
47
48 public class DeploymentsResourceTest {
49     @Rule
50     public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
51
52     @Rule
53     public ExpectedException thrown = ExpectedException.none();
54
55     @Test
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)));
60
61         int port = wireMockRule.port();
62
63         Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
64         DeploymentsResource br = c.deployments();
65
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());
73     }
74
75     @Test
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)));
80
81         int port = wireMockRule.port();
82
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());
88     }
89
90     @Test
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)));
95
96         int port = wireMockRule.port();
97
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());
103     }
104
105     @Test
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)));
110
111         int port = wireMockRule.port();
112
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());
118
119         Map<String, Object> map = new HashMap<String, Object>();
120         map.put("test", "answer");
121         assertEquals("answer", d.getMapValue(map, "test", String.class));
122
123         Integer i = d.getMapValue(map, "nil", Integer.class);
124         assertNull(i);
125
126         i = d.getMapValue(map, "test", Integer.class);
127         assertNull(i);
128     }
129
130     @Test
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)));
135
136         int port = wireMockRule.port();
137
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());
143     }
144
145 }