diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-11-23 16:14:40 +0100 |
---|---|---|
committer | Daniel Schwarz <bartfastiel@users.noreply.github.com> | 2017-11-29 20:24:11 +0100 |
commit | a1629c2cc959c72932c0d483457005de8dc55ad0 (patch) | |
tree | 3b597c09b845d582f71f9ef8ef05db1883faae0b | |
parent | b8d9ebc1a94519ab3a0f285945c894b31de05c9a (diff) | |
download | sonarqube-a1629c2cc959c72932c0d483457005de8dc55ad0.tar.gz sonarqube-a1629c2cc959c72932c0d483457005de8dc55ad0.zip |
Generate client of api/qualitygates and api/roots
43 files changed, 232 insertions, 349 deletions
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java index 5db54abe49f..66ef0f036db 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.sonarqube.ws.Projects.CreateWsResponse.Project; -import org.sonarqube.ws.Qualitygates.CreateWsResponse; +import org.sonarqube.ws.Qualitygates; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.qualitygates.CreateRequest; @@ -53,12 +53,12 @@ public class QGateTester { .forEach(qualityGate -> session.wsClient().wsConnector().call(new PostRequest("api/qualitygates/destroy").setParam("id", qualityGate.getId())).failIfNotSuccessful()); } - public CreateWsResponse generate() { + public Qualitygates.CreateResponse generate() { int id = ID_GENERATOR.getAndIncrement(); return session.wsClient().qualityGates().create(new CreateRequest().setName("QualityGate" + id)); } - public void associateProject(CreateWsResponse qualityGate, Project project){ + public void associateProject(Qualitygates.CreateResponse qualityGate, Project project){ service().select(new SelectRequest().setGateId(String.valueOf(qualityGate.getId())).setProjectKey(project.getKey())); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/AppAction.java index f24c9bb7ecf..e1851a29d4b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/AppAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/AppAction.java @@ -30,13 +30,13 @@ import org.sonar.db.metric.MetricDto; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.db.permission.OrganizationPermission; import org.sonar.server.user.UserSession; -import org.sonarqube.ws.Qualitygates.AppWsResponse.Metric; +import org.sonarqube.ws.Qualitygates.AppResponse.Metric; import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY; import static org.sonar.api.measures.Metric.ValueType.RATING; import static org.sonar.server.qualitygate.ValidRatingMetrics.isCoreRatingMetric; import static org.sonar.server.ws.WsUtils.writeProtobuf; -import static org.sonarqube.ws.Qualitygates.AppWsResponse; +import static org.sonarqube.ws.Qualitygates.AppResponse; public class AppAction implements QualityGatesWsAction { @@ -62,7 +62,7 @@ public class AppAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - writeProtobuf(AppWsResponse.newBuilder() + writeProtobuf(AppResponse.newBuilder() .setEdit(userSession.hasPermission(OrganizationPermission.ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid())) .addAllMetrics(loadMetrics() .stream() diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java index 9dae665d2d4..6c8d57a8680 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java @@ -29,7 +29,7 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.qualitygate.QualityGateUpdater; import org.sonar.server.user.UserSession; -import org.sonarqube.ws.Qualitygates.CreateWsResponse; +import org.sonarqube.ws.Qualitygates.CreateResponse; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_CREATE; @@ -38,6 +38,7 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAM public class CreateAction implements QualityGatesWsAction { public static final int NAME_MAXIMUM_LENGTH = 100; + private final DbClient dbClient; private final UserSession userSession; private final QualityGateUpdater qualityGateUpdater; @@ -58,6 +59,7 @@ public class CreateAction implements QualityGatesWsAction { .setDescription("Create a Quality Gate.<br>" + "Requires the 'Administer Quality Gates' permission.") .setSince("4.3") + .setResponseExample(getClass().getResource("create-example.json")) .setHandler(this); action.createParam(PARAM_NAME) @@ -73,11 +75,11 @@ public class CreateAction implements QualityGatesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { QualityGateDto newQualityGate = qualityGateUpdater.create(dbSession, request.mandatoryParam(PARAM_NAME)); - CreateWsResponse.Builder createWsResponse = CreateWsResponse.newBuilder() + CreateResponse.Builder createResponse = CreateResponse.newBuilder() .setId(newQualityGate.getId()) .setName(newQualityGate.getName()); dbSession.commit(); - writeProtobuf(createWsResponse.build(), request, response); + writeProtobuf(createResponse.build(), request, response); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java index d54894299c6..6509351d621 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java @@ -29,7 +29,7 @@ import org.sonar.db.qualitygate.QualityGateConditionDto; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.qualitygate.QualityGateConditionsUpdater; import org.sonar.server.user.UserSession; -import org.sonarqube.ws.Qualitygates.CreateConditionWsResponse; +import org.sonarqube.ws.Qualitygates.CreateConditionResponse; import static org.sonar.core.util.Protobuf.setNullable; import static org.sonar.server.qualitygate.ws.QualityGatesWs.addConditionParams; @@ -64,6 +64,7 @@ public class CreateConditionAction implements QualityGatesWsAction { .setDescription("Add a new condition to a quality gate.<br>" + "Requires the 'Administer Quality Gates' permission.") .setSince("4.3") + .setResponseExample(getClass().getResource("create-condition-example.json")) .setHandler(this); createCondition @@ -89,14 +90,14 @@ public class CreateConditionAction implements QualityGatesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, gateId, metric, operator, warning, error, period); - CreateConditionWsResponse.Builder createConditionWsResponse = CreateConditionWsResponse.newBuilder() + CreateConditionResponse.Builder createConditionResponse = CreateConditionResponse.newBuilder() .setId(condition.getId()) .setMetric(condition.getMetricKey()) .setOp(condition.getOperator()); - setNullable(condition.getWarningThreshold(), createConditionWsResponse::setWarning); - setNullable(condition.getErrorThreshold(), createConditionWsResponse::setError); - setNullable(condition.getPeriod(), createConditionWsResponse::setPeriod); - writeProtobuf(createConditionWsResponse.build(), request, response); + setNullable(condition.getWarningThreshold(), createConditionResponse::setWarning); + setNullable(condition.getErrorThreshold(), createConditionResponse::setError); + setNullable(condition.getPeriod(), createConditionResponse::setPeriod); + writeProtobuf(createConditionResponse.build(), request, response); dbSession.commit(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java index 8c89d6381d3..23d7bb84ea7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java @@ -33,7 +33,7 @@ import org.sonar.server.component.ComponentFinder; import org.sonar.server.qualitygate.QualityGateFinder; import org.sonar.server.qualitygate.QualityGateFinder.QualityGateData; import org.sonar.server.user.UserSession; -import org.sonarqube.ws.Qualitygates.GetByProjectWsResponse; +import org.sonarqube.ws.Qualitygates.GetByProjectResponse; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; @@ -97,13 +97,13 @@ public class GetByProjectAction implements QualityGatesWsAction { } } - private static GetByProjectWsResponse buildResponse(Optional<QualityGateData> data) { + private static GetByProjectResponse buildResponse(Optional<QualityGateData> data) { if (!data.isPresent()) { - return GetByProjectWsResponse.getDefaultInstance(); + return GetByProjectResponse.getDefaultInstance(); } QualityGateDto qualityGate = data.get().getQualityGate(); - GetByProjectWsResponse.Builder response = GetByProjectWsResponse.newBuilder(); + GetByProjectResponse.Builder response = GetByProjectResponse.newBuilder(); response.getQualityGateBuilder() .setId(String.valueOf(qualityGate.getId())) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java index 46fbf90e8d0..53c9b817282 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java @@ -42,7 +42,7 @@ import org.sonar.server.component.ComponentFinder.ParamNames; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.user.UserSession; import org.sonar.server.ws.KeyExamples; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse; import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Collections.singletonList; @@ -56,7 +56,7 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PRO import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY; public class ProjectStatusAction implements QualityGatesWsAction { - private static final String QG_STATUSES_ONE_LINE = Arrays.stream(ProjectStatusWsResponse.Status.values()) + private static final String QG_STATUSES_ONE_LINE = Arrays.stream(ProjectStatusResponse.Status.values()) .map(Enum::toString) .collect(Collectors.joining(", ")); private static final String MSG_ONE_PARAMETER_ONLY = String.format("Either '%s', '%s' or '%s' must be provided", PARAM_ANALYSIS_ID, PARAM_PROJECT_ID, PARAM_PROJECT_KEY); @@ -83,7 +83,7 @@ public class ProjectStatusAction implements QualityGatesWsAction { "<li>'Administer System'</li>" + "<li>'Administer' rights on the specified project</li>" + "<li>'Browse' on the specified project</li>" + - "</ul>", QG_STATUSES_ONE_LINE, ProjectStatusWsResponse.Status.NONE)) + "</ul>", QG_STATUSES_ONE_LINE, ProjectStatusResponse.Status.NONE)) .setResponseExample(getClass().getResource("project_status-example.json")) .setSince("5.3") .setHandler(this) @@ -116,17 +116,17 @@ public class ProjectStatusAction implements QualityGatesWsAction { ^ !isNullOrEmpty(projectId) ^ !isNullOrEmpty(projectKey), MSG_ONE_PARAMETER_ONLY); - ProjectStatusWsResponse projectStatusWsResponse = doHandle(analysisId, projectId, projectKey); - writeProtobuf(projectStatusWsResponse, request, response); + ProjectStatusResponse projectStatusResponse = doHandle(analysisId, projectId, projectKey); + writeProtobuf(projectStatusResponse, request, response); } - private ProjectStatusWsResponse doHandle(String analysisId, String projectId, String projectKey) { + private ProjectStatusResponse doHandle(String analysisId, String projectId, String projectKey) { try (DbSession dbSession = dbClient.openSession(false)) { ProjectAndSnapshot projectAndSnapshot = getProjectAndSnapshot(dbSession, analysisId, projectId, projectKey); checkPermission(projectAndSnapshot.project); Optional<String> measureData = getQualityGateDetailsMeasureData(dbSession, projectAndSnapshot.project); - return ProjectStatusWsResponse.newBuilder() + return ProjectStatusResponse.newBuilder() .setProjectStatus(new QualityGateDetailsFormatter(measureData, projectAndSnapshot.snapshotDto).format()) .build(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java index 9e593013ffd..84c902f8729 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java @@ -28,7 +28,7 @@ import java.util.function.Predicate; import java.util.stream.StreamSupport; import javax.annotation.Nullable; import org.sonar.db.component.SnapshotDto; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse; import static com.google.common.base.Strings.isNullOrEmpty; import static org.sonar.api.utils.DateUtils.formatDateTime; @@ -36,15 +36,15 @@ import static org.sonar.api.utils.DateUtils.formatDateTime; public class QualityGateDetailsFormatter { private final Optional<String> optionalMeasureData; private final Optional<SnapshotDto> optionalSnapshot; - private final ProjectStatusWsResponse.ProjectStatus.Builder projectStatusBuilder; + private final ProjectStatusResponse.ProjectStatus.Builder projectStatusBuilder; public QualityGateDetailsFormatter(Optional<String> measureData, Optional<SnapshotDto> snapshot) { this.optionalMeasureData = measureData; this.optionalSnapshot = snapshot; - this.projectStatusBuilder = ProjectStatusWsResponse.ProjectStatus.newBuilder(); + this.projectStatusBuilder = ProjectStatusResponse.ProjectStatus.newBuilder(); } - public ProjectStatusWsResponse.ProjectStatus format() { + public ProjectStatusResponse.ProjectStatus format() { if (!optionalMeasureData.isPresent()) { return newResponseWithoutQualityGateDetails(); } @@ -52,7 +52,7 @@ public class QualityGateDetailsFormatter { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(optionalMeasureData.get()).getAsJsonObject(); - ProjectStatusWsResponse.Status qualityGateStatus = measureLevelToQualityGateStatus(json.get("level").getAsString()); + ProjectStatusResponse.Status qualityGateStatus = measureLevelToQualityGateStatus(json.get("level").getAsString()); projectStatusBuilder.setStatus(qualityGateStatus); formatIgnoredConditions(json); @@ -76,7 +76,7 @@ public class QualityGateDetailsFormatter { return; } - ProjectStatusWsResponse.Period.Builder periodBuilder = ProjectStatusWsResponse.Period.newBuilder(); + ProjectStatusResponse.Period.Builder periodBuilder = ProjectStatusResponse.Period.newBuilder(); periodBuilder.clear(); SnapshotDto snapshot = this.optionalSnapshot.get(); @@ -109,7 +109,7 @@ public class QualityGateDetailsFormatter { } private void formatCondition(JsonObject jsonCondition) { - ProjectStatusWsResponse.Condition.Builder conditionBuilder = ProjectStatusWsResponse.Condition.newBuilder(); + ProjectStatusResponse.Condition.Builder conditionBuilder = ProjectStatusResponse.Condition.newBuilder(); formatConditionLevel(conditionBuilder, jsonCondition); formatConditionMetric(conditionBuilder, jsonCondition); @@ -122,28 +122,28 @@ public class QualityGateDetailsFormatter { projectStatusBuilder.addConditions(conditionBuilder); } - private static void formatConditionActual(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionActual(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement actual = jsonCondition.get("actual"); if (actual != null && !isNullOrEmpty(actual.getAsString())) { conditionBuilder.setActualValue(actual.getAsString()); } } - private static void formatConditionErrorThreshold(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionErrorThreshold(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement error = jsonCondition.get("error"); if (error != null && !isNullOrEmpty(error.getAsString())) { conditionBuilder.setErrorThreshold(error.getAsString()); } } - private static void formatConditionWarningThreshold(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionWarningThreshold(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement warning = jsonCondition.get("warning"); if (warning != null && !isNullOrEmpty(warning.getAsString())) { conditionBuilder.setWarningThreshold(warning.getAsString()); } } - private static void formatConditionPeriod(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionPeriod(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement periodIndex = jsonCondition.get("period"); if (periodIndex == null) { return; @@ -151,31 +151,31 @@ public class QualityGateDetailsFormatter { conditionBuilder.setPeriodIndex(periodIndex.getAsInt()); } - private static void formatConditionOperation(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionOperation(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement op = jsonCondition.get("op"); if (op != null && !isNullOrEmpty(op.getAsString())) { String stringOp = op.getAsString(); - ProjectStatusWsResponse.Comparator comparator = measureOpToQualityGateComparator(stringOp); + ProjectStatusResponse.Comparator comparator = measureOpToQualityGateComparator(stringOp); conditionBuilder.setComparator(comparator); } } - private static void formatConditionMetric(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionMetric(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement metric = jsonCondition.get("metric"); if (metric != null && !isNullOrEmpty(metric.getAsString())) { conditionBuilder.setMetricKey(metric.getAsString()); } } - private static void formatConditionLevel(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { + private static void formatConditionLevel(ProjectStatusResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) { JsonElement measureLevel = jsonCondition.get("level"); if (measureLevel != null && !isNullOrEmpty(measureLevel.getAsString())) { conditionBuilder.setStatus(measureLevelToQualityGateStatus(measureLevel.getAsString())); } } - private static ProjectStatusWsResponse.Status measureLevelToQualityGateStatus(String measureLevel) { - for (ProjectStatusWsResponse.Status status : ProjectStatusWsResponse.Status.values()) { + private static ProjectStatusResponse.Status measureLevelToQualityGateStatus(String measureLevel) { + for (ProjectStatusResponse.Status status : ProjectStatusResponse.Status.values()) { if (status.name().equals(measureLevel)) { return status; } @@ -184,8 +184,8 @@ public class QualityGateDetailsFormatter { throw new IllegalStateException(String.format("Unknown quality gate status '%s'", measureLevel)); } - private static ProjectStatusWsResponse.Comparator measureOpToQualityGateComparator(String measureOp) { - for (ProjectStatusWsResponse.Comparator comparator : ProjectStatusWsResponse.Comparator.values()) { + private static ProjectStatusResponse.Comparator measureOpToQualityGateComparator(String measureOp) { + for (ProjectStatusResponse.Comparator comparator : ProjectStatusResponse.Comparator.values()) { if (comparator.name().equals(measureOp)) { return comparator; } @@ -194,8 +194,8 @@ public class QualityGateDetailsFormatter { throw new IllegalStateException(String.format("Unknown quality gate comparator '%s'", measureOp)); } - private static ProjectStatusWsResponse.ProjectStatus newResponseWithoutQualityGateDetails() { - return ProjectStatusWsResponse.ProjectStatus.newBuilder().setStatus(ProjectStatusWsResponse.Status.NONE).build(); + private static ProjectStatusResponse.ProjectStatus newResponseWithoutQualityGateDetails() { + return ProjectStatusResponse.ProjectStatus.newBuilder().setStatus(ProjectStatusResponse.Status.NONE).build(); } private static Predicate<JsonObject> isConditionOnValidPeriod() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java index dff97b49f94..5bfd1c58e9e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java @@ -28,7 +28,7 @@ import org.sonar.db.qualitygate.QualityGateConditionDto; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.qualitygate.QualityGateConditionsUpdater; import org.sonar.server.user.UserSession; -import org.sonarqube.ws.Qualitygates.UpdateConditionWsResponse; +import org.sonarqube.ws.Qualitygates.UpdateConditionResponse; import static org.sonar.core.util.Protobuf.setNullable; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES; @@ -88,14 +88,14 @@ public class UpdateConditionAction implements QualityGatesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { QualityGateConditionDto condition = qualityGateConditionsUpdater.updateCondition(dbSession, id, metric, operator, warning, error, period); - UpdateConditionWsResponse.Builder updateConditionWsResponse = UpdateConditionWsResponse.newBuilder() + UpdateConditionResponse.Builder updateConditionResponse = UpdateConditionResponse.newBuilder() .setId(condition.getId()) .setMetric(condition.getMetricKey()) .setOp(condition.getOperator()); - setNullable(condition.getWarningThreshold(), updateConditionWsResponse::setWarning); - setNullable(condition.getErrorThreshold(), updateConditionWsResponse::setError); - setNullable(condition.getPeriod(), updateConditionWsResponse::setPeriod); - writeProtobuf(updateConditionWsResponse.build(), request, response); + setNullable(condition.getWarningThreshold(), updateConditionResponse::setWarning); + setNullable(condition.getErrorThreshold(), updateConditionResponse::setError); + setNullable(condition.getPeriod(), updateConditionResponse::setPeriod); + writeProtobuf(updateConditionResponse.build(), request, response); dbSession.commit(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java index ea8519f37c9..07333fa58dd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java @@ -28,7 +28,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.user.UserDto; import org.sonar.server.user.UserSession; -import org.sonarqube.ws.Root; +import org.sonarqube.ws.Roots; import static org.sonar.server.ws.WsUtils.writeProtobuf; @@ -69,13 +69,13 @@ public class SearchAction implements RootsWsAction { } private static void writeResponse(Request request, Response response, List<UserDto> dtos) { - Root.SearchWsResponse.Builder responseBuilder = Root.SearchWsResponse.newBuilder(); - Root.RootContent.Builder rootBuilder = Root.RootContent.newBuilder(); + Roots.SearchResponse.Builder responseBuilder = Roots.SearchResponse.newBuilder(); + Roots.RootContent.Builder rootBuilder = Roots.RootContent.newBuilder(); dtos.forEach(dto -> responseBuilder.addRoots(toRoot(rootBuilder, dto))); writeProtobuf(responseBuilder.build(), request, response); } - private static Root.RootContent toRoot(Root.RootContent.Builder builder, UserDto dto) { + private static Roots.RootContent toRoot(Roots.RootContent.Builder builder, UserDto dto) { builder.clear(); builder.setLogin(dto.getLogin()); if (dto.getName() != null) { diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/create-condition-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/create-condition-example.json new file mode 100644 index 00000000000..e53dcdd1fb1 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/create-condition-example.json @@ -0,0 +1,7 @@ +{ + "id": 1, + "metric": "blocker_violations", + "op": "LT", + "error": "10", + "warning": "5" +} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/create-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/create-example.json new file mode 100644 index 00000000000..f362b98bd3f --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/create-example.json @@ -0,0 +1,4 @@ +{ + "id": 1, + "name": "My Quality Gate" +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/AppActionTest.java index ec037e309f9..2c019103772 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/AppActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/AppActionTest.java @@ -32,7 +32,7 @@ import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; -import org.sonarqube.ws.Qualitygates.AppWsResponse; +import org.sonarqube.ws.Qualitygates.AppResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.measures.Metric.ValueType.BOOL; @@ -70,11 +70,11 @@ public class AppActionTest { .setHidden(true)); dbSession.commit(); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); - List<AppWsResponse.Metric> metrics = response.getMetricsList(); + List<AppResponse.Metric> metrics = response.getMetricsList(); assertThat(metrics).hasSize(1); - AppWsResponse.Metric metric = metrics.get(0); + AppResponse.Metric metric = metrics.get(0); assertThat(metric.getKey()).isEqualTo("metric"); assertThat(metric.getName()).isEqualTo("Metric"); assertThat(metric.getDomain()).isEqualTo("General"); @@ -92,11 +92,11 @@ public class AppActionTest { .setHidden(true)); dbSession.commit(); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); - List<AppWsResponse.Metric> metrics = response.getMetricsList(); + List<AppResponse.Metric> metrics = response.getMetricsList(); assertThat(metrics).hasSize(1); - AppWsResponse.Metric metric = metrics.get(0); + AppResponse.Metric metric = metrics.get(0); assertThat(metric.getKey()).isEqualTo("metric"); assertThat(metric.hasDomain()).isFalse(); } @@ -109,9 +109,9 @@ public class AppActionTest { newMetricDto().setKey("sqale_rating").setValueType(RATING.name()).setHidden(false), newMetricDto().setKey("none_core_rating").setValueType(RATING.name()).setHidden(false)); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); - assertThat(response.getMetricsList()).extracting(AppWsResponse.Metric::getKey).containsOnly( + assertThat(response.getMetricsList()).extracting(AppResponse.Metric::getKey).containsOnly( "reliability_rating", "new_reliability_rating", "sqale_rating"); } @@ -125,7 +125,7 @@ public class AppActionTest { .setHidden(false)); dbSession.commit(); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); assertThat(response.getMetricsList()).isEmpty(); } @@ -140,7 +140,7 @@ public class AppActionTest { .setHidden(false)); dbSession.commit(); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); assertThat(response.getMetricsList()).isEmpty(); } @@ -155,7 +155,7 @@ public class AppActionTest { .setHidden(false)); dbSession.commit(); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); assertThat(response.getMetricsList()).isEmpty(); } @@ -164,7 +164,7 @@ public class AppActionTest { public void return_edit_to_false_when_not_quality_gate_permission() throws Exception { userSession.logIn(); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); assertThat(response.getEdit()).isFalse(); } @@ -173,7 +173,7 @@ public class AppActionTest { public void return_edit_to_true_when_quality_gate_permission() throws Exception { userSession.logIn().addPermission(ADMINISTER_QUALITY_GATES, db.getDefaultOrganization()); - AppWsResponse response = executeRequest(); + AppResponse response = executeRequest(); assertThat(response.getEdit()).isTrue(); } @@ -220,7 +220,7 @@ public class AppActionTest { dbSession.commit(); } - private AppWsResponse executeRequest() { - return ws.newRequest().executeProtobuf(AppWsResponse.class); + private AppResponse executeRequest() { + return ws.newRequest().executeProtobuf(AppResponse.class); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java index 66181d1f55b..8e877eac7d9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java @@ -34,7 +34,7 @@ import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.qualitygate.QualityGateUpdater; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; -import org.sonarqube.ws.Qualitygates.CreateWsResponse; +import org.sonarqube.ws.Qualitygates.CreateResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES; @@ -60,7 +60,7 @@ public class CreateActionTest { public void create_quality_gate() throws Exception { logInAsQualityGateAdmin(); - CreateWsResponse response = executeRequest("Default"); + CreateResponse response = executeRequest("Default"); assertThat(response.getName()).isEqualTo("Default"); assertThat(response.getId()).isNotNull(); @@ -98,14 +98,14 @@ public class CreateActionTest { assertThat(action).isNotNull(); assertThat(action.isInternal()).isFalse(); assertThat(action.isPost()).isTrue(); - assertThat(action.responseExampleAsString()).isNull(); + assertThat(action.responseExampleAsString()).isNotEmpty(); assertThat(action.params()).hasSize(1); } - private CreateWsResponse executeRequest(String name) { + private CreateResponse executeRequest(String name) { return ws.newRequest() .setParam("name", name) - .executeProtobuf(CreateWsResponse.class); + .executeProtobuf(CreateResponse.class); } private void logInAsQualityGateAdmin() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java index 995bad40b56..f37e8c72f60 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java @@ -42,7 +42,7 @@ import org.sonar.server.qualitygate.QualityGateConditionsUpdater; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; -import org.sonarqube.ws.Qualitygates.CreateConditionWsResponse; +import org.sonarqube.ws.Qualitygates.CreateConditionResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.metric.MetricTesting.newMetricDto; @@ -91,7 +91,7 @@ public class CreateConditionActionTest { public void create_warning_condition() throws Exception { logInAsQualityGateAdmin(); - CreateConditionWsResponse response = executeRequest(qualityGateDto.getId(), coverageMetricDto.getKey(), "LT", "90", null, null); + CreateConditionResponse response = executeRequest(qualityGateDto.getId(), coverageMetricDto.getKey(), "LT", "90", null, null); assertCondition(response, "LT", "90", null, null); } @@ -100,7 +100,7 @@ public class CreateConditionActionTest { public void create_error_condition() throws Exception { logInAsQualityGateAdmin(); - CreateConditionWsResponse response = executeRequest(qualityGateDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", null); + CreateConditionResponse response = executeRequest(qualityGateDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", null); assertCondition(response, "LT", null, "90", null); } @@ -109,7 +109,7 @@ public class CreateConditionActionTest { public void create_condition_over_leak_period() throws Exception { logInAsQualityGateAdmin(); - CreateConditionWsResponse response = executeRequest(qualityGateDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", 1); + CreateConditionResponse response = executeRequest(qualityGateDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", 1); assertCondition(response, "LT", null, "90", 1); } @@ -143,11 +143,11 @@ public class CreateConditionActionTest { assertThat(action).isNotNull(); assertThat(action.isInternal()).isFalse(); assertThat(action.isPost()).isTrue(); - assertThat(action.responseExampleAsString()).isNull(); + assertThat(action.responseExampleAsString()).isNotEmpty(); assertThat(action.params()).hasSize(6); } - private void assertCondition(CreateConditionWsResponse response, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) { + private void assertCondition(CreateConditionResponse response, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) { List<QualityGateConditionDto> conditionDtoList = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())); assertThat(conditionDtoList).hasSize(1); QualityGateConditionDto qualityGateConditionDto = conditionDtoList.get(0); @@ -178,7 +178,7 @@ public class CreateConditionActionTest { } } - private CreateConditionWsResponse executeRequest(long qualityProfileId, String metricKey, String operator, @Nullable String warning, @Nullable String error, + private CreateConditionResponse executeRequest(long qualityProfileId, String metricKey, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) { TestRequest request = ws.newRequest() .setParam(PARAM_GATE_ID, Long.toString(qualityProfileId)) @@ -193,7 +193,7 @@ public class CreateConditionActionTest { if (period != null) { request.setParam(PARAM_PERIOD, Integer.toString(period)); } - return request.executeProtobuf(CreateConditionWsResponse.class); + return request.executeProtobuf(CreateConditionResponse.class); } private void logInAsQualityGateAdmin() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java index 63879d99429..cfbd5e10c1f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java @@ -44,7 +44,7 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; import org.sonarqube.ws.Qualitygates; -import org.sonarqube.ws.Qualitygates.GetByProjectWsResponse; +import org.sonarqube.ws.Qualitygates.GetByProjectResponse; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -118,7 +118,7 @@ public class GetByProjectActionTest { setDefaultQualityGate(dbQualityGate.getId()); logInAsProjectUser(project); - GetByProjectWsResponse result = callByKey(project.getKey()); + GetByProjectResponse result = callByKey(project.getKey()); Qualitygates.QualityGate qualityGate = result.getQualityGate(); assertThat(Long.valueOf(qualityGate.getId())).isEqualTo(dbQualityGate.getId()); @@ -135,7 +135,7 @@ public class GetByProjectActionTest { associateProjectToQualityGate(project.getId(), dbQualityGate.getId()); logInAsProjectUser(project); - GetByProjectWsResponse result = callByKey(project.getKey()); + GetByProjectResponse result = callByKey(project.getKey()); Qualitygates.QualityGate qualityGate = result.getQualityGate(); assertThat(qualityGate.getName()).isEqualTo(dbQualityGate.getName()); @@ -149,7 +149,7 @@ public class GetByProjectActionTest { associateProjectToQualityGate(project.getId(), dbQualityGate.getId()); logInAsProjectUser(project); - GetByProjectWsResponse result = callByKey(project.getDbKey()); + GetByProjectResponse result = callByKey(project.getDbKey()); assertThat(result.getQualityGate().getName()).isEqualTo(dbQualityGate.getName()); } @@ -161,7 +161,7 @@ public class GetByProjectActionTest { QualityGateDto dbQualityGate = insertQualityGate("Sonar way"); setDefaultQualityGate(dbQualityGate.getId()); - GetByProjectWsResponse result = callByKey(project.getKey()); + GetByProjectResponse result = callByKey(project.getKey()); assertThat(result.getQualityGate().getName()).isEqualTo(dbQualityGate.getName()); } @@ -173,7 +173,7 @@ public class GetByProjectActionTest { QualityGateDto dbQualityGate = insertQualityGate("Sonar way"); setDefaultQualityGate(dbQualityGate.getId()); - GetByProjectWsResponse result = callByKey(project.getKey()); + GetByProjectResponse result = callByKey(project.getKey()); assertThat(result.getQualityGate().getName()).isEqualTo(dbQualityGate.getName()); } @@ -217,16 +217,16 @@ public class GetByProjectActionTest { call(branch.getDbKey()); } - private GetByProjectWsResponse callByKey(String projectKey) { + private GetByProjectResponse callByKey(String projectKey) { return call(projectKey); } - private GetByProjectWsResponse call(@Nullable String projectKey) { + private GetByProjectResponse call(@Nullable String projectKey) { TestRequest request = ws.newRequest(); if (projectKey != null) { request.setParam("project", projectKey); } - return request.executeProtobuf(GetByProjectWsResponse.class); + return request.executeProtobuf(GetByProjectResponse.class); } private QualityGateDto insertQualityGate(String name) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java index 7e0115e803d..2bf2c728243 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java @@ -44,8 +44,8 @@ import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse.Status; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse.Status; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -166,7 +166,7 @@ public class ProjectStatusActionTest { dbSession.commit(); userSession.addProjectPermission(UserRole.USER, project); - ProjectStatusWsResponse result = call(snapshot.getUuid()); + ProjectStatusResponse result = call(snapshot.getUuid()); assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE); assertThat(result.getProjectStatus().getConditionsCount()).isEqualTo(0); @@ -177,7 +177,7 @@ public class ProjectStatusActionTest { ComponentDto project = db.components().insertPrivateProject(db.organizations().insert()); userSession.addProjectPermission(UserRole.USER, project); - ProjectStatusWsResponse result = callByProjectUuid(project.uuid()); + ProjectStatusResponse result = callByProjectUuid(project.uuid()); assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE); assertThat(result.getProjectStatus().getConditionsCount()).isEqualTo(0); @@ -280,16 +280,16 @@ public class ProjectStatusActionTest { .execute(); } - private ProjectStatusWsResponse call(String taskId) { + private ProjectStatusResponse call(String taskId) { return ws.newRequest() .setParam("analysisId", taskId) - .executeProtobuf(ProjectStatusWsResponse.class); + .executeProtobuf(ProjectStatusResponse.class); } - private ProjectStatusWsResponse callByProjectUuid(String projectUuid) { + private ProjectStatusResponse callByProjectUuid(String projectUuid) { return ws.newRequest() .setParam(PARAM_PROJECT_ID, projectUuid) - .executeProtobuf(ProjectStatusWsResponse.class); + .executeProtobuf(ProjectStatusResponse.class); } private void logInAsSystemAdministrator() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java index 00196c7e001..62f96974cf8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java @@ -28,8 +28,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.db.component.SnapshotDto; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse.ProjectStatus; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse.ProjectStatus; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.utils.DateUtils.formatDateTime; @@ -51,21 +51,21 @@ public class QualityGateDetailsFormatterTest { ProjectStatus result = underTest.format(); - assertThat(result.getStatus()).isEqualTo(ProjectStatusWsResponse.Status.ERROR); + assertThat(result.getStatus()).isEqualTo(ProjectStatusResponse.Status.ERROR); // check conditions assertThat(result.getConditionsCount()).isEqualTo(4); - List<ProjectStatusWsResponse.Condition> conditions = result.getConditionsList(); + List<ProjectStatusResponse.Condition> conditions = result.getConditionsList(); assertThat(conditions).extracting("status").containsExactly( - ProjectStatusWsResponse.Status.ERROR, - ProjectStatusWsResponse.Status.WARN, - ProjectStatusWsResponse.Status.OK, - ProjectStatusWsResponse.Status.OK); + ProjectStatusResponse.Status.ERROR, + ProjectStatusResponse.Status.WARN, + ProjectStatusResponse.Status.OK, + ProjectStatusResponse.Status.OK); assertThat(conditions).extracting("metricKey").containsExactly("new_coverage", "new_blocker_violations", "new_critical_violations", "new_sqale_debt_ratio"); assertThat(conditions).extracting("comparator").containsExactly( - ProjectStatusWsResponse.Comparator.LT, - ProjectStatusWsResponse.Comparator.GT, - ProjectStatusWsResponse.Comparator.NE, - ProjectStatusWsResponse.Comparator.EQ); + ProjectStatusResponse.Comparator.LT, + ProjectStatusResponse.Comparator.GT, + ProjectStatusResponse.Comparator.NE, + ProjectStatusResponse.Comparator.EQ); assertThat(conditions).extracting("periodIndex").containsExactly(1, 1, 1, 1); assertThat(conditions).extracting("warningThreshold").containsOnly("80", ""); assertThat(conditions).extracting("errorThreshold").containsOnly("85", "0", "5"); @@ -73,7 +73,7 @@ public class QualityGateDetailsFormatterTest { // check periods assertThat(result.getPeriodsCount()).isEqualTo(1); - List<ProjectStatusWsResponse.Period> periods = result.getPeriodsList(); + List<ProjectStatusResponse.Period> periods = result.getPeriodsList(); assertThat(periods).extracting("index").containsExactly(1); assertThat(periods).extracting("mode").containsExactly("last_version"); assertThat(periods).extracting("parameter").containsExactly("2015-12-07"); @@ -93,10 +93,10 @@ public class QualityGateDetailsFormatterTest { // check conditions assertThat(result.getConditionsCount()).isEqualTo(1); - List<ProjectStatusWsResponse.Condition> conditions = result.getConditionsList(); - assertThat(conditions).extracting("status").containsExactly(ProjectStatusWsResponse.Status.ERROR); + List<ProjectStatusResponse.Condition> conditions = result.getConditionsList(); + assertThat(conditions).extracting("status").containsExactly(ProjectStatusResponse.Status.ERROR); assertThat(conditions).extracting("metricKey").containsExactly("new_coverage"); - assertThat(conditions).extracting("comparator").containsExactly(ProjectStatusWsResponse.Comparator.LT); + assertThat(conditions).extracting("comparator").containsExactly(ProjectStatusResponse.Comparator.LT); assertThat(conditions).extracting("periodIndex").containsExactly(1); assertThat(conditions).extracting("warningThreshold").containsOnly("80"); assertThat(conditions).extracting("errorThreshold").containsOnly("85"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java index 560a7de1529..ea5072a6cae 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java @@ -42,7 +42,7 @@ import org.sonar.server.qualitygate.QualityGateConditionsUpdater; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; -import org.sonarqube.ws.Qualitygates.CreateConditionWsResponse; +import org.sonarqube.ws.Qualitygates.CreateConditionResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.metric.MetricTesting.newMetricDto; @@ -99,7 +99,7 @@ public class UpdateConditionActionTest { public void update_warning_condition() throws Exception { logInAsQualityGateAdmin(); - CreateConditionWsResponse response = executeRequest(conditionDto.getId(), coverageMetricDto.getKey(), "LT", "90", null, null); + CreateConditionResponse response = executeRequest(conditionDto.getId(), coverageMetricDto.getKey(), "LT", "90", null, null); assertCondition(response, "LT", "90", null, null); } @@ -108,7 +108,7 @@ public class UpdateConditionActionTest { public void update_error_condition() throws Exception { logInAsQualityGateAdmin(); - CreateConditionWsResponse response = executeRequest(conditionDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", null); + CreateConditionResponse response = executeRequest(conditionDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", null); assertCondition(response, "LT", null, "90", null); } @@ -117,7 +117,7 @@ public class UpdateConditionActionTest { public void update_condition_over_leak_period() throws Exception { logInAsQualityGateAdmin(); - CreateConditionWsResponse response = executeRequest(conditionDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", 1); + CreateConditionResponse response = executeRequest(conditionDto.getId(), coverageMetricDto.getKey(), "LT", null, "90", 1); assertCondition(response, "LT", null, "90", 1); } @@ -155,7 +155,7 @@ public class UpdateConditionActionTest { assertThat(action.params()).hasSize(6); } - private void assertCondition(CreateConditionWsResponse response, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) { + private void assertCondition(CreateConditionResponse response, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) { List<QualityGateConditionDto> conditionDtoList = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())); assertThat(conditionDtoList).hasSize(1); QualityGateConditionDto qualityGateConditionDto = conditionDtoList.get(0); @@ -186,7 +186,7 @@ public class UpdateConditionActionTest { } } - private CreateConditionWsResponse executeRequest(long conditionId, String metricKey, String operator, @Nullable String warning, @Nullable String error, + private CreateConditionResponse executeRequest(long conditionId, String metricKey, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) { TestRequest request = ws.newRequest() .setParam(PARAM_ID, Long.toString(conditionId)) @@ -201,7 +201,7 @@ public class UpdateConditionActionTest { if (period != null) { request.setParam(PARAM_PERIOD, Integer.toString(period)); } - return request.executeProtobuf(CreateConditionWsResponse.class); + return request.executeProtobuf(CreateConditionResponse.class); } private void logInAsQualityGateAdmin() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java index 0c7d2ef1aa1..55557c52b5b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java @@ -35,7 +35,7 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; import org.sonarqube.ws.MediaTypes; -import org.sonarqube.ws.Root; +import org.sonarqube.ws.Roots; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.test.JsonAssert.assertJson; @@ -112,9 +112,9 @@ public class SearchActionTest { userDao.setRoot(dbSession, rootDto.getLogin(), true); dbSession.commit(); - List<Root.RootContent> roots = executeRequest(); + List<Roots.RootContent> roots = executeRequest(); assertThat(roots).hasSize(1); - Root.RootContent root = roots.iterator().next(); + Roots.RootContent root = roots.iterator().next(); assertThat(root.getLogin()).isEqualTo(rootDto.getLogin()); assertThat(root.hasName()).isFalse(); assertThat(root.hasEmail()).isFalse(); @@ -132,7 +132,7 @@ public class SearchActionTest { dbSession.commit(); assertThat(executeRequest()) - .extracting(Root.RootContent::getName) + .extracting(Roots.RootContent::getName) .containsExactly("bbb", "ccc"); } @@ -140,9 +140,9 @@ public class SearchActionTest { return userSessionRule.logIn().setRoot(); } - private List<Root.RootContent> executeRequest() { + private List<Roots.RootContent> executeRequest() { return wsTester.newRequest() - .executeProtobuf(Root.SearchWsResponse.class) + .executeProtobuf(Roots.SearchResponse.class) .getRootsList(); } diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/batch/BatchService.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/batch/BatchService.java index 410d569803c..86f8551cbaf 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/batch/BatchService.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/batch/BatchService.java @@ -19,12 +19,14 @@ */ package org.sonarqube.ws.client.batch; +import java.util.stream.Collectors; import javax.annotation.Generated; -import org.sonarqube.ws.Batch.WsProjectResponse; import org.sonarqube.ws.MediaTypes; 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.Batch.WsProjectResponse; /** * Get JAR files and referentials for batch diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java index 9fda0dc7fb7..609d9c44633 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java @@ -77,7 +77,7 @@ public class ActivityRequest { /** * Maximum date of end of task processing (inclusive) * - * Example value: "2017-11-16T10:21:24+0100" + * Example value: "2017-11-23T15:56:03+0100" */ public ActivityRequest setMaxExecutedAt(String maxExecutedAt) { this.maxExecutedAt = maxExecutedAt; @@ -91,7 +91,7 @@ public class ActivityRequest { /** * Minimum date of task submission (inclusive) * - * Example value: "2017-11-16T10:21:24+0100" + * Example value: "2017-11-23T15:56:03+0100" */ public ActivityRequest setMinSubmittedAt(String minSubmittedAt) { this.minSubmittedAt = minSubmittedAt; diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ComponentsService.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ComponentsService.java index 4e4980c8c3e..712b44f7614 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ComponentsService.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ComponentsService.java @@ -104,7 +104,7 @@ public class ComponentsService extends BaseService { } /** - * Returns a component (file, directory, project, view…) and its ancestors. The ancestors are ordered from the parent to the root project. The 'componentId' or 'component' parameter must be provided.<br>Requires the following permission: 'Browse' on the project of the specified component. + * Returns a component (file, directory, project, view?) and its ancestors. The ancestors are ordered from the parent to the root project. The 'componentId' or 'component' parameter must be provided.<br>Requires the following permission: 'Browse' on the project of the specified component. * * This is part of the internal API. * This is a GET request. diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ShowRequest.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ShowRequest.java index 6c7a5b8e2ab..c07e1b91e64 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ShowRequest.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/components/ShowRequest.java @@ -23,7 +23,7 @@ import java.util.List; import javax.annotation.Generated; /** - * Returns a component (file, directory, project, view…) and its ancestors. The ancestors are ordered from the parent to the root project. The 'componentId' or 'component' parameter must be provided.<br>Requires the following permission: 'Browse' on the project of the specified component. + * Returns a component (file, directory, project, view?) and its ancestors. The ancestors are ordered from the parent to the root project. The 'componentId' or 'component' parameter must be provided.<br>Requires the following permission: 'Browse' on the project of the specified component. * * This is part of the internal API. * This is a POST request. diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/projectanalyses/ProjectAnalysesService.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/projectanalyses/ProjectAnalysesService.java index 6538f888f8f..40b8084aa51 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/projectanalyses/ProjectAnalysesService.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/projectanalyses/ProjectAnalysesService.java @@ -19,15 +19,16 @@ */ package org.sonarqube.ws.client.projectanalyses; +import java.util.stream.Collectors; import javax.annotation.Generated; import org.sonarqube.ws.MediaTypes; -import org.sonarqube.ws.ProjectAnalyses.CreateEventResponse; -import org.sonarqube.ws.ProjectAnalyses.SearchResponse; -import org.sonarqube.ws.ProjectAnalyses.UpdateEventResponse; 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.ProjectAnalyses.CreateEventResponse; +import org.sonarqube.ws.ProjectAnalyses.SearchResponse; +import org.sonarqube.ws.ProjectAnalyses.UpdateEventResponse; /** * Manage project analyses. diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java index f37cd94efee..760cee9eac0 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java @@ -21,12 +21,13 @@ package org.sonarqube.ws.client.qualitygates; import javax.annotation.Generated; import org.sonarqube.ws.MediaTypes; -import org.sonarqube.ws.Qualitygates.AppWsResponse; -import org.sonarqube.ws.Qualitygates.CreateConditionWsResponse; -import org.sonarqube.ws.Qualitygates.CreateWsResponse; -import org.sonarqube.ws.Qualitygates.GetByProjectWsResponse; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse; -import org.sonarqube.ws.Qualitygates.UpdateConditionWsResponse; +import org.sonarqube.ws.Qualitygates; +import org.sonarqube.ws.Qualitygates.AppResponse; +import org.sonarqube.ws.Qualitygates.CreateConditionResponse; +import org.sonarqube.ws.Qualitygates.CreateResponse; +import org.sonarqube.ws.Qualitygates.GetByProjectResponse; +import org.sonarqube.ws.Qualitygates.ProjectStatusResponse; +import org.sonarqube.ws.Qualitygates.UpdateConditionResponse; import org.sonarqube.ws.client.BaseService; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; @@ -51,10 +52,10 @@ public class QualitygatesService extends BaseService { * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/qualitygates/app">Further information about this action online (including a response example)</a> * @since 4.3 */ - public AppWsResponse app() { + public AppResponse app() { return call( new GetRequest(path("app")), - AppWsResponse.parser()); + AppResponse.parser()); } /** @@ -82,11 +83,11 @@ public class QualitygatesService extends BaseService { * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/qualitygates/create">Further information about this action online (including a response example)</a> * @since 4.3 */ - public CreateWsResponse create(CreateRequest request) { + public Qualitygates.CreateResponse create(CreateRequest request) { return call( new PostRequest(path("create")) .setParam("name", request.getName()), - CreateWsResponse.parser()); + CreateResponse.parser()); } /** @@ -97,7 +98,7 @@ public class QualitygatesService extends BaseService { * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/qualitygates/create_condition">Further information about this action online (including a response example)</a> * @since 4.3 */ - public CreateConditionWsResponse createCondition(CreateConditionRequest request) { + public CreateConditionResponse createCondition(CreateConditionRequest request) { return call( new PostRequest(path("create_condition")) .setParam("error", request.getError()) @@ -106,7 +107,7 @@ public class QualitygatesService extends BaseService { .setParam("op", request.getOp()) .setParam("period", request.getPeriod()) .setParam("warning", request.getWarning()), - CreateConditionWsResponse.parser()); + CreateConditionResponse.parser()); } /** @@ -166,11 +167,11 @@ public class QualitygatesService extends BaseService { * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/qualitygates/get_by_project">Further information about this action online (including a response example)</a> * @since 6.1 */ - public GetByProjectWsResponse getByProject(GetByProjectRequest request) { + public GetByProjectResponse getByProject(GetByProjectRequest request) { return call( new GetRequest(path("get_by_project")) .setParam("project", request.getProject()), - GetByProjectWsResponse.parser()); + GetByProjectResponse.parser()); } /** @@ -196,13 +197,13 @@ public class QualitygatesService extends BaseService { * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/qualitygates/project_status">Further information about this action online (including a response example)</a> * @since 5.3 */ - public ProjectStatusWsResponse projectStatus(ProjectStatusRequest request) { + public ProjectStatusResponse projectStatus(ProjectStatusRequest request) { return call( new GetRequest(path("project_status")) .setParam("analysisId", request.getAnalysisId()) .setParam("projectId", request.getProjectId()) .setParam("projectKey", request.getProjectKey()), - ProjectStatusWsResponse.parser()); + ProjectStatusResponse.parser()); } /** @@ -326,6 +327,6 @@ public class QualitygatesService extends BaseService { .setParam("op", request.getOp()) .setParam("period", request.getPeriod()) .setParam("warning", request.getWarning()), - UpdateConditionWsResponse.parser()); + UpdateConditionResponse.parser()); } } diff --git a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/roots/RootsService.java b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/roots/RootsService.java index a1dc93f98f7..506197f170a 100644 --- a/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/roots/RootsService.java +++ b/sonar-ws-generated/src/main/java/org/sonarqube/ws/client/roots/RootsService.java @@ -26,6 +26,7 @@ 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.Roots.SearchResponse; /** * Manage root users @@ -46,11 +47,10 @@ public class RootsService extends BaseService { * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/roots/search">Further information about this action online (including a response example)</a> * @since 6.2 */ - public String search() { + public SearchResponse search() { return call( - new GetRequest(path("search")) - .setMediaType(MediaTypes.JSON) - ).content(); + new GetRequest(path("search")), + SearchResponse.parser()); } /** diff --git a/sonar-ws-generated/src/main/protobuf/ws-qualitygates.proto b/sonar-ws-generated/src/main/protobuf/ws-qualitygates.proto index c7d63b571ca..7a40a0bf2ce 100644 --- a/sonar-ws-generated/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws-generated/src/main/protobuf/ws-qualitygates.proto @@ -25,7 +25,7 @@ option java_outer_classname = "Qualitygates"; option optimize_for = SPEED; // GET api/qualitygates/project_status -message ProjectStatusWsResponse { +message ProjectStatusResponse { optional ProjectStatus projectStatus = 1; message ProjectStatus { @@ -68,7 +68,7 @@ message ProjectStatusWsResponse { } // GET api/qualitygates/get_by_project -message GetByProjectWsResponse { +message GetByProjectResponse { optional QualityGate qualityGate = 1; } @@ -79,7 +79,7 @@ message QualityGate { } // GET api/qualitygates/app -message AppWsResponse { +message AppResponse { optional bool edit = 1; repeated Metric metrics = 3; @@ -93,13 +93,13 @@ message AppWsResponse { } // POST api/qualitygates/create -message CreateWsResponse { +message CreateResponse { optional int64 id = 1; optional string name = 2; } // POST api/qualitygates/create_condition -message CreateConditionWsResponse { +message CreateConditionResponse { optional int64 id = 1; optional string metric = 2; optional string op = 3; @@ -109,7 +109,7 @@ message CreateConditionWsResponse { } // POST api/qualitygates/update_condition -message UpdateConditionWsResponse { +message UpdateConditionResponse { optional int64 id = 1; optional string metric = 2; optional string op = 3; diff --git a/sonar-ws-generated/src/main/protobuf/ws-root.proto b/sonar-ws-generated/src/main/protobuf/ws-root.proto index c80ecfb270f..fd55b926a4d 100644 --- a/sonar-ws-generated/src/main/protobuf/ws-root.proto +++ b/sonar-ws-generated/src/main/protobuf/ws-root.proto @@ -21,11 +21,11 @@ syntax = "proto2"; package sonarqube.ws.root; option java_package = "org.sonarqube.ws"; -option java_outer_classname = "Root"; +option java_outer_classname = "Roots"; option optimize_for = SPEED; // WS api/root/search -message SearchWsResponse { +message SearchResponse { repeated RootContent roots = 1; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index 61f41989b8f..660f3652418 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -33,7 +33,7 @@ import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; import org.sonarqube.ws.client.projectlinks.ProjectLinksService; import org.sonarqube.ws.client.qualitygates.QualitygatesService; import org.sonarqube.ws.client.qualityprofile.QualityProfilesService; -import org.sonarqube.ws.client.root.RootsService; +import org.sonarqube.ws.client.roots.RootsService; import org.sonarqube.ws.client.rule.RulesService; import org.sonarqube.ws.client.setting.SettingsService; import org.sonarqube.ws.client.system.SystemService; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index 824ec008990..b81990aa1a6 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -33,7 +33,7 @@ import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; import org.sonarqube.ws.client.projectlinks.ProjectLinksService; import org.sonarqube.ws.client.qualitygates.QualitygatesService; import org.sonarqube.ws.client.qualityprofile.QualityProfilesService; -import org.sonarqube.ws.client.root.RootsService; +import org.sonarqube.ws.client.roots.RootsService; import org.sonarqube.ws.client.rule.RulesService; import org.sonarqube.ws.client.setting.SettingsService; import org.sonarqube.ws.client.system.SystemService; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootsService.java deleted file mode 100644 index 43b06b8a3e0..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootsService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.root; - -import org.sonarqube.ws.Root; -import org.sonarqube.ws.client.BaseService; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.PostRequest; -import org.sonarqube.ws.client.WsConnector; - -public class RootsService extends BaseService { - public RootsService(WsConnector wsConnector) { - super(wsConnector, "api/roots"); - } - - public Root.SearchWsResponse search() { - return call(new GetRequest(path("search")), Root.SearchWsResponse.parser()); - } - - public void setRoot(String login) { - PostRequest post = new PostRequest(path("set_root")) - .setParam("login", login); - - call(post); - } - - public void unsetRoot(String login) { - PostRequest post = new PostRequest(path("unset_root")) - .setParam("login", login); - - call(post); - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/root/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/root/package-info.java deleted file mode 100644 index f524396d5a2..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/root/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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. - */ -@ParametersAreNonnullByDefault -package org.sonarqube.ws.client.root; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootsServiceTest.java deleted file mode 100644 index b6cbcf439de..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootsServiceTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.root; - -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.ws.client.ServiceTester; -import org.sonarqube.ws.client.WsConnector; - -import static org.mockito.Mockito.mock; - -public class RootsServiceTest { - private static final String SOME_LOGIN = "johnDoe"; - - @Rule - public ServiceTester<RootsService> serviceTester = new ServiceTester<>(new RootsService(mock(WsConnector.class))); - - private RootsService underTest = serviceTester.getInstanceUnderTest(); - - @Test - public void search() { - underTest.search(); - - serviceTester.assertThat(serviceTester.getGetRequest()) - .hasPath("search") - .andNoOtherParam(); - } - - @Test - public void setRoot() { - underTest.setRoot(SOME_LOGIN); - - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasPath("set_root") - .hasParam("login", SOME_LOGIN) - .andNoOtherParam(); - } - - @Test - public void unsetRoot() { - underTest.unsetRoot(SOME_LOGIN); - - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasPath("unset_root") - .hasParam("login", SOME_LOGIN) - .andNoOtherParam(); - } -} diff --git a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipUiTest.java b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipUiTest.java index e909fd2d810..955680532f1 100644 --- a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipUiTest.java @@ -30,6 +30,7 @@ import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.organization.MembersPage; import org.sonarqube.ws.Organizations.Organization; import org.sonarqube.ws.Users.CreateWsResponse.User; +import org.sonarqube.ws.client.roots.SetRootRequest; public class OrganizationMembershipUiTest { @@ -45,7 +46,7 @@ public class OrganizationMembershipUiTest { public void setUp() { tester.settings().setGlobalSetting("sonar.organizations.anyoneCanCreate", "true"); root = tester.users().generate(); - tester.wsClient().roots().setRoot(root.getLogin()); + tester.wsClient().roots().setRoot(new SetRootRequest().setLogin(root.getLogin())); } @After diff --git a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationTest.java b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationTest.java index fbf6725f48f..bbde52e720e 100644 --- a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationTest.java @@ -43,6 +43,8 @@ import org.sonarqube.ws.client.organization.SearchWsRequest; import org.sonarqube.ws.client.organization.UpdateWsRequest; import org.sonarqube.ws.client.permission.AddUserWsRequest; import org.sonarqube.ws.client.permission.PermissionsService; +import org.sonarqube.ws.client.roots.SetRootRequest; +import org.sonarqube.ws.client.roots.UnsetRootRequest; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; @@ -181,13 +183,13 @@ public class OrganizationTest { User user = tester.users().generate(); OrganizationTester asUser = tester.as(user.getLogin()).organizations(); - tester.wsClient().roots().setRoot(user.getLogin()); + tester.wsClient().roots().setRoot(new SetRootRequest().setLogin(user.getLogin())); Organization org = asUser.generate(); // delete org, attempt recreate when no root anymore and ensure it can't anymore asUser.service().delete(org.getKey()); - tester.wsClient().roots().unsetRoot(user.getLogin()); + tester.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user.getLogin())); expectForbiddenError(() -> asUser.generate()); } diff --git a/tests/src/test/java/org/sonarqube/tests/organization/RootUserTest.java b/tests/src/test/java/org/sonarqube/tests/organization/RootUserTest.java index 18451b12339..c9bb141d8e9 100644 --- a/tests/src/test/java/org/sonarqube/tests/organization/RootUserTest.java +++ b/tests/src/test/java/org/sonarqube/tests/organization/RootUserTest.java @@ -26,8 +26,10 @@ import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.TesterSession; -import org.sonarqube.ws.Root; +import org.sonarqube.ws.Roots; import org.sonarqube.ws.Users; +import org.sonarqube.ws.client.roots.SetRootRequest; +import org.sonarqube.ws.client.roots.UnsetRootRequest; import util.user.UserRule; import static org.assertj.core.api.Assertions.assertThat; @@ -45,23 +47,23 @@ public class RootUserTest { @Test public void system_administrator_is_flagged_as_root_when_he_enables_organization_support() { assertThat(tester.wsClient().roots().search().getRootsList()) - .extracting(Root.RootContent::getLogin) + .extracting(Roots.RootContent::getLogin) .containsExactly(UserRule.ADMIN_LOGIN); } @Test public void a_root_can_flag_other_user_as_root() { Users.CreateWsResponse.User user = tester.users().generate(); - tester.wsClient().roots().setRoot(user.getLogin()); + tester.wsClient().roots().setRoot(new SetRootRequest().setLogin(user.getLogin())); assertThat(tester.wsClient().roots().search().getRootsList()) - .extracting(Root.RootContent::getLogin) + .extracting(Roots.RootContent::getLogin) .containsExactlyInAnyOrder(UserRule.ADMIN_LOGIN, user.getLogin()); } @Test public void last_root_can_not_be_unset_root() throws SQLException { - expectBadRequestError(() -> tester.wsClient().roots().unsetRoot(UserRule.ADMIN_LOGIN)); + expectBadRequestError(() -> tester.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(UserRule.ADMIN_LOGIN))); } @Test @@ -72,19 +74,19 @@ public class RootUserTest { TesterSession user2Session = tester.as(user2.getLogin()); // non root can not set or unset root another user not itself - expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user2.getLogin())); - expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(user1.getLogin())); - expectForbiddenError(() -> user1Session.wsClient().roots().unsetRoot(user1.getLogin())); - expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(user1.getLogin())); - expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(user2.getLogin())); + expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(new SetRootRequest().setLogin(user2.getLogin()))); + expectForbiddenError(() -> user1Session.wsClient().roots().setRoot(new SetRootRequest().setLogin(user1.getLogin()))); + expectForbiddenError(() -> user1Session.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user1.getLogin()))); + expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user1.getLogin()))); + expectForbiddenError(() -> user2Session.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user2.getLogin()))); // admin (the first root) sets root1 as root - tester.wsClient().roots().setRoot(user1.getLogin()); + tester.wsClient().roots().setRoot(new SetRootRequest().setLogin(user1.getLogin())); // root1 can set root root2 - user1Session.wsClient().roots().setRoot(user2.getLogin()); + user1Session.wsClient().roots().setRoot(new SetRootRequest().setLogin(user2.getLogin())); // root2 can unset root root1 - user2Session.wsClient().roots().unsetRoot(user1.getLogin()); + user2Session.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user1.getLogin())); // root2 can unset root itself as it's not the last root - user2Session.wsClient().roots().unsetRoot(user2.getLogin()); + user2Session.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user2.getLogin())); } } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java index e4f9bf3fd27..fd8d71284c0 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java @@ -31,12 +31,11 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; +import org.sonarqube.ws.Ce; import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.Organizations; -import org.sonarqube.ws.Ce; import org.sonarqube.ws.Projects.CreateWsResponse.Project; import org.sonarqube.ws.Qualitygates; -import org.sonarqube.ws.Qualitygates.CreateWsResponse; import org.sonarqube.ws.Users; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; @@ -60,9 +59,9 @@ public class OrganizationQualityGateForSmallChangesetsTest { public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lines_of_NEW_code() throws Exception { Organizations.Organization organization = tester.organizations().generate(); Project project = tester.projects().provision(organization); - CreateWsResponse qualityGate = tester.qGates().generate(); + Qualitygates.CreateResponse qualityGate = tester.qGates().generate(); tester.qGates().associateProject(qualityGate, project); - Qualitygates.CreateConditionWsResponse condition = tester.wsClient().qualityGates().createCondition(new CreateConditionRequest() + Qualitygates.CreateConditionResponse condition = tester.wsClient().qualityGates().createCondition(new CreateConditionRequest() .setGateId(String.valueOf(qualityGate.getId())) .setMetric("new_coverage") .setOp("LT") diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java index 2deaa41a397..953df1c4a21 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Organizations.Organization; import org.sonarqube.ws.Projects.CreateWsResponse.Project; -import org.sonarqube.ws.Qualitygates.CreateWsResponse; +import org.sonarqube.ws.Qualitygates; import org.sonarqube.ws.Users; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; @@ -50,7 +50,7 @@ public class OrganizationQualityGateTest { public void always_display_current_quality_gate_in_effect() throws Exception { Organization organization = tester.organizations().generate(); Project project = tester.projects().provision(organization); - CreateWsResponse qualityGate = tester.qGates().generate(); + Qualitygates.CreateResponse qualityGate = tester.qGates().generate(); tester.qGates().associateProject(qualityGate, project); tester.wsClient().qualityGates().createCondition(new CreateConditionRequest() .setGateId(String.valueOf(qualityGate.getId())) @@ -80,7 +80,7 @@ public class OrganizationQualityGateTest { Map currentQualityGate2 = (Map) ItUtils.jsonToMap(response2.content()).get("qualityGate"); assertThat((long) (double) (Double) currentQualityGate2.get("key")).isEqualTo(qualityGate.getId()); - CreateWsResponse qualityGate2 = tester.qGates().generate(); + Qualitygates.CreateResponse qualityGate2 = tester.qGates().generate(); tester.qGates().associateProject(qualityGate2, project); tester.wsClient().qualityGates().createCondition(new CreateConditionRequest() .setGateId(String.valueOf(qualityGate2.getId())) diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java index e2a64b36ddf..41f36e564a8 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java @@ -86,7 +86,7 @@ public class QualityGateNotificationTest { .failIfNotSuccessful(); // Create quality gate with conditions on variations - Qualitygates.CreateWsResponse simple = tester.qGates().generate(); + Qualitygates.CreateResponse simple = tester.qGates().generate(); tester.qGates().service() .createCondition(new CreateConditionRequest().setGateId(String.valueOf(simple.getId())).setMetric("ncloc").setPeriod("1").setOp("EQ").setWarning("0")); Project project = tester.projects().provision(); diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java index 5da686950bf..66041b9c68b 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java @@ -47,7 +47,7 @@ public class QualityGateOnRatingMeasuresTest { @Test public void generate_warning_qgate_on_rating_metric() throws Exception { Project project = tester.projects().provision(); - Qualitygates.CreateWsResponse qualityGate = tester.qGates().generate(); + Qualitygates.CreateResponse qualityGate = tester.qGates().generate(); tester.qGates().associateProject(qualityGate, project); tester.qGates().service().createCondition(new CreateConditionRequest() .setGateId(String.valueOf(qualityGate.getId())) @@ -65,7 +65,7 @@ public class QualityGateOnRatingMeasuresTest { @Test public void generate_error_qgate_on_rating_metric_on_leak_period() throws Exception { Project project = tester.projects().provision(); - Qualitygates.CreateWsResponse qualityGate = tester.qGates().generate(); + Qualitygates.CreateResponse qualityGate = tester.qGates().generate(); tester.qGates().associateProject(qualityGate, project); tester.settings().setGlobalSetting("sonar.leak.period", "previous_version"); tester.wsClient().qualityGates().createCondition(new CreateConditionRequest() diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java index f4c931997ed..12be1f95854 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java @@ -45,12 +45,11 @@ import org.sonar.wsclient.qualitygate.QualityGateClient; import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.TesterSession; import org.sonarqube.ws.Ce; +import org.sonarqube.ws.Measures.Measure; import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.Organizations.Organization; -import org.sonarqube.ws.Measures.Measure; import org.sonarqube.ws.Projects.CreateWsResponse.Project; import org.sonarqube.ws.Qualitygates; -import org.sonarqube.ws.Qualitygates.ProjectStatusWsResponse; import org.sonarqube.ws.Users; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; @@ -247,11 +246,11 @@ public class QualityGateTest { String taskId = getTaskIdInLocalReport(projectDir("qualitygate/xoo-sample")); String analysisId = getAnalysisId(taskId); - ProjectStatusWsResponse projectStatusWsResponse = tester.wsClient().qualityGates().projectStatus(new ProjectStatusRequest().setAnalysisId(analysisId)); - ProjectStatusWsResponse.ProjectStatus projectStatus = projectStatusWsResponse.getProjectStatus(); - assertThat(projectStatus.getStatus()).isEqualTo(ProjectStatusWsResponse.Status.ERROR); + Qualitygates.ProjectStatusResponse projectStatusWsResponse = tester.wsClient().qualityGates().projectStatus(new ProjectStatusRequest().setAnalysisId(analysisId)); + Qualitygates.ProjectStatusResponse.ProjectStatus projectStatus = projectStatusWsResponse.getProjectStatus(); + assertThat(projectStatus.getStatus()).isEqualTo(Qualitygates.ProjectStatusResponse.Status.ERROR); assertThat(projectStatus.getConditionsCount()).isEqualTo(1); - ProjectStatusWsResponse.Condition condition = projectStatus.getConditionsList().get(0); + Qualitygates.ProjectStatusResponse.Condition condition = projectStatus.getConditionsList().get(0); assertThat(condition.getMetricKey()).isEqualTo("ncloc"); assertThat(condition.getErrorThreshold()).isEqualTo("7"); } finally { @@ -270,7 +269,7 @@ public class QualityGateTest { createCustomIntMetric(customMetricKey); try { // create quality gate - Qualitygates.CreateWsResponse simple = tester.wsClient().qualityGates().create(new CreateRequest().setName("OnCustomMetric")); + Qualitygates.CreateResponse simple = tester.wsClient().qualityGates().create(new CreateRequest().setName("OnCustomMetric")); Long qualityGateId = simple.getId(); qgClient().createCondition(NewCondition.create(qualityGateId).metricKey(customMetricKey).operator("GT").warningThreshold("40")); @@ -298,8 +297,8 @@ public class QualityGateTest { TesterSession qGateAdminTester = tester.as(user.getLogin()); QualitygatesService qGateService = qGateAdminTester.qGates().service(); // perform administration operations - Qualitygates.CreateWsResponse qualityGate = qGateAdminTester.qGates().generate(); - Qualitygates.CreateConditionWsResponse condition = qGateService.createCondition(new CreateConditionRequest() + Qualitygates.CreateResponse qualityGate = qGateAdminTester.qGates().generate(); + Qualitygates.CreateConditionResponse condition = qGateService.createCondition(new CreateConditionRequest() .setGateId(String.valueOf(qualityGate.getId())).setMetric("coverage").setOp("LT").setError("90")); qGateService.updateCondition(new UpdateConditionRequest() .setId(String.valueOf(condition.getId())).setMetric("coverage").setOp("LT").setError("90").setWarning("80")); diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java index 9d7a4b52765..0baa09641a2 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java @@ -66,14 +66,14 @@ public class QualityGateUiTest { @Test public void display_alerts_correctly_in_history_page() { Project project = tester.projects().provision(); - Qualitygates.CreateWsResponse qGate = tester.qGates().generate(); + Qualitygates.CreateResponse qGate = tester.qGates().generate(); tester.qGates().associateProject(qGate, project); String firstAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -2)); String secondAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1)); // with this configuration, project should have an Orange alert - Qualitygates.CreateConditionWsResponse lowThresholds = tester.qGates().service() + Qualitygates.CreateConditionResponse lowThresholds = tester.qGates().service() .createCondition(new CreateConditionRequest().setGateId(String.valueOf(qGate.getId())).setMetric("lines").setOp("GT").setWarning("5").setError("50")); scanSampleWithDate(project, firstAnalysisDate); // with this configuration, project should have a Green alert diff --git a/tests/src/test/java/util/user/UserRule.java b/tests/src/test/java/util/user/UserRule.java index 80df9438ab6..65863a9629d 100644 --- a/tests/src/test/java/util/user/UserRule.java +++ b/tests/src/test/java/util/user/UserRule.java @@ -36,6 +36,7 @@ import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.permission.AddUserWsRequest; +import org.sonarqube.ws.client.roots.SetRootRequest; import org.sonarqube.ws.client.user.CreateRequest; import org.sonarqube.ws.client.user.SearchRequest; import org.sonarqube.ws.client.user.UsersService; @@ -152,7 +153,7 @@ public class UserRule extends ExternalResource implements GroupManagement { } public void setRoot(String login) { - adminWsClient().roots().setRoot(login); + adminWsClient().roots().setRoot(new SetRootRequest().setLogin(login)); } public Optional<util.user.Users.User> getUserByLogin(String login) { |