Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sniro / SniroClientTestIT.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.client.sniro;
22
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;
33
34
35 public class SniroClientTestIT extends BaseIntegrationTest {
36
37     @Autowired
38     private SniroClient client;
39
40
41     @Test(expected = Test.None.class)
42     public void testPostDemands_success() throws BadResponseException, JsonProcessingException {
43         String mockResponse =
44                 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
45
46         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
47                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
48
49         client.postDemands(new SniroManagerRequest());
50
51     }
52
53     @Test(expected = BadResponseException.class)
54     public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException {
55         String mockResponse =
56                 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}";
57
58         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
59                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
60
61
62         client.postDemands(new SniroManagerRequest());
63
64         // TODO assertEquals("missing data", );
65
66     }
67
68     @Test(expected = BadResponseException.class)
69     public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
70         String mockResponse =
71                 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
72
73         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
74                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
75
76
77         client.postDemands(new SniroManagerRequest());
78
79     }
80
81     @Test(expected = BadResponseException.class)
82     public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException {
83         String mockResponse =
84                 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}";
85
86         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
87                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
88
89
90         client.postDemands(new SniroManagerRequest());
91
92     }
93
94     @Test(expected = BadResponseException.class)
95     public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
96         String mockResponse = "{ }";
97
98         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
99                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
100
101
102         client.postDemands(new SniroManagerRequest());
103     }
104
105     @Test(expected = Test.None.class)
106     public void testPostRelease_success() throws BadResponseException, JsonProcessingException {
107         String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}";
108
109         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
110                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
111
112         client.postRelease(new SniroConductorRequest());
113     }
114
115     @Test(expected = BadResponseException.class)
116     public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException {
117         String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}";
118
119         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
120                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
121
122         client.postRelease(new SniroConductorRequest());
123     }
124
125     @Test(expected = BadResponseException.class)
126     public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException {
127         String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}";
128
129         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
130                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
131
132         client.postRelease(new SniroConductorRequest());
133
134     }
135
136     @Test(expected = BadResponseException.class)
137     public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException {
138         String mockResponse = "{\"status\": \"failure\", \"message\": null}";
139
140         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
141                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
142
143         client.postRelease(new SniroConductorRequest());
144
145     }
146
147     @Test(expected = BadResponseException.class)
148     public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException {
149         String mockResponse = "{ }";
150
151         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn(
152                 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
153
154         client.postRelease(new SniroConductorRequest());
155
156     }
157
158 }