mapper(dbSession).insertOrgQualityGate(uuid, organization.getUuid(), qualityGate.getUuid());
}
- public Collection<QualityGateDto> selectAll(DbSession session) {
- return mapper(session).selectAll();
+ public Collection<QualityGateDto> selectAll(DbSession session, OrganizationDto organization) {
+ return mapper(session).selectAll(organization.getUuid());
}
@CheckForNull
void insertOrgQualityGate(@Param("uuid") String uuid, @Param("organizationUuid") String organizationUuid, @Param("qualityGateUuid") String qualityGateUuuid);
- List<QualityGateDto> selectAll();
+ List<QualityGateDto> selectAll(@Param("organizationUuid") String organizationUuid);
QualityGateDto selectByName(String name);
VALUES (#{uuid, jdbcType=VARCHAR}, #{organizationUuid, jdbcType=VARCHAR}, #{qualityGateUuid, jdbcType=VARCHAR})
</insert>
- <select id="selectAll" resultType="QualityGate">
- select
- <include refid="gateColumns"/>
- from quality_gates
- order by name asc
+ <select id="selectAll" resultType="org.sonar.db.qualitygate.QGateWithOrgDto">
+ SELECT
+ <include refid="qateWithOrgColumns"/>
+ FROM quality_gates qg
+ INNER JOIN
+ org_quality_gates oqg ON oqg.quality_gate_uuid = qg.uuid AND oqg.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
+ ORDER BY qg.name ASC
</select>
<select id="selectByName" parameterType="String" resultType="QualityGate">
*/
package org.sonar.db.qualitygate;
+import java.util.Date;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.groups.Tuple.tuple;
public class QualityGateDaoTest {
private QualityGateDao underTest = db.getDbClient().qualityGateDao();
@Test
- public void testInsert() {
- QualityGateDto newQgate = new QualityGateDto().setName("My Quality Gate").setUuid(Uuids.createFast());
+ public void insert() {
+ QualityGateDto newQgate = new QualityGateDto()
+ .setUuid(Uuids.createFast())
+ .setName("My Quality Gate")
+ .setBuiltIn(false)
+ .setUpdatedAt(new Date());
underTest.insert(dbSession, newQgate);
dbSession.commit();
- assertThat(underTest.selectAll(dbSession)).extracting(QualityGateDto::getName, QualityGateDto::isBuiltIn)
- .containsExactlyInAnyOrder(
- // TODO : tuple("Sonar way", true),
- tuple("My Quality Gate", false));
- assertThat(newQgate.getId()).isNotNull();
+ QualityGateDto reloaded = underTest.selectById(dbSession, newQgate.getId());
+ assertThat(reloaded.getName()).isEqualTo("My Quality Gate");
+ assertThat(reloaded.getUuid()).isEqualTo(newQgate.getUuid());
+ assertThat(reloaded.isBuiltIn()).isFalse();
+ assertThat(reloaded.getCreatedAt()).isNotNull();
+ assertThat(reloaded.getUpdatedAt()).isNotNull();
}
@Test
}
@Test
- public void testSelectAll() {
- insertQualityGates();
-
- assertThat(underTest.selectAll(dbSession)).extracting(QualityGateDto::getName, QualityGateDto::isBuiltIn)
- .containsExactlyInAnyOrder(
- // TODO : tuple("Sonar Way", true),
- tuple("Balanced", false),
- tuple("Lenient", false),
- tuple("Very strict", false));
+ public void select_all() {
+ OrganizationDto organization1 = db.organizations().insert();
+ OrganizationDto organization2 = db.organizations().insert();
+ QGateWithOrgDto qualityGate1 = qualityGateDbTester.insertQualityGate(organization1);
+ QGateWithOrgDto qualityGate2 = qualityGateDbTester.insertQualityGate(organization1);
+ QGateWithOrgDto qualityGateOnOtherOrg = qualityGateDbTester.insertQualityGate(organization2);
+
+ assertThat(underTest.selectAll(dbSession, organization1))
+ .extracting(QualityGateDto::getUuid)
+ .containsExactlyInAnyOrder(qualityGate1.getUuid(), qualityGate2.getUuid());
}
@Test
}
@Test
- public void testDelete() {
- insertQualityGates();
+ public void delete() {
+ OrganizationDto organization = db.organizations().insert();
+ QGateWithOrgDto qualityGate = qualityGateDbTester.insertQualityGate(organization);
+ QGateWithOrgDto otherQualityGate = qualityGateDbTester.insertQualityGate(organization);
- underTest.delete(underTest.selectByName(dbSession, "Very strict"), dbSession);
+ underTest.delete(qualityGate, dbSession);
dbSession.commit();
- assertThat(underTest.selectAll(dbSession)).extracting(QualityGateDto::getName, QualityGateDto::isBuiltIn)
- .containsExactlyInAnyOrder(
- // TODO : tuple("Sonar Way", true),
- tuple("Balanced", false),
- tuple("Lenient", false));
+ assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull();
+ assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, otherQualityGate.getUuid())).isNotNull();
}
@Test
- public void testUpdate() {
- insertQualityGates();
+ public void update() {
+ OrganizationDto organization = db.organizations().insert();
+ QGateWithOrgDto qualityGate = qualityGateDbTester.insertQualityGate(organization, qg -> qg.setName("old name"));
- underTest.update(underTest.selectByName(dbSession, "Very strict").setName("Not so strict"), dbSession);
+ underTest.update(qualityGate.setName("Not so strict"), dbSession);
dbSession.commit();
- assertThat(underTest.selectAll(dbSession)).extracting(QualityGateDto::getName, QualityGateDto::isBuiltIn)
- .containsExactlyInAnyOrder(
- // TODO : tuple("Sonar Way", true),
- tuple("Balanced", false),
- tuple("Lenient", false),
- tuple("Not so strict", false));
+ QGateWithOrgDto reloaded = underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid());
+ assertThat(reloaded.getName()).isEqualTo("Not so strict");
}
private void insertQualityGates() {
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.server.qualitygate.QualityGateFinder;
import org.sonarqube.ws.Qualitygates.ListWsResponse;
@Override
public void define(WebService.NewController controller) {
- controller.createAction("list")
+ WebService.NewAction action = controller.createAction("list")
.setDescription("Get a list of quality gates")
.setSince("4.3")
.setResponseExample(Resources.getResource(this.getClass(), "list-example.json"))
new Change("7.0", "'isBuiltIn' field is added in the response"),
new Change("7.0", "'actions' fields are added in the response"))
.setHandler(this);
+ wsSupport.createOrganizationParam(action);
}
@Override
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
+ OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
Optional<QualityGateDto> defaultQualityGate = finder.getDefault(dbSession);
- Collection<QualityGateDto> qualityGates = dbClient.qualityGateDao().selectAll(dbSession);
- writeProtobuf(buildResponse(qualityGates, defaultQualityGate.orElse(null)), request, response);
+ Collection<QualityGateDto> qualityGates = dbClient.qualityGateDao().selectAll(dbSession, organization);
+ writeProtobuf(buildResponse(organization, qualityGates, defaultQualityGate.orElse(null)), request, response);
}
}
- private ListWsResponse buildResponse(Collection<QualityGateDto> qualityGates, @Nullable QualityGateDto defaultQualityGate) {
+ private ListWsResponse buildResponse(OrganizationDto organization, Collection<QualityGateDto> qualityGates, @Nullable QualityGateDto defaultQualityGate) {
Long defaultId = defaultQualityGate == null ? null : defaultQualityGate.getId();
ListWsResponse.Builder builder = ListWsResponse.newBuilder()
- .setActions(ListWsResponse.RootActions.newBuilder().setCreate(wsSupport.isQualityGateAdmin()))
+ .setActions(ListWsResponse.RootActions.newBuilder().setCreate(wsSupport.isQualityGateAdmin(organization)))
.addAllQualitygates(qualityGates.stream()
.map(qualityGate -> QualityGate.newBuilder()
.setId(qualityGate.getId())
.setName(qualityGate.getName())
.setIsDefault(qualityGate.getId().equals(defaultId))
.setIsBuiltIn(qualityGate.isBuiltIn())
- .setActions(wsSupport.getActions(qualityGate, defaultQualityGate))
+ .setActions(wsSupport.getActions(organization, qualityGate, defaultQualityGate))
.build())
.collect(toList()));
setNullable(defaultId, builder::setDefault);
return checkFound(dbClient.gateConditionDao().selectById(id, dbSession), "No quality gate condition with id '%d'", id);
}
- /**
- * @deprecated use {@link #isQualityGateAdmin(OrganizationDto)} instead
- */
- @Deprecated
- boolean isQualityGateAdmin() {
- return userSession.hasPermission(ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid());
- }
-
boolean isQualityGateAdmin(OrganizationDto organization) {
return userSession.hasPermission(ADMINISTER_QUALITY_GATES, organization);
}
.setExampleValue("my-org");
}
- /**
- * @deprecated use {@link #getActions(OrganizationDto, QualityGateDto, QualityGateDto)} instead
- */
- @Deprecated
- Qualitygates.Actions getActions(QualityGateDto qualityGate, @Nullable QualityGateDto defaultQualityGate) {
- Long defaultId = defaultQualityGate == null ? null : defaultQualityGate.getId();
- boolean isDefault = qualityGate.getId().equals(defaultId);
- boolean isBuiltIn = qualityGate.isBuiltIn();
- boolean isQualityGateAdmin = isQualityGateAdmin();
- return Qualitygates.Actions.newBuilder()
- .setCopy(isQualityGateAdmin)
- .setRename(!isBuiltIn && isQualityGateAdmin)
- .setManageConditions(!isBuiltIn && isQualityGateAdmin)
- .setDelete(!isDefault && !isBuiltIn && isQualityGateAdmin)
- .setSetAsDefault(!isDefault && isQualityGateAdmin)
- .setAssociateProjects(!isDefault && isQualityGateAdmin)
- .build();
- }
-
Qualitygates.Actions getActions(OrganizationDto organization, QualityGateDto qualityGate, @Nullable QualityGateDto defaultQualityGate) {
Long defaultId = defaultQualityGate == null ? null : defaultQualityGate.getId();
boolean isDefault = qualityGate.getId().equals(defaultId);
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.core.util.Uuids;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
verifyCorrectBuiltInQualityGate();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been created")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been created")).isTrue();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue();
}
@Test
dbSession.commit();
underTest.start();
- assertThat(qualityGateDao.selectAll(dbSession)).hasSize(1);
+ assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1);
verifyCorrectBuiltInQualityGate();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue();
}
@Test
dbSession.commit();
underTest.start();
- assertThat(qualityGateDao.selectAll(dbSession)).hasSize(1);
+ assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1);
verifyCorrectBuiltInQualityGate();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue();
}
@Test
dbSession.commit();
underTest.start();
- assertThat(qualityGateDao.selectAll(dbSession)).hasSize(1);
+ assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1);
verifyCorrectBuiltInQualityGate();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue();
}
@Test
dbSession.commit();
underTest.start();
- assertThat(qualityGateDao.selectAll(dbSession)).hasSize(1);
+ assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1);
verifyCorrectBuiltInQualityGate();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Quality gate [Sonar way] has been set as built-in")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Quality gate [Sonar way] has been set as built-in")).isTrue();
}
@Test
dbSession.commit();
underTest.start();
- assertThat(qualityGateDao.selectAll(dbSession)).hasSize(1);
+ assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1);
verifyCorrectBuiltInQualityGate();
// Log must not be present
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Quality gate [Sonar way] has been set as built-in")
- ).isFalse();
+ logTester.logs(LoggerLevel.INFO).contains("Quality gate [Sonar way] has been set as built-in")).isFalse();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been created")
- ).isFalse();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been created")).isFalse();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isFalse();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isFalse();
}
@Test
assertThat(oldQualityGate).isNotNull();
assertThat(oldQualityGate.isBuiltIn()).isFalse();
- List<QualityGateDto> allBuiltInQualityProfiles = qualityGateDao.selectAll(dbSession)
- .stream()
- .filter(QualityGateDto::isBuiltIn)
- .collect(MoreCollectors.toList());
- assertThat(allBuiltInQualityProfiles)
- .extracting("name")
+ assertThat(db.select("select name as \"name\" from quality_gates where is_built_in is true"))
+ .extracting(column -> column.get("name"))
.containsExactly(BUILT_IN_NAME);
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been created")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been created")).isTrue();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue();
}
@Test
assertThat(qualityGateFinder.getDefault(dbSession).get().getId()).isEqualTo(builtin.getId());
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been set as default")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate [Sonar way] has been set as default")).isTrue();
}
@Test
.setOperator(OPERATOR_GREATER_THAN)
.setErrorThreshold("1")
.setWarningThreshold("1");
- gateConditionDao.insert(conditionDto,dbSession);
+ gateConditionDao.insert(conditionDto, dbSession);
dbSession.commit();
underTest.start();
verifyCorrectBuiltInQualityGate();
assertThat(
- logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")
- ).isTrue();
+ logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue();
}
private void insertMetrics() {
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.qualitygate.QGateWithOrgDto;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
private DbClient dbClient = db.getDbClient();
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
+
private WsActionTester ws = new WsActionTester(new ListAction(db.getDbClient(),
new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider), qualityGateFinder));
tuple("7.0", "'default' field on root level is deprecated"),
tuple("7.0", "'isBuiltIn' field is added in the response"),
tuple("7.0", "'actions' fields are added in the response"));
- assertThat(action.params()).isEmpty();
+ assertThat(action.params()).extracting(WebService.Param::key, WebService.Param::isRequired)
+ .containsExactlyInAnyOrder(tuple("organization", false));
}
@Test
public void json_example() {
- userSession.logIn("admin").addPermission(ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid());
- QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setName("Sonar way").setBuiltIn(true));
- db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setName("Sonar way - Without Coverage").setBuiltIn(false));
+ OrganizationDto organization = db.organizations().insert();
+ userSession.logIn("admin").addPermission(ADMINISTER_QUALITY_GATES, organization);
+ QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization, qualityGate -> qualityGate.setName("Sonar way").setBuiltIn(true));
+ db.qualityGates().insertQualityGate(organization, qualityGate -> qualityGate.setName("Sonar way - Without Coverage").setBuiltIn(false));
db.qualityGates().setDefaultQualityGate(defaultQualityGate);
String response = ws.newRequest()
+ .setParam("organization", organization.getKey())
.execute()
.getInput();
@Test
public void list_quality_gates() {
- QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate("Sonar way");
- QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate("Sonar way - Without Coverage");
+ OrganizationDto organization = db.organizations().insert();
+ QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization);
+ QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(organization);
db.qualityGates().setDefaultQualityGate(defaultQualityGate);
- ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
assertThat(response.getQualitygatesList())
.extracting(QualityGate::getId, QualityGate::getName, QualityGate::getIsDefault)
}
@Test
- public void test_built_in_flag() {
- QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setBuiltIn(true));
- QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setBuiltIn(false));
+ public void default_organization_is_used_when_no_organization_parameter() {
+ QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+ OrganizationDto otherOrganization = db.organizations().insert();
+ QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ assertThat(response.getQualitygatesList())
+ .extracting(QualityGate::getId)
+ .containsExactlyInAnyOrder(qualityGate.getId());
+ }
+
+ @Test
+ public void test_built_in_flag() {
+ OrganizationDto organization = db.organizations().insert();
+ QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(organization, qualityGate -> qualityGate.setBuiltIn(true));
+ QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(organization, qualityGate -> qualityGate.setBuiltIn(false));
+
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
+
assertThat(response.getQualitygatesList())
.extracting(QualityGate::getId, QualityGate::getIsBuiltIn)
.containsExactlyInAnyOrder(
@Test
public void test_deprecated_default_field() {
- QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate("Sonar way");
+ OrganizationDto organization = db.organizations().insert();
+ QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization);
db.qualityGates().setDefaultQualityGate(defaultQualityGate);
- ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
assertThat(response.getDefault()).isEqualTo(defaultQualityGate.getId());
}
@Test
public void no_default_quality_gate() {
- QualityGateDto qualityGate = db.qualityGates().insertQualityGate("Sonar way");
+ OrganizationDto organization = db.organizations().insert();
+ QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
- ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
assertThat(response.getQualitygatesList())
.extracting(QualityGate::getId, QualityGate::getName, QualityGate::getIsDefault)
@Test
public void actions_with_quality_gate_administer_permission() {
- userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid());
- QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Default").setBuiltIn(false));
- QualityGateDto builtInQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way").setBuiltIn(true));
- QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way - Without Coverage").setBuiltIn(false));
+ OrganizationDto organization = db.organizations().insert();
+ userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES, organization);
+ QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("Default").setBuiltIn(false));
+ QualityGateDto builtInQualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("Sonar way").setBuiltIn(true));
+ QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("Sonar way - Without Coverage").setBuiltIn(false));
db.qualityGates().setDefaultQualityGate(defaultQualityGate);
- ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
assertThat(response.getActions())
.extracting(ListWsResponse.RootActions::getCreate)
@Test
public void actions_without_quality_gate_administer_permission() {
- userSession.logIn("john").addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
- QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way").setBuiltIn(true));
- QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way - Without Coverage").setBuiltIn(false));
+ OrganizationDto organization = db.organizations().insert();
+ userSession.logIn("john").addPermission(ADMINISTER_QUALITY_PROFILES, organization);
+ QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("Sonar way").setBuiltIn(true));
+ QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("Sonar way - Without Coverage").setBuiltIn(false));
db.qualityGates().setDefaultQualityGate(defaultQualityGate);
- ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
assertThat(response.getActions())
.extracting(ListWsResponse.RootActions::getCreate)
@Test
public void empty() {
- ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
+ OrganizationDto organization = db.organizations().insert();
+
+ ListWsResponse response = ws.newRequest()
+ .setParam("organization", organization.getKey())
+ .executeProtobuf(ListWsResponse.class);
assertThat(response.getQualitygatesList()).isEmpty();
}