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.BaseIntegrationTest;
28 import org.onap.so.client.exception.BadResponseException;
29 import org.onap.so.client.sniro.beans.SniroConductorRequest;
30 import org.onap.so.client.sniro.beans.SniroManagerRequest;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import com.fasterxml.jackson.core.JsonProcessingException;
35 public class SniroClientTestIT extends BaseIntegrationTest {
38 private SniroClient client;
41 @Test(expected = Test.None.class)
42 public void testPostDemands_success() throws BadResponseException, JsonProcessingException {
44 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
46 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
47 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
49 client.postDemands(new SniroManagerRequest());
53 @Test(expected = BadResponseException.class)
54 public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException {
56 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}";
58 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
59 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
62 client.postDemands(new SniroManagerRequest());
64 // TODO assertEquals("missing data", );
68 @Test(expected = BadResponseException.class)
69 public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
71 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
73 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
74 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
77 client.postDemands(new SniroManagerRequest());
81 @Test(expected = BadResponseException.class)
82 public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException {
84 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}";
86 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
87 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
90 client.postDemands(new SniroManagerRequest());
94 @Test(expected = BadResponseException.class)
95 public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
96 String mockResponse = "{ }";
98 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
99 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
102 client.postDemands(new SniroManagerRequest());
105 @Test(expected = Test.None.class)
106 public void testPostRelease_success() throws BadResponseException, JsonProcessingException {
107 String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}";
109 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
110 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
112 client.postRelease(new SniroConductorRequest());
115 @Test(expected = BadResponseException.class)
116 public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException {
117 String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}";
119 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
120 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
122 client.postRelease(new SniroConductorRequest());
125 @Test(expected = BadResponseException.class)
126 public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException {
127 String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}";
129 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
130 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
132 client.postRelease(new SniroConductorRequest());
136 @Test(expected = BadResponseException.class)
137 public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException {
138 String mockResponse = "{\"status\": \"failure\", \"message\": null}";
140 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
141 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
143 client.postRelease(new SniroConductorRequest());
147 @Test(expected = BadResponseException.class)
148 public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException {
149 String mockResponse = "{ }";
151 wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
152 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
154 client.postRelease(new SniroConductorRequest());