]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10134 Add organization parameter in api/qualitygates/list
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 4 Dec 2017 15:51:34 +0000 (16:51 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 14 Dec 2017 16:03:35 +0000 (17:03 +0100)
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java

index 11a5a704ca2d03f3ad71a2802060211cf2ec7503..4c109c56ba979665bae29f75b5b21b82e1902faf 100644 (file)
@@ -38,8 +38,8 @@ public class QualityGateDao implements Dao {
     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
index e60464e237cbcae475f58545d6aa23d2fdcd97f3..4d2d37058a587b34784063fb956c0048c5419acf 100644 (file)
@@ -28,7 +28,7 @@ public interface QualityGateMapper {
 
   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);
 
index ad1cedba967680836c3b601c4df162d8a99c04da..ef19f754d5311b2d6cf9fd71b03e6c0da2ff923f 100644 (file)
     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">
index bf0be78d83da9c2476cdbb774eb4b900e3c20705..0ff216bb7e6270a4f282f58dffc6572c3773d316 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.db.qualitygate;
 
+import java.util.Date;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
@@ -28,7 +29,6 @@ import org.sonar.db.DbTester;
 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 {
 
@@ -40,17 +40,22 @@ 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
@@ -76,15 +81,16 @@ public class QualityGateDaoTest {
   }
 
   @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
@@ -127,32 +133,28 @@ public class QualityGateDaoTest {
   }
 
   @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() {
index e33623c5fd4ca083c7586d4960e5462be79f770b..64d341bfb52e662b91a7a5679fe2111034872142 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.server.ws.Response;
 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;
@@ -52,7 +53,7 @@ public class ListAction implements QualityGatesWsAction {
 
   @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"))
@@ -62,28 +63,30 @@ public class ListAction implements QualityGatesWsAction {
         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);
index 3c190e4c089776abe2d56e61be1df4fff9f10678..ce367c78c821b06e041391dc9b3053e4efe5cf6a 100644 (file)
@@ -56,14 +56,6 @@ public class QualityGatesWsSupport {
     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);
   }
@@ -78,25 +70,6 @@ public class QualityGatesWsSupport {
       .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);
index 9b11e2c39dd9128ecc2656581b4fec45e26f4b9a..a4976339c72484bc90e9cc772cf26d5f640f0344 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.api.utils.log.LogTester;
 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;
@@ -96,11 +95,9 @@ public class RegisterQualityGatesTest {
     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
@@ -110,12 +107,11 @@ public class RegisterQualityGatesTest {
     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
@@ -132,11 +128,10 @@ public class RegisterQualityGatesTest {
     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
@@ -153,12 +148,11 @@ public class RegisterQualityGatesTest {
     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
@@ -170,12 +164,11 @@ public class RegisterQualityGatesTest {
     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
@@ -187,19 +180,16 @@ public class RegisterQualityGatesTest {
     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
@@ -215,20 +205,14 @@ public class RegisterQualityGatesTest {
     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
@@ -243,8 +227,7 @@ public class RegisterQualityGatesTest {
     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
@@ -256,7 +239,7 @@ public class RegisterQualityGatesTest {
       .setOperator(OPERATOR_GREATER_THAN)
       .setErrorThreshold("1")
       .setWarningThreshold("1");
-    gateConditionDao.insert(conditionDto,dbSession);
+    gateConditionDao.insert(conditionDto, dbSession);
     dbSession.commit();
 
     underTest.start();
@@ -265,8 +248,7 @@ public class RegisterQualityGatesTest {
     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() {
index edc04d97103dd746197c0eea0bf9997b7425312f..21639462b2f83459416af7a050f1ba0de2634832 100644 (file)
@@ -27,6 +27,8 @@ import org.sonar.api.server.ws.Change;
 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;
@@ -54,6 +56,7 @@ public class ListActionTest {
   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));
 
@@ -70,17 +73,20 @@ public class ListActionTest {
         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();
 
@@ -90,11 +96,14 @@ public class ListActionTest {
 
   @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)
@@ -104,12 +113,28 @@ public class ListActionTest {
   }
 
   @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(
@@ -119,19 +144,25 @@ public class ListActionTest {
 
   @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)
@@ -140,13 +171,16 @@ public class ListActionTest {
 
   @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)
@@ -163,12 +197,15 @@ public class ListActionTest {
 
   @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)
@@ -184,7 +221,11 @@ public class ListActionTest {
 
   @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();
   }