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;
.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()));
}
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 {
@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()
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;
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;
.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)
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);
}
}
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;
.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
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();
}
}
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;
}
}
- 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()))
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;
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);
"<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)
^ !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();
}
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;
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();
}
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);
return;
}
- ProjectStatusWsResponse.Period.Builder periodBuilder = ProjectStatusWsResponse.Period.newBuilder();
+ ProjectStatusResponse.Period.Builder periodBuilder = ProjectStatusResponse.Period.newBuilder();
periodBuilder.clear();
SnapshotDto snapshot = this.optionalSnapshot.get();
}
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);
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;
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;
}
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;
}
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() {
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;
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();
}
}
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;
}
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) {
--- /dev/null
+{
+ "id": 1,
+ "metric": "blocker_violations",
+ "op": "LT",
+ "error": "10",
+ "warning": "5"
+}
--- /dev/null
+{
+ "id": 1,
+ "name": "My Quality Gate"
+}
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;
.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");
.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();
}
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");
}
.setHidden(false));
dbSession.commit();
- AppWsResponse response = executeRequest();
+ AppResponse response = executeRequest();
assertThat(response.getMetricsList()).isEmpty();
}
.setHidden(false));
dbSession.commit();
- AppWsResponse response = executeRequest();
+ AppResponse response = executeRequest();
assertThat(response.getMetricsList()).isEmpty();
}
.setHidden(false));
dbSession.commit();
- AppWsResponse response = executeRequest();
+ AppResponse response = executeRequest();
assertThat(response.getMetricsList()).isEmpty();
}
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();
}
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();
}
dbSession.commit();
}
- private AppWsResponse executeRequest() {
- return ws.newRequest().executeProtobuf(AppWsResponse.class);
+ private AppResponse executeRequest() {
+ return ws.newRequest().executeProtobuf(AppResponse.class);
}
}
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;
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();
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() {
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;
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);
}
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);
}
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);
}
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);
}
}
- 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))
if (period != null) {
request.setParam(PARAM_PERIOD, Integer.toString(period));
}
- return request.executeProtobuf(CreateConditionWsResponse.class);
+ return request.executeProtobuf(CreateConditionResponse.class);
}
private void logInAsQualityGateAdmin() {
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;
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());
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());
associateProjectToQualityGate(project.getId(), dbQualityGate.getId());
logInAsProjectUser(project);
- GetByProjectWsResponse result = callByKey(project.getDbKey());
+ GetByProjectResponse result = callByKey(project.getDbKey());
assertThat(result.getQualityGate().getName()).isEqualTo(dbQualityGate.getName());
}
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());
}
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());
}
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) {
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;
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);
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);
.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() {
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;
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");
// 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");
// 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");
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;
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);
}
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);
}
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);
}
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);
}
}
- 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))
if (period != null) {
request.setParam(PARAM_PERIOD, Integer.toString(period));
}
- return request.executeProtobuf(CreateConditionWsResponse.class);
+ return request.executeProtobuf(CreateConditionResponse.class);
}
private void logInAsQualityGateAdmin() {
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;
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();
dbSession.commit();
assertThat(executeRequest())
- .extracting(Root.RootContent::getName)
+ .extracting(Roots.RootContent::getName)
.containsExactly("bbb", "ccc");
}
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();
}
*/
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
/**
* 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;
/**
* 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;
}
/**
- * 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.
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.
*/
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.
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;
* @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());
}
/**
* @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());
}
/**
* @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())
.setParam("op", request.getOp())
.setParam("period", request.getPeriod())
.setParam("warning", request.getWarning()),
- CreateConditionWsResponse.parser());
+ CreateConditionResponse.parser());
}
/**
* @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());
}
/**
* @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());
}
/**
.setParam("op", request.getOp())
.setParam("period", request.getPeriod())
.setParam("warning", request.getWarning()),
- UpdateConditionWsResponse.parser());
+ UpdateConditionResponse.parser());
}
}
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
* @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());
}
/**
option optimize_for = SPEED;
// GET api/qualitygates/project_status
-message ProjectStatusWsResponse {
+message ProjectStatusResponse {
optional ProjectStatus projectStatus = 1;
message ProjectStatus {
}
// GET api/qualitygates/get_by_project
-message GetByProjectWsResponse {
+message GetByProjectResponse {
optional QualityGate qualityGate = 1;
}
}
// GET api/qualitygates/app
-message AppWsResponse {
+message AppResponse {
optional bool edit = 1;
repeated Metric metrics = 3;
}
// 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;
}
// POST api/qualitygates/update_condition
-message UpdateConditionWsResponse {
+message UpdateConditionResponse {
optional int64 id = 1;
optional string metric = 2;
optional string op = 3;
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;
}
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;
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;
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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;
-
+++ /dev/null
-/*
- * 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();
- }
-}
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 {
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
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;
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());
}
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;
@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
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()));
}
}
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;
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")
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;
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()))
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()))
.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();
@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()))
@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()
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;
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 {
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"));
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"));
@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
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;
}
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) {