import org.sonarqube.ws.client.OkHttpClientBuilder;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.net.HttpURLConnection.HTTP_ACCEPTED;
import static java.net.HttpURLConnection.HTTP_CREATED;
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static java.net.HttpURLConnection.HTTP_OK;
try (okhttp3.Response response = client.newCall(newPostRequest(appUrl, token, endPoint, body)).execute()) {
int responseCode = response.code();
- if (responseCode == HTTP_OK || responseCode == HTTP_CREATED) {
+ if (responseCode == HTTP_OK || responseCode == HTTP_CREATED || responseCode == HTTP_ACCEPTED) {
return new ResponseImpl(responseCode, readContent(response.body()).orElse(null));
} else if (responseCode == HTTP_NO_CONTENT) {
return new ResponseImpl(responseCode, null);
}
@Test
- public void post_returns_body_as_response_if_code_is_200() throws IOException {
- server.enqueue(new MockResponse().setResponseCode(200).setBody(randomBody));
-
- Response response = underTest.post(appUrl, accessToken, randomEndPoint);
-
- assertThat(response.getContent()).contains(randomBody);
- }
-
- @Test
- public void post_returns_body_as_response_if_code_is_201() throws IOException {
- server.enqueue(new MockResponse().setResponseCode(201).setBody(randomBody));
+ @DataProvider({"200", "201", "202"})
+ public void post_returns_body_as_response_if_success(int code) throws IOException {
+ server.enqueue(new MockResponse().setResponseCode(code).setBody(randomBody));
Response response = underTest.post(appUrl, accessToken, randomEndPoint);