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;
26 import org.junit.Test;
27 import org.onap.so.client.exception.BadResponseException;
28 import org.onap.so.client.sniro.beans.SniroConductorRequest;
29 import org.onap.so.client.sniro.beans.SniroManagerRequest;
30 import org.springframework.beans.factory.annotation.Autowired;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import static com.github.tomakehurst.wiremock.client.WireMock.*;
36 public class SniroClientTestIT{
39 private SniroClient client;
42 @Test(expected = Test.None.class)
43 public void testPostDemands_success() throws BadResponseException, JsonProcessingException {
44 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
46 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
47 .willReturn(aResponse().withStatus(200)
48 .withHeader("Content-Type", "application/json")
49 .withBody(mockResponse)));
51 client.postDemands(new SniroManagerRequest());
55 @Test(expected = BadResponseException.class)
56 public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException {
57 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}";
59 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
60 .willReturn(aResponse().withStatus(200)
61 .withHeader("Content-Type", "application/json")
62 .withBody(mockResponse)));
65 client.postDemands(new SniroManagerRequest());
67 //TODO assertEquals("missing data", );
71 @Test(expected = BadResponseException.class)
72 public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
73 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
75 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
76 .willReturn(aResponse().withStatus(200)
77 .withHeader("Content-Type", "application/json")
78 .withBody(mockResponse)));
81 client.postDemands(new SniroManagerRequest());
85 @Test(expected = BadResponseException.class)
86 public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException {
87 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}";
89 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
90 .willReturn(aResponse().withStatus(200)
91 .withHeader("Content-Type", "application/json")
92 .withBody(mockResponse)));
95 client.postDemands(new SniroManagerRequest());
99 @Test(expected = BadResponseException.class)
100 public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
101 String mockResponse = "{ }";
103 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
104 .willReturn(aResponse().withStatus(200)
105 .withHeader("Content-Type", "application/json")
106 .withBody(mockResponse)));
109 client.postDemands(new SniroManagerRequest());
112 @Test(expected = Test.None.class)
113 public void testPostRelease_success() throws BadResponseException, JsonProcessingException {
114 String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}";
116 stubFor(post(urlEqualTo("/v1/release-orders"))
117 .willReturn(aResponse().withStatus(200)
118 .withHeader("Content-Type", "application/json")
119 .withBody(mockResponse)));
121 client.postRelease(new SniroConductorRequest());
124 @Test(expected = BadResponseException.class)
125 public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException {
126 String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}";
128 stubFor(post(urlEqualTo("/v1/release-orders"))
129 .willReturn(aResponse().withStatus(200)
130 .withHeader("Content-Type", "application/json")
131 .withBody(mockResponse)));
133 client.postRelease(new SniroConductorRequest());
136 @Test(expected = BadResponseException.class)
137 public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException {
138 String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}";
140 stubFor(post(urlEqualTo("/v1/release-orders"))
141 .willReturn(aResponse().withStatus(200)
142 .withHeader("Content-Type", "application/json")
143 .withBody(mockResponse)));
145 client.postRelease(new SniroConductorRequest());
149 @Test(expected = BadResponseException.class)
150 public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException {
151 String mockResponse = "{\"status\": \"failure\", \"message\": null}";
153 stubFor(post(urlEqualTo("/v1/release-orders"))
154 .willReturn(aResponse().withStatus(200)
155 .withHeader("Content-Type", "application/json")
156 .withBody(mockResponse)));
158 client.postRelease(new SniroConductorRequest());
162 @Test(expected = BadResponseException.class)
163 public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException {
164 String mockResponse = "{ }";
166 stubFor(post(urlEqualTo("/v1/release-orders"))
167 .willReturn(aResponse().withStatus(200)
168 .withHeader("Content-Type", "application/json")
169 .withBody(mockResponse)));
171 client.postRelease(new SniroConductorRequest());