2 * ============LICENSE_START=======================================================
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
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.oof;
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;
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;
33 import com.fasterxml.jackson.core.JsonProcessingException;
36 public class OofClientTestIT extends BaseIntegrationTest {
39 private OofClient client;
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\"}";
46 wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
47 .willReturn(aResponse().withStatus(200)
48 .withHeader("Content-Type", "application/json")
49 .withBody(mockResponse)));
51 client.postDemands(new OofRequest());
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\"}";
58 wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
59 .willReturn(aResponse().withStatus(200)
60 .withHeader("Content-Type", "application/json")
61 .withBody(mockResponse)));
63 client.postDemands(new OofRequest());
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\"}";
70 wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
71 .willReturn(aResponse().withStatus(200)
72 .withHeader("Content-Type", "application/json")
73 .withBody(mockResponse)));
76 client.postDemands(new OofRequest());
78 //TODO assertEquals("missing data", );
82 @Test(expected = BadResponseException.class)
83 public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException {
84 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
86 wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
87 .willReturn(aResponse().withStatus(200)
88 .withHeader("Content-Type", "application/json")
89 .withBody(mockResponse)));
92 client.postDemands(new OofRequest());
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}";
100 wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
101 .willReturn(aResponse().withStatus(200)
102 .withHeader("Content-Type", "application/json")
103 .withBody(mockResponse)));
106 client.postDemands(new OofRequest());
110 @Test(expected = BadResponseException.class)
111 public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
112 String mockResponse = "{ }";
114 wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement"))
115 .willReturn(aResponse().withStatus(200)
116 .withHeader("Content-Type", "application/json")
117 .withBody(mockResponse)));
120 client.postDemands(new OofRequest());