]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17210 - upload scanning alerts to GitHub
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Wed, 24 Aug 2022 15:46:58 +0000 (17:46 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 30 Aug 2022 20:03:14 +0000 (20:03 +0000)
server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java

index c0a43d6c57fab177fb44b4fc7ac1b92d386a13f3..a716055aee1c20f6eeab86110494bc9fbd0ce3ab 100644 (file)
@@ -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);
index 0552666bba9e23a14fe4da6e5b4cd5ad71f51477..64ceedb12127df506065e0adfdfd656a10dfb4f6 100644 (file)
@@ -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);