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.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;
29 import org.apache.http.HttpStatus;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.onap.so.cloudify.connector.http.HttpClientException;
34 import org.onap.so.cloudify.v3.client.NodeInstancesResource.GetNodeInstance;
35 import org.onap.so.cloudify.v3.client.NodeInstancesResource.ListNodeInstances;
36 import org.onap.so.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance;
37 import org.onap.so.cloudify.v3.model.NodeInstance;
38 import org.onap.so.cloudify.v3.model.NodeInstances;
39 import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams;
40 import com.github.tomakehurst.wiremock.junit.WireMockRule;
42 public class NodeInstancesResourceTest {
44 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
47 public ExpectedException thrown = ExpectedException.none();
50 public void nodeInstanceGet() {
51 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/123"))
52 .willReturn(aResponse().withHeader("Content-Type", "application/json")
53 .withBody("{ \"node_instance\": { \"id\": \"123\" } }").withStatus(HttpStatus.SC_OK)));
55 int port = wireMockRule.port();
57 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
58 NodeInstancesResource nir = c.nodeInstances();
59 GetNodeInstance gni = nir.byId("123");
60 NodeInstance ni = gni.execute();
61 assertEquals("123", ni.getId());
65 public void nodeInstanceList() {
66 wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances"))
67 .willReturn(aResponse().withHeader("Content-Type", "application/json")
68 // .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ")
69 .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ").withStatus(HttpStatus.SC_OK)));
71 int port = wireMockRule.port();
73 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
74 NodeInstancesResource nir = c.nodeInstances();
75 ListNodeInstances lni = nir.list();
76 NodeInstances ni = lni.execute();
77 assertEquals("123", ni.getItems().get(0).getId());
81 public void nodeInstanceUpdate() {
82 wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/"))
83 .willReturn(aResponse().withHeader("Content-Type", "application/json")
84 .withBody("{ \"node_instance\": { \"id\": \"123\" } }").withStatus(HttpStatus.SC_OK)));
86 int port = wireMockRule.port();
88 Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
89 NodeInstancesResource nir = c.nodeInstances();
90 UpdateNodeInstanceParams params = new UpdateNodeInstanceParams();
92 UpdateNodeInstance uni = nir.update("123", params);
93 thrown.expect(HttpClientException.class); /// ???????
94 NodeInstance ni = uni.execute();