]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13427 implement ITs
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Tue, 16 Nov 2021 14:19:28 +0000 (15:19 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 16 Nov 2021 20:03:55 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectBadgeTokenDao.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/ProjectBadgesSupport.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/MeasureRequest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/ProjectBadgesService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/QualityGateRequest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/RenewTokenRequest.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/TokenRequest.java [new file with mode: 0644]

index 9565bf0a0a7666cfaa83e5d7ad2a25c11d6f64d2..8a6a00d1eda01b9b962892b60f922c7ae963a1d3 100644 (file)
@@ -65,5 +65,6 @@ public class ProjectBadgeTokenDao implements Dao {
   @CheckForNull
   public ProjectBadgeTokenDto selectTokenByProject(DbSession session, ProjectDto projectDto) {
     return mapper(session).selectTokenByProjectUuid(projectDto.getUuid());
+
   }
 }
index 981f8a7b94785db40e714223b8243b42d73c297b..405cdef4dcadd4fa91ac4567454f6fa5fdf67ac0 100644 (file)
@@ -40,6 +40,7 @@ public class ProjectBadgesSupport {
   private static final String PARAM_PROJECT = "project";
   private static final String PARAM_BRANCH = "branch";
   private static final String PARAM_TOKEN = "token";
+  public static final String PROJECT_HAS_NOT_BEEN_FOUND = "Project has not been found";
 
   private final ComponentFinder componentFinder;
   private final DbClient dbClient;
@@ -83,7 +84,7 @@ public class ProjectBadgesSupport {
 
       return branch;
     } catch (NotFoundException e) {
-      throw new NotFoundException("Project has not been found");
+      throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND);
     }
   }
 
@@ -98,11 +99,11 @@ public class ProjectBadgesSupport {
       try {
         projectDto = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
       } catch (NotFoundException e) {
-        throw new NotFoundException("Project has not been found");
+        throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND);
       }
       String token = request.param(PARAM_TOKEN);
       if (projectDto.isPrivate() && !isTokenValid(dbSession, projectDto, token)) {
-        throw generateInvalidProjectException();
+        throw new NotFoundException(PROJECT_HAS_NOT_BEEN_FOUND);
       }
     }
   }
index e4e55bf1da3309d65e8dbfc7cd89e0a394b1bc80..e319a912e71475f3b0f61e48a7b0e0015b3e9b68 100644 (file)
@@ -329,7 +329,7 @@ public class MeasureActionTest {
       .setParam("metric", metric.getKey())
       .execute();
 
-    checkError(response, "Project is invalid");
+    checkError(response, "Project has not been found");
   }
 
   @Test
index f139f890bf01889b81d7aa2d67f8e13d79645926..29fc9c9d4d2bfaeac9260eedc1fb4995a75b6c91 100644 (file)
@@ -197,7 +197,7 @@ public class QualityGateActionTest {
       .setParam("project", project.getKey())
       .execute();
 
-    checkError(response, "Project is invalid");
+    checkError(response, "Project has not been found");
   }
 
   @Test
index 6d08e716944573d7cd4537c16d5511d421abac54..ddecb76a2457fa79c5f2ffb5ec5632d2e11298bf 100644 (file)
@@ -33,6 +33,7 @@ public class MeasureRequest {
   private String branch;
   private String metric;
   private String project;
+  private String token;
 
   /**
    * Example value: "feature/my_branch"
@@ -84,4 +85,16 @@ public class MeasureRequest {
   public String getProject() {
     return project;
   }
+
+  /**
+   * Tthis an optional parameter.
+   */
+  public MeasureRequest setToken(String token) {
+    this.token = token;
+    return this;
+  }
+
+  public String getToken() {
+    return token;
+  }
 }
index 393a0355dcffe86fba6a5dcfbce5ddd78b9e79eb..f06083b0d5cd2049330ac79e1c319f8cd8cccf86 100644 (file)
@@ -21,9 +21,12 @@ package org.sonarqube.ws.client.projectbadges;
 
 import javax.annotation.Generated;
 import org.sonarqube.ws.MediaTypes;
+import org.sonarqube.ws.ProjectBadgeToken.TokenWsResponse;
 import org.sonarqube.ws.client.BaseService;
 import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.WsConnector;
+import org.sonarqube.ws.client.WsResponse;
 
 /**
  * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges">Further information about this web service online</a>
@@ -48,6 +51,7 @@ public class ProjectBadgesService extends BaseService {
         .setParam("branch", request.getBranch())
         .setParam("metric", request.getMetric())
         .setParam("project", request.getProject())
+        .setParam("token", request.getToken())
         .setMediaType(MediaTypes.JSON)
       ).content();
   }
@@ -64,7 +68,35 @@ public class ProjectBadgesService extends BaseService {
       new GetRequest(path("quality_gate"))
         .setParam("branch", request.getBranch())
         .setParam("project", request.getProject())
+        .setParam("token", request.getToken())
         .setMediaType(MediaTypes.JSON)
       ).content();
   }
+
+  /**
+   *
+   * This is part of the internal API.
+   * This is a GET request.
+   * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges/token">Further information about this action online (including a response example)</a>
+   * @since 9.2
+   * @return
+   */
+  public TokenWsResponse token(TokenRequest request) {
+    return call(
+      new GetRequest(path("token"))
+        .setParam("project", request.getProject())
+        .setMediaType(MediaTypes.JSON),
+      TokenWsResponse.parser()
+    );
+  }
+
+
+  public WsResponse renewToken(RenewTokenRequest request) {
+    return call(
+      new PostRequest(path("renew_token"))
+        .setParam("project", request.getProject())
+        .setMediaType(MediaTypes.JSON)
+    );
+
+  }
 }
index dc3e47f78d9269e505a8dcdeeff44a0d3c9ca898..d345552ba55253611b006e927e129c5da91c241b 100644 (file)
@@ -32,6 +32,7 @@ public class QualityGateRequest {
 
   private String branch;
   private String project;
+  private String token;
 
   /**
    * Example value: "feature/my_branch"
@@ -57,4 +58,16 @@ public class QualityGateRequest {
   public String getProject() {
     return project;
   }
+
+  /**
+   * This is aan optional parameter.
+   */
+  public QualityGateRequest setToken(String token) {
+    this.token = token;
+    return this;
+  }
+
+  public String getToken() {
+    return token;
+  }
 }
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/RenewTokenRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/RenewTokenRequest.java
new file mode 100644 (file)
index 0000000..8a8e86b
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.ws.client.projectbadges;
+
+import javax.annotation.Generated;
+
+/**
+ * This is part of the internal API.
+ * This is a POST request.
+ * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges/renew_token">Further information about this action online (including a response example)</a>
+ * @since 9.2
+ */
+@Generated("sonar-ws-generator")
+public class RenewTokenRequest {
+
+  private String project;
+
+  /**
+   * This is a mandatory parameter.
+   * Example value: "my_project"
+   */
+  public RenewTokenRequest setProject(String project) {
+    this.project = project;
+    return this;
+  }
+
+  public String getProject() {
+    return project;
+  }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/TokenRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectbadges/TokenRequest.java
new file mode 100644 (file)
index 0000000..7054f2f
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.ws.client.projectbadges;
+
+import javax.annotation.Generated;
+
+/**
+ * This is part of the internal API.
+ * This is a GET request.
+ * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/project_badges/token">Further information about this action online (including a response example)</a>
+ * @since 9.2
+ */
+@Generated("sonar-ws-generator")
+public class TokenRequest {
+
+  private String project;
+
+  /**
+   * This is a mandatory parameter.
+   * Example value: "my_project"
+   */
+  public TokenRequest setProject(String project) {
+    this.project = project;
+    return this;
+  }
+
+  public String getProject() {
+    return project;
+  }
+}