2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 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.client.sniro;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27 import org.junit.Test;
28 import org.onap.so.BaseIntegrationTest;
29 import org.onap.so.client.exception.BadResponseException;
30 import org.onap.so.client.sniro.beans.SniroConductorRequest;
31 import org.onap.so.client.sniro.beans.SniroManagerRequest;
32 import org.springframework.beans.factory.annotation.Autowired;
34 import com.fasterxml.jackson.core.JsonProcessingException;
37 public class SniroClientTestIT extends BaseIntegrationTest {
40 private SniroClient client;
43 @Test(expected = Test.None.class)
44 public void testPostDemands_success() throws BadResponseException, JsonProcessingException {
45 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
47 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
48 .willReturn(aResponse().withStatus(200)
49 .withHeader("Content-Type", "application/json")
50 .withBody(mockResponse)));
52 client.postDemands(new SniroManagerRequest());
56 @Test(expected = BadResponseException.class)
57 public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException {
58 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}";
60 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
61 .willReturn(aResponse().withStatus(200)
62 .withHeader("Content-Type", "application/json")
63 .withBody(mockResponse)));
66 client.postDemands(new SniroManagerRequest());
68 //TODO assertEquals("missing data", );
72 @Test(expected = BadResponseException.class)
73 public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
74 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
76 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
77 .willReturn(aResponse().withStatus(200)
78 .withHeader("Content-Type", "application/json")
79 .withBody(mockResponse)));
82 client.postDemands(new SniroManagerRequest());
86 @Test(expected = BadResponseException.class)
87 public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException {
88 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}";
90 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
91 .willReturn(aResponse().withStatus(200)
92 .withHeader("Content-Type", "application/json")
93 .withBody(mockResponse)));
96 client.postDemands(new SniroManagerRequest());
100 @Test(expected = BadResponseException.class)
101 public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
102 String mockResponse = "{ }";
104 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
105 .willReturn(aResponse().withStatus(200)
106 .withHeader("Content-Type", "application/json")
107 .withBody(mockResponse)));
110 client.postDemands(new SniroManagerRequest());
113 @Test(expected = Test.None.class)
114 public void testPostRelease_success() throws BadResponseException, JsonProcessingException {
115 String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}";
117 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
118 .willReturn(aResponse().withStatus(200)
119 .withHeader("Content-Type", "application/json")
120 .withBody(mockResponse)));
122 client.postRelease(new SniroConductorRequest());
125 @Test(expected = BadResponseException.class)
126 public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException {
127 String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}";
129 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
130 .willReturn(aResponse().withStatus(200)
131 .withHeader("Content-Type", "application/json")
132 .withBody(mockResponse)));
134 client.postRelease(new SniroConductorRequest());
137 @Test(expected = BadResponseException.class)
138 public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException {
139 String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}";
141 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
142 .willReturn(aResponse().withStatus(200)
143 .withHeader("Content-Type", "application/json")
144 .withBody(mockResponse)));
146 client.postRelease(new SniroConductorRequest());
150 @Test(expected = BadResponseException.class)
151 public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException {
152 String mockResponse = "{\"status\": \"failure\", \"message\": null}";
154 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
155 .willReturn(aResponse().withStatus(200)
156 .withHeader("Content-Type", "application/json")
157 .withBody(mockResponse)));
159 client.postRelease(new SniroConductorRequest());
163 @Test(expected = BadResponseException.class)
164 public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException {
165 String mockResponse = "{ }";
167 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
168 .willReturn(aResponse().withStatus(200)
169 .withHeader("Content-Type", "application/json")
170 .withBody(mockResponse)));
172 client.postRelease(new SniroConductorRequest());