*/
package org.sonar.server.qualitygate.ws;
+import java.util.Collection;
+import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualitygate.QualityGateCaycChecker;
import org.sonar.server.qualitygate.QualityGateFinder;
+import org.sonar.server.qualitygate.QualityGateModeChecker;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.Qualitygates.ShowWsResponse;
@Rule
public DbTester db = DbTester.create();
private final QualityGateCaycChecker qualityGateCaycChecker = mock(QualityGateCaycChecker.class);
-
+ private final QualityGateModeChecker qualityGateModeChecker = mock(QualityGateModeChecker.class);
private final WsActionTester ws = new WsActionTester(
new ShowAction(db.getDbClient(), new QualityGateFinder(db.getDbClient()),
- new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db)), qualityGateCaycChecker));
+ new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db)), qualityGateCaycChecker, qualityGateModeChecker));
@Before
public void setUp() {
when(qualityGateCaycChecker.checkCaycCompliant(any(), any(String.class))).thenReturn(COMPLIANT);
+ when(qualityGateModeChecker.getUsageOfModeMetrics(any()))
+ .thenReturn(new QualityGateModeChecker.QualityModeResult(false, false));
}
@Test
assertEquals(COMPLIANT.toString(), response.getCaycStatus());
}
+ @Test
+ public void execute_shouldShowModeFlags() {
+ QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+ when(qualityGateModeChecker.getUsageOfModeMetrics(any(Collection.class)))
+ .thenReturn(new QualityGateModeChecker.QualityModeResult(true, true));
+ db.qualityGates().setDefaultQualityGate(qualityGate);
+
+ ShowWsResponse response = ws.newRequest()
+ .setParam("name", qualityGate.getName())
+ .executeProtobuf(ShowWsResponse.class);
+
+ Assertions.assertThat(response.getHasStandardConditions()).isTrue();
+ Assertions.assertThat(response.getHasMQRConditions()).isTrue();
+ }
+
@Test
public void show_by_name() {
QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
import org.sonar.server.qualitygate.QualityGateCaycChecker;
import org.sonar.server.qualitygate.QualityGateCaycStatus;
import org.sonar.server.qualitygate.QualityGateFinder;
+import org.sonar.server.qualitygate.QualityGateModeChecker;
import org.sonarqube.ws.Qualitygates.ShowWsResponse;
import static com.google.common.base.Preconditions.checkState;
private final QualityGateFinder qualityGateFinder;
private final QualityGatesWsSupport wsSupport;
private final QualityGateCaycChecker qualityGateCaycChecker;
+ private final QualityGateModeChecker qualityGateModeChecker;
- public ShowAction(DbClient dbClient, QualityGateFinder qualityGateFinder, QualityGatesWsSupport wsSupport, QualityGateCaycChecker qualityGateCaycChecker) {
+ public ShowAction(DbClient dbClient, QualityGateFinder qualityGateFinder, QualityGatesWsSupport wsSupport, QualityGateCaycChecker qualityGateCaycChecker,
+ QualityGateModeChecker qualityGateModeChecker) {
this.dbClient = dbClient;
this.qualityGateFinder = qualityGateFinder;
this.wsSupport = wsSupport;
this.qualityGateCaycChecker = qualityGateCaycChecker;
+ this.qualityGateModeChecker = qualityGateModeChecker;
}
@Override
.setSince("4.3")
.setResponseExample(Resources.getResource(this.getClass(), "show-example.json"))
.setChangelog(
+ new Change("10.8", "'hasMQRConditions' and 'hasStandardConditions' fields are added on quality gate"),
new Change("10.3", "'isDefault' field is added to the response"),
new Change("10.0", "Field 'id' in the response has been removed"),
new Change("10.0", "Parameter 'id' is removed. Use 'name' instead."),
Map<String, MetricDto> metricsByUuid = getMetricsByUuid(dbSession, conditions);
QualityGateDto defaultQualityGate = qualityGateFinder.getDefault(dbSession);
QualityGateCaycStatus caycStatus = qualityGateCaycChecker.checkCaycCompliant(dbSession, qualityGate.getUuid());
- writeProtobuf(buildResponse(dbSession, qualityGate, defaultQualityGate, conditions, metricsByUuid, caycStatus), request, response);
+ QualityGateModeChecker.QualityModeResult qualityModeResult = qualityGateModeChecker.getUsageOfModeMetrics(metricsByUuid.values());
+ writeProtobuf(buildResponse(dbSession, qualityGate, defaultQualityGate, conditions, metricsByUuid, caycStatus, qualityModeResult), request, response);
}
}
}
private ShowWsResponse buildResponse(DbSession dbSession, QualityGateDto qualityGate, QualityGateDto defaultQualityGate,
- Collection<QualityGateConditionDto> conditions, Map<String, MetricDto> metricsByUuid, QualityGateCaycStatus caycStatus) {
+ Collection<QualityGateConditionDto> conditions, Map<String, MetricDto> metricsByUuid, QualityGateCaycStatus caycStatus,
+ QualityGateModeChecker.QualityModeResult qualityModeResult) {
return ShowWsResponse.newBuilder()
.setName(qualityGate.getName())
.setIsBuiltIn(qualityGate.isBuiltIn())
.setIsDefault(qualityGate.getUuid().equals(defaultQualityGate.getUuid()))
.setCaycStatus(caycStatus.toString())
+ .setHasMQRConditions(qualityModeResult.hasMQRConditions())
+ .setHasStandardConditions(qualityModeResult.hasStandardConditions())
.addAllConditions(conditions.stream()
.map(toWsCondition(metricsByUuid))
.toList())