aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-09-27 13:55:11 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-10-03 15:23:29 +0200
commit3ee70a85b0289d1b2246572d32d9edf2d8dbfb54 (patch)
treef9f8c5c9d3aea41edbc84eda71e3be07a32b7433 /server
parent51292592677363b43e1e7840f5a79aa2a51f7463 (diff)
downloadsonarqube-3ee70a85b0289d1b2246572d32d9edf2d8dbfb54.tar.gz
sonarqube-3ee70a85b0289d1b2246572d32d9edf2d8dbfb54.zip
SONAR-7956 remove obsolete gateId parameter of api/qualitygates/deselect
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java15
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java68
3 files changed, 51 insertions, 36 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
index b916e587b17..085db85ca0b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
@@ -44,7 +44,6 @@ import org.sonar.server.user.UserSession;
import org.sonar.server.util.Validation;
import static java.lang.String.format;
-import static org.sonar.core.permission.GlobalPermissions.QUALITY_GATE_ADMIN;
import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
import static org.sonar.server.ws.WsUtils.checkRequest;
@@ -179,8 +178,7 @@ public class QualityGates {
}
}
- public void dissociateProject(DbSession dbSession, Long qGateId, ComponentDto project) {
- getNonNullQgate(qGateId);
+ public void dissociateProject(DbSession dbSession, ComponentDto project) {
checkProjectAdmin(project);
propertiesDao.deleteProjectProperty(SONAR_QUALITYGATE_PROPERTY, project.getId(), dbSession);
dbSession.commit();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
index 088125fc196..332afc796df 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
@@ -21,6 +21,7 @@ package org.sonar.server.qualitygate.ws;
import com.google.common.base.Optional;
import javax.annotation.Nullable;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -30,7 +31,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.qualitygate.QualityGates;
-import org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_ID;
@@ -54,15 +54,12 @@ public class DeselectAction implements QualityGatesWsAction {
.setDescription("Remove the association of a project from a quality gate. Require Administer Quality Gates permission")
.setPost(true)
.setSince("4.3")
- .setHandler(this);
-
- action.createParam(QualityGatesWsParameters.PARAM_GATE_ID)
- .setDescription("Quality Gate id")
- .setRequired(true)
- .setExampleValue("23");
+ .setHandler(this)
+ .setChangelog(new Change("6.6", "The parameter 'gateId' was removed"));
action.createParam(PARAM_PROJECT_ID)
- .setDescription("Project id. Project id as an numeric value is deprecated since 6.1")
+ .setDescription("Project id")
+ .setDeprecatedSince("6.1")
.setExampleValue(Uuids.UUID_EXAMPLE_01);
action.createParam(PARAM_PROJECT_KEY)
@@ -75,7 +72,7 @@ public class DeselectAction implements QualityGatesWsAction {
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = getProject(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY));
- qualityGates.dissociateProject(dbSession, QualityGatesWs.parseId(request, QualityGatesWsParameters.PARAM_GATE_ID), project);
+ qualityGates.dissociateProject(dbSession, project);
response.noContent();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
index 753cd1531b2..49ae302197d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
@@ -24,6 +24,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.measures.MetricFinder;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
@@ -43,6 +45,7 @@ import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
import static org.sonar.server.qualitygate.QualityGates.SONAR_QUALITYGATE_PROPERTY;
@@ -75,6 +78,33 @@ public class DeselectActionTest {
}
@Test
+ public void definition() {
+ WebService.Action def = ws.getDef();
+
+ assertThat(def.description()).isNotEmpty();
+ assertThat(def.isPost()).isTrue();
+ assertThat(def.since()).isEqualTo("4.3");
+ assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactly(
+ tuple("6.6", "The parameter 'gateId' was removed")
+ );
+
+ assertThat(def.params()).extracting(WebService.Param::key)
+ .containsExactlyInAnyOrder("projectId", "projectKey");
+
+ WebService.Param projectId = def.param("projectId");
+ assertThat(projectId.isRequired()).isFalse();
+ assertThat(projectId.deprecatedSince()).isEqualTo("6.1");
+ assertThat(projectId.description()).isNotEmpty();
+ assertThat(projectId.exampleValue()).isNotEmpty();
+
+ WebService.Param projectKey = def.param("projectKey");
+ assertThat(projectKey.isRequired()).isFalse();
+ assertThat(projectKey.since()).isEqualTo("6.1");
+ assertThat(projectKey.description()).isNotEmpty();
+ assertThat(projectKey.exampleValue()).isNotEmpty();
+ }
+
+ @Test
public void deselect_by_id() throws Exception {
logInAsRoot();
@@ -83,7 +113,7 @@ public class DeselectActionTest {
associateProjectToQualityGate(project.getId(), gateId);
associateProjectToQualityGate(anotherProject.getId(), gateId);
- callById(gateId, project.getId());
+ callById(project.getId());
assertDeselected(project.getId());
assertSelected(gateId, anotherProject.getId());
@@ -96,7 +126,7 @@ public class DeselectActionTest {
String gateId = String.valueOf(gate.getId());
associateProjectToQualityGate(project.getId(), gateId);
- callByUuid(gateId, project.uuid());
+ callByUuid(project.uuid());
assertDeselected(project.getId());
}
@@ -108,7 +138,7 @@ public class DeselectActionTest {
String gateId = String.valueOf(gate.getId());
associateProjectToQualityGate(project.getId(), gateId);
- callByKey(gateId, project.getDbKey());
+ callByKey(project.getDbKey());
assertDeselected(project.getId());
}
@@ -120,25 +150,18 @@ public class DeselectActionTest {
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
- callByKey(gateId, project.getDbKey());
+ callByKey(project.getDbKey());
assertDeselected(project.getId());
}
@Test
- public void fail_when_no_quality_gate() throws Exception {
- expectedException.expect(NotFoundException.class);
-
- callByKey("-1", project.getDbKey());
- }
-
- @Test
public void fail_when_no_project_id() throws Exception {
String gateId = String.valueOf(gate.getId());
expectedException.expect(NotFoundException.class);
- callById(gateId, 1L);
+ callById(1L);
}
@Test
@@ -147,7 +170,7 @@ public class DeselectActionTest {
expectedException.expect(NotFoundException.class);
- callByKey(gateId, "unknown");
+ callByKey("unknown");
}
@Test
@@ -156,7 +179,7 @@ public class DeselectActionTest {
userSession.anonymous();
expectedException.expect(ForbiddenException.class);
- callByKey(gateId, project.getDbKey());
+ callByKey(project.getDbKey());
}
@Test
@@ -167,7 +190,7 @@ public class DeselectActionTest {
expectedException.expect(ForbiddenException.class);
- callByKey(gateId, project.getDbKey());
+ callByKey(project.getDbKey());
}
@Test
@@ -178,7 +201,7 @@ public class DeselectActionTest {
expectedException.expect(ForbiddenException.class);
- callByKey(gateId, project.getDbKey());
+ callByKey(project.getDbKey());
}
@Test
@@ -192,7 +215,7 @@ public class DeselectActionTest {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey()));
- callByKey(gateId, branch.getDbKey());
+ callByKey(branch.getDbKey());
}
@Test
@@ -206,7 +229,7 @@ public class DeselectActionTest {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(format("Component id '%s' not found", branch.uuid()));
- callByUuid(gateId, branch.uuid());
+ callByUuid(branch.uuid());
}
private QualityGateDto insertQualityGate() {
@@ -216,23 +239,20 @@ public class DeselectActionTest {
return gate;
}
- private void callByKey(String gateId, String projectKey) {
+ private void callByKey(String projectKey) {
ws.newRequest()
- .setParam("gateId", String.valueOf(gateId))
.setParam("projectKey", projectKey)
.execute();
}
- private void callById(String gateId, Long projectId) {
+ private void callById(Long projectId) {
ws.newRequest()
- .setParam("gateId", String.valueOf(gateId))
.setParam("projectId", String.valueOf(projectId))
.execute();
}
- private void callByUuid(String gateId, String projectUuid) {
+ private void callByUuid(String projectUuid) {
ws.newRequest()
- .setParam("gateId", String.valueOf(gateId))
.setParam("projectId", projectUuid)
.execute();
}