replace all fixed wiremock ports
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / oof / OofClientTestIT.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Intel Corp. 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.oof;
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.oof.beans.OofRequest;
31 import org.springframework.beans.factory.annotation.Autowired;
32
33 import com.fasterxml.jackson.core.JsonProcessingException;
34
35
36 public class OofClientTestIT extends BaseIntegrationTest {
37
38     @Autowired
39     private OofClient 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\": \"status\", \"requestStatus\": \"accepted\"}";
45
46         wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
47                 .willReturn(aResponse().withStatus(200)
48                         .withHeader("Content-Type", "application/json")
49                         .withBody(mockResponse)));
50
51         client.postDemands(new OofRequest());
52     }
53
54     @Test(expected = Test.None.class)
55     public void testAsyncResponse_success() throws BadResponseException, JsonProcessingException {
56         String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}";
57
58         wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
59                 .willReturn(aResponse().withStatus(200)
60                         .withHeader("Content-Type", "application/json")
61                         .withBody(mockResponse)));
62
63         client.postDemands(new OofRequest());
64     }
65
66     @Test(expected = BadResponseException.class)
67     public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException {
68         String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}";
69
70         wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
71                 .willReturn(aResponse().withStatus(200)
72                         .withHeader("Content-Type", "application/json")
73                         .withBody(mockResponse)));
74
75
76         client.postDemands(new OofRequest());
77
78         //TODO  assertEquals("missing data", );
79
80     }
81
82     @Test(expected = BadResponseException.class)
83     public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
84         String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
85
86         wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
87                 .willReturn(aResponse().withStatus(200)
88                         .withHeader("Content-Type", "application/json")
89                         .withBody(mockResponse)));
90
91
92         client.postDemands(new OofRequest());
93
94     }
95
96     @Test(expected = BadResponseException.class)
97     public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException {
98         String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}";
99
100         wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
101                 .willReturn(aResponse().withStatus(200)
102                         .withHeader("Content-Type", "application/json")
103                         .withBody(mockResponse)));
104
105
106         client.postDemands(new OofRequest());
107
108     }
109
110     @Test(expected = BadResponseException.class)
111     public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
112         String mockResponse = "{ }";
113
114         wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
115                 .willReturn(aResponse().withStatus(200)
116                         .withHeader("Content-Type", "application/json")
117                         .withBody(mockResponse)));
118
119
120         client.postDemands(new OofRequest());
121     }
122
123 }