Replaced all tabs with spaces in java and pom.xml
[so.git] / cloudify-client / src / test / java / org / onap / so / cloudify / v3 / client / NodeInstancesResourceTest.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.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;
41
42 public class NodeInstancesResourceTest {
43     @Rule
44     public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
45
46     @Rule
47     public ExpectedException thrown = ExpectedException.none();
48
49     @Test
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)));
54
55         int port = wireMockRule.port();
56
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());
62     }
63
64     @Test
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)));
70
71         int port = wireMockRule.port();
72
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());
78     }
79
80     @Test
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)));
85
86         int port = wireMockRule.port();
87
88         Cloudify c = new Cloudify("http://localhost:" + port, "tenant");
89         NodeInstancesResource nir = c.nodeInstances();
90         UpdateNodeInstanceParams params = new UpdateNodeInstanceParams();
91
92         UpdateNodeInstance uni = nir.update("123", params);
93         thrown.expect(HttpClientException.class); /// ???????
94         NodeInstance ni = uni.execute();
95     }
96 }