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.openecomp.mso.cloudify.v3.client;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.patch;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
27 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
28 import static org.junit.Assert.assertEquals;
30 import org.apache.http.HttpStatus;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.ExpectedException;
34 import org.openecomp.mso.cloudify.connector.http.HttpClientException;
35 import org.openecomp.mso.cloudify.v3.client.NodeInstancesResource.GetNodeInstance;
36 import org.openecomp.mso.cloudify.v3.client.NodeInstancesResource.ListNodeInstances;
37 import org.openecomp.mso.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance;
38 import org.openecomp.mso.cloudify.v3.model.NodeInstance;
39 import org.openecomp.mso.cloudify.v3.model.NodeInstances;
40 import org.openecomp.mso.cloudify.v3.model.UpdateNodeInstanceParams;
42 import com.github.tomakehurst.wiremock.junit.WireMockRule;
44 public class NodeInstancesResourceTest {
46 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
49 public ExpectedException thrown = ExpectedException.none();
52 public void nodeInstanceGet() {
53 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
54 .withBody("{ \"node_instance\": { \"id\": \"123\" } }")
55 .withStatus(HttpStatus.SC_OK)));
57 int port = wireMockRule.port();
59 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
60 NodeInstancesResource nir = c.nodeInstances();
61 GetNodeInstance gni = nir.byId("123");
62 NodeInstance ni = gni.execute();
63 assertEquals("123", ni.getId());
67 public void nodeInstanceList() {
68 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")).willReturn(aResponse().withHeader("Content-Type", "application/json")
69 // .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ")
70 .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ")
71 .withStatus(HttpStatus.SC_OK)));
73 int port = wireMockRule.port();
75 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
76 NodeInstancesResource nir = c.nodeInstances();
77 ListNodeInstances lni = nir.list();
78 NodeInstances ni = lni.execute();
79 assertEquals("123", ni.getItems().get(0).getId());
83 public void nodeInstanceUpdate() {
84 wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json")
85 .withBody("{ \"node_instance\": { \"id\": \"123\" } }")
86 .withStatus(HttpStatus.SC_OK)));
88 int port = wireMockRule.port();
90 Cloudify c = new Cloudify("http://localhost:"+port, "tenant");
91 NodeInstancesResource nir = c.nodeInstances();
92 UpdateNodeInstanceParams params = new UpdateNodeInstanceParams();
94 UpdateNodeInstance uni = nir.update("123", params);
95 thrown.expect(HttpClientException.class); /// ???????
96 NodeInstance ni = uni.execute();