From 914890e41cb7131886143a74acd8c4e5f27ec97a Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Wed, 24 Aug 2022 17:46:58 +0200 Subject: [PATCH] SONAR-17210 - upload scanning alerts to GitHub --- .../github/GithubApplicationHttpClientImpl.java | 3 ++- .../GithubApplicationHttpClientImplTest.java | 14 +++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java index c0a43d6c57f..a716055aee1 100644 --- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java +++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java @@ -40,6 +40,7 @@ import org.sonar.api.utils.log.Loggers; 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; @@ -128,7 +129,7 @@ public class GithubApplicationHttpClientImpl implements GithubApplicationHttpCli 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); diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java index 0552666bba9..64ceedb1212 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java @@ -235,17 +235,9 @@ public class GithubApplicationHttpClientImplTest { } @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); -- 2.39.5