replace all fixed wiremock ports
[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
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;
33
34 import com.fasterxml.jackson.core.JsonProcessingException;
35
36
37 public class SniroClientTestIT extends BaseIntegrationTest {
38
39     @Autowired
40     private SniroClient client;
41
42
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\"}";
46
47         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
48                                 .willReturn(aResponse().withStatus(200)
49                     .withHeader("Content-Type", "application/json")
50                     .withBody(mockResponse)));
51
52           client.postDemands(new SniroManagerRequest());
53
54     }
55
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\"}";
59
60         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
61                         .willReturn(aResponse().withStatus(200)
62                                         .withHeader("Content-Type", "application/json")
63                                         .withBody(mockResponse)));
64
65
66         client.postDemands(new SniroManagerRequest());
67
68         //TODO  assertEquals("missing data", );
69
70     }
71
72     @Test(expected = BadResponseException.class)
73     public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
74         String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
75
76         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
77                         .willReturn(aResponse().withStatus(200)
78                                         .withHeader("Content-Type", "application/json")
79                                         .withBody(mockResponse)));
80
81
82         client.postDemands(new SniroManagerRequest());
83
84     }
85
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}";
89
90         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
91                         .willReturn(aResponse().withStatus(200)
92                                         .withHeader("Content-Type", "application/json")
93                                         .withBody(mockResponse)));
94
95
96         client.postDemands(new SniroManagerRequest());
97
98     }
99
100     @Test(expected = BadResponseException.class)
101     public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
102         String mockResponse = "{ }";
103
104         wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
105                         .willReturn(aResponse().withStatus(200)
106                                         .withHeader("Content-Type", "application/json")
107                                         .withBody(mockResponse)));
108
109
110         client.postDemands(new SniroManagerRequest());
111     }
112
113     @Test(expected = Test.None.class)
114     public void testPostRelease_success() throws BadResponseException, JsonProcessingException {
115         String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}";
116
117         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
118                                 .willReturn(aResponse().withStatus(200)
119                     .withHeader("Content-Type", "application/json")
120                     .withBody(mockResponse)));
121
122           client.postRelease(new SniroConductorRequest());
123     }
124
125     @Test(expected = BadResponseException.class)
126     public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException {
127         String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}";
128
129         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
130                                 .willReturn(aResponse().withStatus(200)
131                     .withHeader("Content-Type", "application/json")
132                     .withBody(mockResponse)));
133
134           client.postRelease(new SniroConductorRequest());
135     }
136
137     @Test(expected = BadResponseException.class)
138     public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException {
139         String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}";
140
141         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
142                                 .willReturn(aResponse().withStatus(200)
143                     .withHeader("Content-Type", "application/json")
144                     .withBody(mockResponse)));
145
146           client.postRelease(new SniroConductorRequest());
147
148     }
149
150     @Test(expected = BadResponseException.class)
151     public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException {
152         String mockResponse = "{\"status\": \"failure\", \"message\": null}";
153
154         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
155                                 .willReturn(aResponse().withStatus(200)
156                     .withHeader("Content-Type", "application/json")
157                     .withBody(mockResponse)));
158
159           client.postRelease(new SniroConductorRequest());
160
161     }
162
163     @Test(expected = BadResponseException.class)
164     public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException {
165         String mockResponse = "{ }";
166
167         wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders"))
168                                 .willReturn(aResponse().withStatus(200)
169                     .withHeader("Content-Type", "application/json")
170                     .withBody(mockResponse)));
171
172           client.postRelease(new SniroConductorRequest());
173
174     }
175
176 }