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;
31 import java.io.ByteArrayInputStream;
32 import java.io.InputStream;
33 import java.nio.charset.StandardCharsets;
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.BlueprintsResource.DeleteBlueprint;
40 import org.onap.so.cloudify.v3.client.BlueprintsResource.GetBlueprint;
41 import org.onap.so.cloudify.v3.client.BlueprintsResource.ListBlueprints;
42 import org.onap.so.cloudify.v3.client.BlueprintsResource.UploadBlueprint;
43 import org.onap.so.cloudify.v3.model.Blueprint;
44 import org.onap.so.cloudify.v3.model.Blueprints;
46 import com.github.tomakehurst.wiremock.junit.WireMockRule;
48 public class BlueprintsResourceTest {
50 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
53 public ExpectedException thrown = ExpectedException.none();
56 public void cloudifyClientBlueprintFromStream() {
57 wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
58 .withBody("{\"id\": \"123\"}")
59 .withStatus(HttpStatus.SC_OK)));
61 int port = wireMockRule.port();
63 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
64 BlueprintsResource br = c.blueprints();
65 InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8));
66 UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is);
67 Blueprint b = ub.execute();
68 assertEquals("123", b.getId());
72 public void cloudifyClientBlueprintFromUrl() {
73 wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
74 .withBody("{\"id\": \"123\"}")
75 .withStatus(HttpStatus.SC_OK)));
77 int port = wireMockRule.port();
79 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
80 BlueprintsResource br = c.blueprints();
81 UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:"+port+"/blueprint");
82 Blueprint b = ub.execute();
83 assertEquals("123", b.getId());
87 public void cloudifyClientBlueprintDelete() {
88 wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
89 .withBody("{\"id\": \"123\"}")
90 .withStatus(HttpStatus.SC_OK)));
92 int port = wireMockRule.port();
94 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
95 BlueprintsResource br = c.blueprints();
96 DeleteBlueprint db = br.deleteById("123");
97 Blueprint b = db.execute();
98 assertEquals("123", b.getId());
102 public void cloudifyClientBlueprintList() {
103 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")).willReturn(aResponse().withHeader("Content-Type", "application/json")
104 .withBody("{\"items\": [{\"id\": \"123\"}]}")
105 .withStatus(HttpStatus.SC_OK)));
107 int port = wireMockRule.port();
109 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
110 BlueprintsResource br = c.blueprints();
111 ListBlueprints lb = br.list();
112 Blueprints b = lb.execute();
113 assertEquals("123", b.getItems().get(0).getId());
117 public void cloudifyClientBlueprintGetById() {
118 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
119 .withBody("{\"id\": \"123\"}")
120 .withStatus(HttpStatus.SC_OK)));
122 int port = wireMockRule.port();
124 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
125 BlueprintsResource br = c.blueprints();
126 GetBlueprint gb = br.getById("123");
127 Blueprint b = gb.execute();
128 assertEquals("123", b.getId());
132 public void cloudifyClientBlueprintGetMetadataById() {
133 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json")
134 .withBody("{\"id\": \"123\"}")
135 .withStatus(HttpStatus.SC_OK)));
137 int port = wireMockRule.port();
139 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
140 BlueprintsResource br = c.blueprints();
141 GetBlueprint gb = br.getMetadataById("123");
142 Blueprint b = gb.execute();
143 assertEquals("123", b.getId());