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