]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13999 drop organization from QualityGate WS
authorJacek <jacek.poreda@sonarsource.com>
Tue, 15 Dec 2020 08:05:56 +0000 (09:05 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Dec 2020 20:09:37 +0000 (20:09 +0000)
62 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateService.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationQuery.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/DbVersion87.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalProperties.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalPropertiesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalPropertiesTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateFinder.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateFinderTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputer.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CopyAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeleteConditionAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsParameters.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/RenameAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SetAsDefaultAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/package-info.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RenameActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SetAsDefaultActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java

index aa02034c48cbd31f4cae4715667527278becffb8..7cee09fb0c7776c50b13dc937fbd560cd9a1f722 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.ce.task.projectanalysis.qualitygate;
 
 import java.util.Optional;
-import org.sonar.ce.task.projectanalysis.analysis.Organization;
 import org.sonar.server.project.Project;
 
 public interface QualityGateService {
@@ -31,10 +30,10 @@ public interface QualityGateService {
   Optional<QualityGate> findByUuid(String uuid);
 
   /**
-   * Retrieve the {@link QualityGate} from the database using organization.
+   * Retrieve the {@link QualityGate} from the database.
    * @throws IllegalStateException if database is corrupted and default gate can't be found.
    */
-  QualityGate findDefaultQualityGate(Organization organizationDto);
+  QualityGate findDefaultQualityGate();
 
   /**
    * Retrieve the {@link QualityGate} from the database associated with project.
index b86fc56d1e5e8eccd4d882f5859fce12b4c52c11..3774b3e2b68c38b698c447a97348200af4b845a2 100644 (file)
@@ -22,10 +22,10 @@ package org.sonar.ce.task.projectanalysis.qualitygate;
 import java.util.Collection;
 import java.util.Objects;
 import java.util.Optional;
-import org.sonar.ce.task.projectanalysis.analysis.Organization;
 import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.property.PropertyDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.project.Project;
@@ -33,6 +33,7 @@ import org.sonar.server.project.Project;
 import static org.sonar.core.util.stream.MoreCollectors.toList;
 
 public class QualityGateServiceImpl implements QualityGateService {
+  private static final String DEFAULT_QUALITY_GATE_PROPERTY_NAME = "qualitygate.default";
 
   private final DbClient dbClient;
   private final MetricRepository metricRepository;
@@ -54,16 +55,24 @@ public class QualityGateServiceImpl implements QualityGateService {
   }
 
   @Override
-  public QualityGate findDefaultQualityGate(Organization organization) {
+  public QualityGate findDefaultQualityGate() {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization.toDto(), organization.getDefaultQualityGateUuid());
+      QualityGateDto qualityGateDto = getDefaultQualityGate(dbSession);
       if (qualityGateDto == null) {
-        throw new IllegalStateException("The default Quality gate is missing on organization " + organization.getKey());
+        throw new IllegalStateException("The default Quality gate is missing");
       }
       return toQualityGate(dbSession, qualityGateDto);
     }
   }
 
+  private QualityGateDto getDefaultQualityGate(DbSession dbSession) {
+    PropertyDto propertyDto = Optional.ofNullable(dbClient.propertiesDao()
+      .selectGlobalProperty(dbSession, DEFAULT_QUALITY_GATE_PROPERTY_NAME))
+      .orElseThrow(() -> new IllegalStateException("The default Quality Gate property is missing"));
+    return Optional.ofNullable(dbClient.qualityGateDao().selectByUuid(dbSession, propertyDto.getValue()))
+      .orElseThrow(() -> new IllegalStateException("The default Quality gate is missing"));
+  }
+
   @Override
   public Optional<QualityGate> findQualityGate(Project project) {
     try (DbSession dbSession = dbClient.openSession(false)) {
index fca307772a6b1d445c832d97e3581ea798ab99dc..0f2616f5128c4953f54722743786e8356803b38e 100644 (file)
@@ -50,8 +50,8 @@ public class LoadQualityGateStep implements ComputationStep {
   public void execute(ComputationStep.Context context) {
     Optional<QualityGate> qualityGate = getProjectQualityGate();
     if (!qualityGate.isPresent()) {
-      // No QG defined for the project, let's retrieve the QG on the organization
-      qualityGate = Optional.of(getOrganizationDefaultQualityGate());
+      // No QG defined for the project, let's retrieve the default QG
+      qualityGate = Optional.of(getDefaultQualityGate());
     }
 
     if (analysisMetadataHolder.isPullRequest()) {
@@ -71,8 +71,8 @@ public class LoadQualityGateStep implements ComputationStep {
     return qualityGateService.findQualityGate(project);
   }
 
-  private QualityGate getOrganizationDefaultQualityGate() {
-    return qualityGateService.findDefaultQualityGate(analysisMetadataHolder.getOrganization());
+  private QualityGate getDefaultQualityGate() {
+    return qualityGateService.findDefaultQualityGate();
   }
 
   @Override
index 50dbc1fc22100edcf23513da89abf06dc43928a7..2a32693650bbe9618eee3f3fc0d4bf9a75b14949 100644 (file)
@@ -24,11 +24,11 @@ import java.util.Collections;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.ce.task.projectanalysis.analysis.Organization;
 import org.sonar.ce.task.projectanalysis.metric.Metric;
 import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
 import org.sonar.db.DbClient;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
+import org.sonar.db.property.PropertiesDao;
+import org.sonar.db.property.PropertyDto;
 import org.sonar.db.qualitygate.QualityGateConditionDao;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDao;
@@ -54,16 +54,18 @@ public class QualityGateServiceImplTest {
   private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricUuid(METRIC_UUID_2).setOperator("GT")
     .setErrorThreshold("error_th");
 
-  private QualityGateDao qualityGateDao = mock(QualityGateDao.class);
-  private QualityGateConditionDao qualityGateConditionDao = mock(QualityGateConditionDao.class);
-  private MetricRepository metricRepository = mock(MetricRepository.class);
-  private DbClient dbClient = mock(DbClient.class);
-  private QualityGateServiceImpl underTest = new QualityGateServiceImpl(dbClient, metricRepository);
+  private final QualityGateDao qualityGateDao = mock(QualityGateDao.class);
+  private final QualityGateConditionDao qualityGateConditionDao = mock(QualityGateConditionDao.class);
+  private final PropertiesDao propertiesDao = mock(PropertiesDao.class);
+  private final MetricRepository metricRepository = mock(MetricRepository.class);
+  private final DbClient dbClient = mock(DbClient.class);
+  private final QualityGateServiceImpl underTest = new QualityGateServiceImpl(dbClient, metricRepository);
 
   @Before
   public void setUp() {
     when(dbClient.qualityGateDao()).thenReturn(qualityGateDao);
     when(dbClient.gateConditionDao()).thenReturn(qualityGateConditionDao);
+    when(dbClient.propertiesDao()).thenReturn(propertiesDao);
 
     when(METRIC_1.getKey()).thenReturn("metric");
     when(METRIC_2.getKey()).thenReturn("new_metric");
@@ -123,23 +125,25 @@ public class QualityGateServiceImplTest {
   }
 
   @Test(expected = IllegalStateException.class)
-  public void findDefaultQualityGate_by_organization_not_found() {
-    when(qualityGateDao.selectByOrganizationAndUuid(any(), any(), any())).thenReturn(null);
+  public void findDefaultQualityGate_by_property_not_found() {
+    when(propertiesDao.selectGlobalProperty(any(), any())).thenReturn(null);
 
-    underTest.findDefaultQualityGate(mock(Organization.class));
+    underTest.findDefaultQualityGate();
   }
 
   @Test
-  public void findDefaultQualityGate_by_organization_found() {
-    QGateWithOrgDto qGateWithOrgDto = new QGateWithOrgDto();
-    qGateWithOrgDto.setUuid(QUALITY_GATE_DTO.getUuid());
-    qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName());
-    when(qualityGateDao.selectByOrganizationAndUuid(any(), any(), any())).thenReturn(qGateWithOrgDto);
+  public void findDefaultQualityGate_by_property_found() {
+    QualityGateDto qualityGateDto = new QualityGateDto();
+    qualityGateDto.setUuid(QUALITY_GATE_DTO.getUuid());
+    qualityGateDto.setName(QUALITY_GATE_DTO.getName());
+    when(propertiesDao.selectGlobalProperty(any(), any())).thenReturn(new PropertyDto().setValue(QUALITY_GATE_DTO.getUuid()));
+
+    when(qualityGateDao.selectByUuid(any(), any())).thenReturn(qualityGateDto);
     when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
     when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
     when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
 
-    QualityGate result = underTest.findDefaultQualityGate(mock(Organization.class));
+    QualityGate result = underTest.findDefaultQualityGate();
 
     assertThat(result).isNotNull();
     assertThat(result.getUuid()).isEqualTo(QUALITY_GATE_DTO.getUuid());
@@ -156,10 +160,10 @@ public class QualityGateServiceImplTest {
 
   @Test
   public void findQualityGate_by_project_found() {
-    QGateWithOrgDto qGateWithOrgDto = new QGateWithOrgDto();
-    qGateWithOrgDto.setUuid(QUALITY_GATE_DTO.getUuid());
-    qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName());
-    when(qualityGateDao.selectByProjectUuid(any(), any())).thenReturn(qGateWithOrgDto);
+    QualityGateDto qualityGateDto = new QualityGateDto();
+    qualityGateDto.setUuid(QUALITY_GATE_DTO.getUuid());
+    qualityGateDto.setName(QUALITY_GATE_DTO.getName());
+    when(qualityGateDao.selectByProjectUuid(any(), any())).thenReturn(qualityGateDto);
     when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
     when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
     when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
index ea942fb5a1219bec74ff7bfed6728f647b327170..2b399921f9da515ae0055e3ea57b233d70d296bc 100644 (file)
@@ -49,10 +49,10 @@ public class LoadQualityGateStepTest {
   @Rule
   public MutableQualityGateHolderRule mutableQualityGateHolder = new MutableQualityGateHolderRule();
 
-  private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
-  private QualityGateService qualityGateService = mock(QualityGateService.class);
+  private final AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
+  private final QualityGateService qualityGateService = mock(QualityGateService.class);
 
-  private LoadQualityGateStep underTest = new LoadQualityGateStep(qualityGateService, mutableQualityGateHolder, analysisMetadataHolder);
+  private final LoadQualityGateStep underTest = new LoadQualityGateStep(qualityGateService, mutableQualityGateHolder, analysisMetadataHolder);
 
   @Before
   public void setUp() {
@@ -68,7 +68,7 @@ public class LoadQualityGateStepTest {
 
     when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
     QualityGate defaultGate = new QualityGate("1", "qg", Arrays.asList(variation, condition));
-    when(qualityGateService.findDefaultQualityGate(any(Organization.class))).thenReturn(defaultGate);
+    when(qualityGateService.findDefaultQualityGate()).thenReturn(defaultGate);
 
     underTest.execute(new TestComputationStepContext());
 
@@ -78,7 +78,7 @@ public class LoadQualityGateStepTest {
   @Test
   public void execute_sets_default_QualityGate_when_project_has_no_settings() {
     QualityGate defaultGate = mock(QualityGate.class);
-    when(qualityGateService.findDefaultQualityGate(any(Organization.class))).thenReturn(defaultGate);
+    when(qualityGateService.findDefaultQualityGate()).thenReturn(defaultGate);
 
     underTest.execute(new TestComputationStepContext());
 
index 0fdbd59b05464204f10e543c0e6c99b0e15b391a..9ed7907c22c9b033f4a55572f45fa134a945ce18 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.db.Pagination;
 import org.sonar.db.alm.ALM;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.permission.template.DefaultTemplates;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.user.GroupDto;
 
 import static java.util.Objects.requireNonNull;
@@ -120,10 +119,6 @@ public class OrganizationDao implements Dao {
     getMapper(dbSession).updateDefaultGroupUuid(uuid, requireNonNull(defaultGroupUuid, "Default group uuid cannot be null"), system2.now());
   }
 
-  public void setDefaultQualityGate(DbSession dbSession, OrganizationDto organization, QGateWithOrgDto qualityGate) {
-    getMapper(dbSession).updateDefaultQualityGate(organization.getUuid(), qualityGate.getUuid(), system2.now());
-  }
-
   public int update(DbSession dbSession, OrganizationDto organization) {
     checkDto(organization);
     organization.setUpdatedAt(system2.now());
index ed77c2e07075a65564bbce4479b2ac5697b5eaf5..0ba046ff2fa8ad88849b18e178de72e22a5b4492 100644 (file)
@@ -40,7 +40,6 @@ public class ProjectQgateAssociationQuery {
   public static final Set<String> AVAILABLE_MEMBERSHIP = ImmutableSet.of(ANY, IN, OUT);
 
   private final String gateUuid;
-  private final String organizationUuid;
   private final String membership;
 
   private final String projectSearch;
@@ -56,7 +55,6 @@ public class ProjectQgateAssociationQuery {
 
   private ProjectQgateAssociationQuery(Builder builder) {
     this.gateUuid = builder.qualityGate.getUuid();
-    this.organizationUuid = builder.qualityGate.getOrganizationUuid();
     this.membership = builder.membership;
     this.projectSearch = builder.projectSearch;
     if (this.projectSearch == null) {
@@ -73,10 +71,6 @@ public class ProjectQgateAssociationQuery {
     return gateUuid;
   }
 
-  public String organizationUuid() {
-    return organizationUuid;
-  }
-
   @CheckForNull
   public String membership() {
     return membership;
@@ -103,7 +97,7 @@ public class ProjectQgateAssociationQuery {
   }
 
   public static class Builder {
-    private QGateWithOrgDto qualityGate;
+    private QualityGateDto qualityGate;
     private String membership;
     private String projectSearch;
 
@@ -113,7 +107,7 @@ public class ProjectQgateAssociationQuery {
     private Builder() {
     }
 
-    public Builder qualityGate(QGateWithOrgDto qualityGate) {
+    public Builder qualityGate(QualityGateDto qualityGate) {
       this.qualityGate = qualityGate;
       return this;
     }
index 4daf6fd17fc06fd13585b468062d63435aac48f6..b0d65fe64b74a5b7c6c120ff4f9abb083f1caa40 100644 (file)
@@ -27,13 +27,17 @@ import org.sonar.db.Dao;
 import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.property.InternalPropertiesDao;
 
 public class QualityGateDao implements Dao {
+  private static final String DEFAULT_ORGANIZATION_PROPERTY_KEY = "organization.default";
 
   private final UuidFactory uuidFactory;
+  private final InternalPropertiesDao internalPropertiesDao;
 
-  public QualityGateDao(UuidFactory uuidFactory) {
+  public QualityGateDao(UuidFactory uuidFactory, InternalPropertiesDao internalPropertiesDao) {
     this.uuidFactory = uuidFactory;
+    this.internalPropertiesDao = internalPropertiesDao;
   }
 
   public QualityGateDto insert(DbSession session, QualityGateDto newQualityGate) {
@@ -43,12 +47,30 @@ public class QualityGateDao implements Dao {
     return newQualityGate;
   }
 
+  /**
+   * @deprecated drop when org are dropped
+   */
+  @Deprecated
   public void associate(DbSession dbSession, String uuid, OrganizationDto organization, QualityGateDto qualityGate) {
     mapper(dbSession).insertOrgQualityGate(uuid, organization.getUuid(), qualityGate.getUuid());
   }
 
-  public Collection<QualityGateDto> selectAll(DbSession session, OrganizationDto organization) {
-    return mapper(session).selectAll(organization.getUuid());
+  public void associate(DbSession dbSession, String uuid, QualityGateDto qualityGate) {
+    String defaultOrganizationUuid = getDefaultOrganizationUuid(dbSession);
+    mapper(dbSession).insertOrgQualityGate(uuid, defaultOrganizationUuid, qualityGate.getUuid());
+  }
+
+  public Collection<QualityGateDto> selectAll(DbSession session) {
+    String defaultOrganizationUuid = getDefaultOrganizationUuid(session);
+    return selectAll(session, defaultOrganizationUuid);
+  }
+
+  /**
+   * @deprecated drop when org are dropped
+   */
+  @Deprecated
+  public Collection<QualityGateDto> selectAll(DbSession session, String organizationUuid) {
+    return mapper(session).selectAll(organizationUuid);
   }
 
   @CheckForNull
@@ -62,17 +84,24 @@ public class QualityGateDao implements Dao {
   }
 
   @CheckForNull
-  public QGateWithOrgDto selectByOrganizationAndUuid(DbSession dbSession, OrganizationDto organization, String qualityGateUuid) {
-    return mapper(dbSession).selectByUuidAndOrganization(qualityGateUuid, organization.getUuid());
+  public QGateWithOrgDto selectByDefaultOrganizationAndUuid(DbSession dbSession, String qualityGateUuid) {
+    String defaultOrganizationUuid = getDefaultOrganizationUuid(dbSession);
+    return mapper(dbSession).selectByUuidAndOrganization(qualityGateUuid, defaultOrganizationUuid);
   }
 
+  /**
+   * @deprecated drop when org are dropped
+   */
   @CheckForNull
-  public QGateWithOrgDto selectByOrganizationAndName(DbSession session, OrganizationDto organization, String name) {
-    return mapper(session).selectByNameAndOrganization(name, organization.getUuid());
+  @Deprecated
+  public QGateWithOrgDto selectByOrganizationAndUuid(DbSession dbSession, OrganizationDto organization, String qualityGateUuid) {
+    return mapper(dbSession).selectByUuidAndOrganization(qualityGateUuid, organization.getUuid());
   }
 
-  public QGateWithOrgDto selectDefault(DbSession dbSession, OrganizationDto organization) {
-    return mapper(dbSession).selectDefault(organization.getUuid());
+  @CheckForNull
+  public QGateWithOrgDto selectByDefaultOrganizationAndName(DbSession session, String name) {
+    String defaultOrganizationUuid = getDefaultOrganizationUuid(session);
+    return mapper(session).selectByNameAndOrganization(name, defaultOrganizationUuid);
   }
 
   public void delete(QualityGateDto qGate, DbSession session) {
@@ -108,4 +137,9 @@ public class QualityGateDao implements Dao {
   public QualityGateDto selectByProjectUuid(DbSession dbSession, String projectUuid) {
     return mapper(dbSession).selectByProjectUuid(projectUuid);
   }
+
+  private String getDefaultOrganizationUuid(DbSession dbSession) {
+    return internalPropertiesDao.selectByKey(dbSession, DEFAULT_ORGANIZATION_PROPERTY_KEY)
+      .orElseThrow(() -> new IllegalStateException("Default organization does not exist."));
+  }
 }
index 6b31322cb8054fbbfd611e801935f2771417d434..4419b062141c7dfc4bd87e3081d6ae75a2d33225 100644 (file)
@@ -13,7 +13,6 @@
     and proj.enabled = ${_true}
     and proj.main_branch_project_uuid is null
     and proj.copy_component_uuid is null
-    and proj.organization_uuid=#{query.organizationUuid, jdbcType=VARCHAR}
     <choose>
       <when test="query.membership() == 'selected'">
         and qg.uuid IS NOT NULL
index 00c61babc899698c8738c6ae0f1d1b32d83729ba..3668da9ca756cf43bf51cd690033311ad625ed0e 100644 (file)
       is_built_in = ${_true}
   </select>
 
-  <select id="selectDefault" 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
-    INNER JOIN organizations o ON o.default_quality_gate_uuid = qg.uuid AND o.uuid=#{organizationUuid, jdbcType=VARCHAR}
-  </select>
-
   <update id="delete" parameterType="String">
     delete from quality_gates where uuid=#{uuid}
   </update>
index f2fe1826be1b39a9339f2abd851e66e940cca68c..b4626b6ea64321579adf485bf1cbca5338bc1d98 100644 (file)
@@ -26,7 +26,6 @@ import org.junit.Test;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -42,12 +41,11 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void select_all_projects_by_query() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization);
-    ComponentDto project2 = db.components().insertPrivateProject(organization);
-    ComponentDto project3 = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject();
+    ComponentDto project2 = db.components().insertPrivateProject();
+    ComponentDto project3 = db.components().insertPrivateProject();
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate1);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project3), qualityGate2);
@@ -66,11 +64,10 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void select_all_projects_by_query_should_have_deterministic_order() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization, d -> d.setName("p1").setDbKey("key1"));
-    ComponentDto project2 = db.components().insertPrivateProject(organization, d -> d.setName("p1").setDbKey("key2"));
-    ComponentDto project3 = db.components().insertPrivateProject(organization, d -> d.setName("p2").setDbKey("key3"));
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setDbKey("key1"));
+    ComponentDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setDbKey("key2"));
+    ComponentDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setDbKey("key3"));
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate1);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project3), qualityGate1);
@@ -86,11 +83,10 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void select_projects_by_query() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization);
-    ComponentDto project2 = db.components().insertPrivateProject(organization);
-    ComponentDto project3 = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject();
+    ComponentDto project2 = db.components().insertPrivateProject();
+    ComponentDto project3 = db.components().insertPrivateProject();
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate);
 
@@ -113,11 +109,10 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void search_by_project_name() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setName("Project One"));
-    ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setName("Project Two"));
-    ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setName("Project Three"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One"));
+    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two"));
+    ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three"));
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate);
 
@@ -138,11 +133,10 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void sorted_by_project_name() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setName("Project One"));
-    ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setName("Project Two"));
-    ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setName("Project Three"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One"));
+    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two"));
+    ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three"));
 
     assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
       .qualityGate(qualityGate)
@@ -151,26 +145,6 @@ public class ProjectQgateAssociationDaoTest {
       .containsExactly(project1.uuid(), project3.uuid(), project2.uuid());
   }
 
-  @Test
-  public void return_only_projects_from_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
-    ComponentDto otherProject = db.components().insertPrivateProject(otherOrganization);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(otherProject), otherQualityGate);
-
-    List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
-      .qualityGate(qualityGate)
-      .build());
-
-    assertThat(result)
-      .extracting(ProjectQgateAssociationDto::getUuid)
-      .containsExactlyInAnyOrder(project.uuid());
-  }
-
   @Test
   public void select_qgate_uuid_is_absent() {
     ComponentDto project = db.components().insertPrivateProject();
@@ -182,11 +156,10 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void select_qgate_uuid() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization);
-    ComponentDto project2 = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject();
+    ComponentDto project2 = db.components().insertPrivateProject();
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1);
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate2);
 
@@ -197,9 +170,8 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void delete_by_project_uuid() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
 
     db.qualityGates().associateProjectToQualityGate(project, qualityGate);
 
@@ -212,9 +184,8 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void delete_by_qgate_uuid() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
 
     db.qualityGates().associateProjectToQualityGate(project, qualityGate);
 
@@ -227,10 +198,9 @@ public class ProjectQgateAssociationDaoTest {
 
   @Test
   public void update_project_qgate_association() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto firstQualityGate = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto secondQualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto firstQualityGate = db.qualityGates().insertQualityGate();
+    QualityGateDto secondQualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
 
     db.qualityGates().associateProjectToQualityGate(project, firstQualityGate);
 
index c79b77093595c438261690167683ad49313c2c2d..814adc717e22b8d682e304143072e724f85ebb43 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 
 import static java.lang.String.format;
@@ -62,18 +61,19 @@ public class QualityGateDaoTest {
     assertThat(reloaded.getUpdatedAt()).isNotNull();
   }
 
-  @Test
-  public void associate() {
-    QualityGateDto qgate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    OrganizationDto org = db.organizations().insert();
-
-    underTest.associate(dbSession, Uuids.createFast(), org, qgate);
-
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())).isNotNull();
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid()))
-      .extracting(QGateWithOrgDto::getUuid, QGateWithOrgDto::getUuid, QGateWithOrgDto::getOrganizationUuid, QGateWithOrgDto::getName)
-      .containsExactly(qgate.getUuid(), qgate.getUuid(), org.getUuid(), qgate.getName());
-  }
+  // TODO::
+  // @Test
+  // public void associate() {
+  // QualityGateDto qgate = db.qualityGates().(db.getDefaultOrganization());
+  // OrganizationDto org = db.organizations().insert();
+  //
+  // underTest.associate(dbSession, Uuids.createFast(), org, qgate);
+  //
+  // assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())).isNotNull();
+  // assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid()))
+  // .extracting(QualityGateDto::getUuid, QualityGateDto::getUuid, QualityGateDto::getOrganizationUuid, QualityGateDto::getName)
+  // .containsExactly(qgate.getUuid(), qgate.getUuid(), org.getUuid(), qgate.getName());
+  // }
 
   @Test
   public void insert_built_in() {
@@ -86,15 +86,13 @@ public class QualityGateDaoTest {
 
   @Test
   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);
+    QualityGateDto qualityGate1 = qualityGateDbTester.insertQualityGate();
+    QualityGateDto qualityGate2 = qualityGateDbTester.insertQualityGate();
+    QualityGateDto qualityGateOnOtherOrg = qualityGateDbTester.insertQualityGate();
 
-    assertThat(underTest.selectAll(dbSession, organization1))
+    assertThat(underTest.selectAll(dbSession))
       .extracting(QualityGateDto::getUuid)
-      .containsExactlyInAnyOrder(qualityGate1.getUuid(), qualityGate2.getUuid());
+      .containsExactlyInAnyOrder(qualityGate1.getUuid(), qualityGate2.getUuid(), qualityGateOnOtherOrg.getUuid());
   }
 
   @Test
@@ -118,68 +116,36 @@ public class QualityGateDaoTest {
     assertThat(underTest.selectByUuid(dbSession, "not-existing-uuid")).isNull();
   }
 
-  @Test
-  public void select_by_organization_and_uuid() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid()).getUuid()).isEqualTo(qualityGate.getUuid());
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, otherOrganization, qualityGate.getUuid())).isNull();
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, otherQualityGate.getUuid())).isNull();
-  }
-
   @Test
   public void select_by_organization_and_name() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate3 = db.qualityGates().insertQualityGate(otherOrganization);
-
-    assertThat(underTest.selectByOrganizationAndName(dbSession, organization, qualityGate1.getName()).getUuid()).isEqualTo(qualityGate1.getUuid());
-    assertThat(underTest.selectByOrganizationAndName(dbSession, otherOrganization, qualityGate3.getName()).getUuid()).isEqualTo(qualityGate3.getUuid());
-    assertThat(underTest.selectByOrganizationAndName(dbSession, organization, "Unknown")).isNull();
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate3 = db.qualityGates().insertQualityGate();
+
+    assertThat(underTest.selectByDefaultOrganizationAndName(dbSession, qualityGate1.getName()).getUuid()).isEqualTo(qualityGate1.getUuid());
+    assertThat(underTest.selectByDefaultOrganizationAndName(dbSession, qualityGate3.getName()).getUuid()).isEqualTo(qualityGate3.getUuid());
+    assertThat(underTest.selectByDefaultOrganizationAndName(dbSession, "Unknown")).isNull();
   }
 
   @Test
   public void select_by_organization_and_id() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate3 = db.qualityGates().insertQualityGate(otherOrganization);
-
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate1.getUuid()).getUuid()).isEqualTo(qualityGate1.getUuid());
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, otherOrganization, qualityGate3.getUuid()).getUuid()).isEqualTo(qualityGate3.getUuid());
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, "123")).isNull();
-  }
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate3 = db.qualityGates().insertQualityGate();
 
-  @Test
-  public void select_default() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.getDbClient().organizationDao().setDefaultQualityGate(dbSession, organization, qualityGate);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-    db.getDbClient().organizationDao().setDefaultQualityGate(dbSession, otherOrganization, otherQualityGate);
-
-    assertThat(underTest.selectDefault(dbSession, organization).getUuid()).isEqualTo(qualityGate.getUuid());
-    assertThat(underTest.selectDefault(dbSession, otherOrganization).getUuid()).isEqualTo(otherQualityGate.getUuid());
+    assertThat(underTest.selectByDefaultOrganizationAndUuid(dbSession, qualityGate1.getUuid()).getUuid()).isEqualTo(qualityGate1.getUuid());
+    assertThat(underTest.selectByDefaultOrganizationAndUuid(dbSession, qualityGate3.getUuid()).getUuid()).isEqualTo(qualityGate3.getUuid());
+    assertThat(underTest.selectByDefaultOrganizationAndUuid(dbSession, "123")).isNull();
   }
 
   @Test
   public void select_by_project_uuid() {
-    OrganizationDto organization = db.organizations().insert();
+    ProjectDto project = db.components().insertPrivateProjectDto();
 
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
 
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
-
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate3 = db.qualityGates().insertQualityGate(otherOrganization);
+    QualityGateDto qualityGate3 = db.qualityGates().insertQualityGate();
 
     db.qualityGates().associateProjectToQualityGate(project, qualityGate1);
 
@@ -189,29 +155,27 @@ public class QualityGateDaoTest {
 
   @Test
   public void delete() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = qualityGateDbTester.insertQualityGate(organization);
-    QGateWithOrgDto otherQualityGate = qualityGateDbTester.insertQualityGate(organization);
+    QualityGateDto qualityGate = qualityGateDbTester.insertQualityGate();
+    QualityGateDto otherQualityGate = qualityGateDbTester.insertQualityGate();
 
     underTest.delete(qualityGate, dbSession);
     dbSession.commit();
 
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull();
+    assertThat(underTest.selectByDefaultOrganizationAndUuid(dbSession, qualityGate.getUuid())).isNull();
     assertThat(db.countSql(dbSession, format("select count(*) from org_quality_gates where quality_gate_uuid='%s'", qualityGate.getUuid()))).isZero();
-    assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, otherQualityGate.getUuid())).isNotNull();
+    assertThat(underTest.selectByDefaultOrganizationAndUuid(dbSession, otherQualityGate.getUuid())).isNotNull();
     assertThat(db.countSql(dbSession, format("select count(*) from org_quality_gates where quality_gate_uuid='%s'", otherQualityGate.getUuid()))).isEqualTo(1);
   }
 
   @Test
   public void delete_by_uuids() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate1 = qualityGateDbTester.insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = qualityGateDbTester.insertQualityGate(organization);
+    QualityGateDto qualityGate1 = qualityGateDbTester.insertQualityGate();
+    QualityGateDto qualityGate2 = qualityGateDbTester.insertQualityGate();
 
     underTest.deleteByUuids(dbSession, asList(qualityGate1.getUuid(), qualityGate2.getUuid()));
     dbSession.commit();
 
-    assertThat(underTest.selectAll(dbSession, organization).stream())
+    assertThat(underTest.selectAll(dbSession).stream())
       .extracting(QualityGateDto::getUuid)
       .doesNotContain(qualityGate1.getUuid(), qualityGate2.getUuid());
   }
@@ -225,36 +189,36 @@ public class QualityGateDaoTest {
     assertThat(db.countRowsOfTable(dbSession, "quality_gates")).isEqualTo(nbOfQualityGates);
   }
 
-  @Test
-  public void deleteOrgQualityGatesByOrganization() {
-    OrganizationDto organization = db.organizations().insert();
-    qualityGateDbTester.insertQualityGate(organization);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    qualityGateDbTester.insertQualityGate(otherOrganization);
-
-    underTest.deleteOrgQualityGatesByOrganization(dbSession, organization);
-    dbSession.commit();
-
-    assertThat(db.select("select organization_uuid as \"organizationUuid\" from org_quality_gates"))
-      .extracting(row -> (String) row.get("organizationUuid"))
-      .containsOnly(otherOrganization.getUuid());
-  }
+  // TODO::
+  // @Test
+  // public void deleteOrgQualityGatesByOrganization() {
+  // OrganizationDto organization = db.organizations().insert();
+  // qualityGateDbTester.insertQualityGate(organization);
+  // OrganizationDto otherOrganization = db.organizations().insert();
+  // qualityGateDbTester.insertQualityGate(otherOrganization);
+  //
+  // underTest.deleteOrgQualityGatesByOrganization(dbSession, organization);
+  // dbSession.commit();
+  //
+  // assertThat(db.select("select organization_uuid as \"organizationUuid\" from org_quality_gates"))
+  // .extracting(row -> (String) row.get("organizationUuid"))
+  // .containsOnly(otherOrganization.getUuid());
+  // }
 
   @Test
   public void update() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = qualityGateDbTester.insertQualityGate(organization, qg -> qg.setName("old name"));
+    QualityGateDto qualityGate = qualityGateDbTester.insertQualityGate(qg -> qg.setName("old name"));
 
     underTest.update(qualityGate.setName("Not so strict"), dbSession);
     dbSession.commit();
 
-    QGateWithOrgDto reloaded = underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid());
+    QualityGateDto reloaded = underTest.selectByDefaultOrganizationAndUuid(dbSession, qualityGate.getUuid());
     assertThat(reloaded.getName()).isEqualTo("Not so strict");
   }
 
   private void insertQualityGates() {
-    qualityGateDbTester.insertQualityGate(db.getDefaultOrganization(), g -> g.setName("Very strict").setBuiltIn(false));
-    qualityGateDbTester.insertQualityGate(db.getDefaultOrganization(), g -> g.setName("Balanced").setBuiltIn(false));
-    qualityGateDbTester.insertQualityGate(db.getDefaultOrganization(), g -> g.setName("Lenient").setBuiltIn(false));
+    qualityGateDbTester.insertQualityGate(g -> g.setName("Very strict").setBuiltIn(false));
+    qualityGateDbTester.insertQualityGate(g -> g.setName("Balanced").setBuiltIn(false));
+    qualityGateDbTester.insertQualityGate(g -> g.setName("Lenient").setBuiltIn(false));
   }
 }
index 5d6f40a579972dd8856b911b292ba09e71a7b269..7717df2cda6eb8cce2e2a502d4e8ed99cbf06b20 100644 (file)
@@ -30,11 +30,13 @@ import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
+import org.sonar.db.property.PropertyDto;
 
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.apache.commons.lang.RandomStringUtils.randomNumeric;
 
 public class QualityGateDbTester {
+  private static final String DEFAULT_QUALITY_GATE_PROPERTY_NAME = "qualitygate.default";
 
   private final DbTester db;
   private final DbClient dbClient;
@@ -80,6 +82,7 @@ public class QualityGateDbTester {
     db.commit();
   }
 
+  @Deprecated
   public void associateQualityGateToOrganization(QualityGateDto qualityGate, OrganizationDto organization) {
     dbClient.qualityGateDao().associate(dbSession, Uuids.createFast(), organization, qualityGate);
     db.commit();
@@ -87,19 +90,13 @@ public class QualityGateDbTester {
 
   @SafeVarargs
   public final QualityGateDto createDefaultQualityGate(Consumer<QualityGateDto>... dtoPopulators) {
-    return createDefaultQualityGate(db.getDefaultOrganization(), dtoPopulators);
-  }
-
-  @SafeVarargs
-  @Deprecated
-  public final QualityGateDto createDefaultQualityGate(OrganizationDto organization, Consumer<QualityGateDto>... dtoPopulators) {
-    QualityGateDto defaultQGate = insertQualityGate(organization, dtoPopulators);
-    setDefaultQualityGate(organization, defaultQGate);
+    QualityGateDto defaultQGate = insertQualityGate(dtoPopulators);
+    setDefaultQualityGate(defaultQGate);
     return defaultQGate;
   }
 
-  public void setDefaultQualityGate(OrganizationDto organization, QualityGateDto qualityGate) {
-    dbClient.organizationDao().update(dbSession, organization.setDefaultQualityGateUuid(qualityGate.getUuid()));
+  public void setDefaultQualityGate(QualityGateDto qualityGate) {
+    dbClient.propertiesDao().saveProperty(new PropertyDto().setKey(DEFAULT_QUALITY_GATE_PROPERTY_NAME).setValue(qualityGate.getUuid()));
     dbSession.commit();
   }
 
index 337faf86be23fb3fdc0e767c28094e1435fb5647..10559c6bfb63e1e62e56b4ab51411322f91a5d54 100644 (file)
@@ -28,6 +28,7 @@ public class DbVersion87 implements DbVersion {
   public void addSteps(MigrationStepRegistry registry) {
     registry
       .add(4200, "Move default project visibility to global properties", MoveDefaultProjectVisibilityToGlobalProperties.class)
+      .add(4201, "Move default quality gate to global properties", MoveDefaultQualityGateToGlobalProperties.class)
 
     ;
   }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalProperties.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalProperties.java
new file mode 100644 (file)
index 0000000..0d8a791
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.sonar.server.platform.db.migration.version.v87;
+
+import java.sql.SQLException;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class MoveDefaultQualityGateToGlobalProperties extends DataChange {
+
+  private final UuidFactory uuidFactory;
+  private final System2 system2;
+
+  public MoveDefaultQualityGateToGlobalProperties(Database db, UuidFactory uuidFactory, System2 system2) {
+    super(db);
+    this.uuidFactory = uuidFactory;
+    this.system2 = system2;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    String defaultQualityGate = context.prepareSelect("select default_quality_gate_uuid from organizations where kee = ?")
+      .setString(1, "default-organization")
+      .get(row -> row.getString(1));
+
+    if (defaultQualityGate == null) {
+      throw new IllegalStateException("Default organization is missing");
+    } else {
+      context.prepareUpsert("insert into properties (uuid, prop_key, is_empty, text_value, created_at) values (?, ?, ?, ?, ?)")
+        .setString(1, uuidFactory.create())
+        .setString(2, "qualitygate.default")
+        .setBoolean(3, false)
+        .setString(4, defaultQualityGate)
+        .setLong(5, system2.now())
+        .execute()
+        .commit();
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalPropertiesTest.java
new file mode 100644 (file)
index 0000000..2277380
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.sonar.server.platform.db.migration.version.v87;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class MoveDefaultQualityGateToGlobalPropertiesTest {
+
+  private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private final TestSystem2 system2 = new TestSystem2();
+  private final long NOW = 1606375781L;
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MoveDefaultQualityGateToGlobalPropertiesTest.class, "schema.sql");
+
+  private final MoveDefaultQualityGateToGlobalProperties underTest = new MoveDefaultQualityGateToGlobalProperties(db.database(),
+    UuidFactoryFast.getInstance(), system2);
+
+  @Before
+  public void before() {
+    system2.setNow(NOW);
+  }
+
+  @Test
+  public void fail_if_organization_not_exist() {
+    assertThatThrownBy(underTest::execute)
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Default organization is missing");
+  }
+
+  @Test
+  public void migrate_default_quality_gate_from_default_organization() throws SQLException {
+    insertDefaultOrganization("default-quality-gate-uuid");
+
+    underTest.execute();
+
+    assertThatDefaultQualityGateIsEqualTo("default-quality-gate-uuid");
+  }
+
+  private void insertDefaultOrganization(String defaultQualityGate) {
+    String uuid = uuidFactory.create();
+    db.executeInsert("organizations",
+      "uuid", uuid,
+      "kee", "default-organization",
+      "name", "name" + uuid,
+      "default_perm_template_project", uuidFactory.create(),
+      "default_perm_template_port", uuidFactory.create(),
+      "default_perm_template_app", uuidFactory.create(),
+      "default_quality_gate_uuid", defaultQualityGate,
+      "new_project_private", false,
+      "subscription", uuid,
+      "created_at", NOW,
+      "updated_at", NOW);
+  }
+
+  private void assertThatDefaultQualityGateIsEqualTo(String s) {
+    assertThat(db.selectFirst("select p.text_value, p.created_at from properties p where p.prop_key = 'qualitygate.default'"))
+      .containsEntry("TEXT_VALUE", s)
+      .containsEntry("CREATED_AT", NOW);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v87/MoveDefaultQualityGateToGlobalPropertiesTest/schema.sql
new file mode 100644 (file)
index 0000000..09e88e0
--- /dev/null
@@ -0,0 +1,33 @@
+CREATE TABLE "PROPERTIES"(
+    "PROP_KEY" VARCHAR(512) NOT NULL,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "CLOB_VALUE" CLOB,
+    "CREATED_AT" BIGINT NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40),
+    "UUID" VARCHAR(40) NOT NULL,
+    "USER_UUID" VARCHAR(255)
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+
+CREATE TABLE "ORGANIZATIONS"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(255) NOT NULL,
+    "NAME" VARCHAR(255) NOT NULL,
+    "DESCRIPTION" VARCHAR(256),
+    "URL" VARCHAR(256),
+    "AVATAR_URL" VARCHAR(256),
+    "GUARDED" BOOLEAN,
+    "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
+    "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
+    "DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40),
+    "DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40),
+    "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
+    "SUBSCRIPTION" VARCHAR(40) NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL,
+    "DEFAULT_GROUP_UUID" VARCHAR(40)
+);
+ALTER TABLE "ORGANIZATIONS" ADD CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS"("KEE");
index 0aad74591a13c853a81af654acf8d47b481e416d..0c89c81d8301d3f2499e0d6f546c82655a781c7d 100644 (file)
@@ -22,15 +22,14 @@ package org.sonar.server.qualitygate;
 import java.util.Optional;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
+import org.sonar.db.property.PropertyDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 
 import static com.google.common.base.Preconditions.checkState;
-import static java.util.Optional.ofNullable;
 
 public class QualityGateFinder {
+  private static final String DEFAULT_QUALITY_GATE_PROPERTY_NAME = "qualitygate.default";
 
   private final DbClient dbClient;
 
@@ -38,30 +37,31 @@ public class QualityGateFinder {
     this.dbClient = dbClient;
   }
 
-  /**
-   * Return effective quality gate of a project.
-   *
-   * It will first try to get the quality gate explicitly defined on a project, if none it will try to return default quality gate of the organization
-   */
-  public Optional<QualityGateData> getQualityGate(DbSession dbSession, OrganizationDto organization, ProjectDto projectDto) {
-    return getQualityGate(dbSession, organization, projectDto.getUuid());
+  public QualityGateData getQualityGate(DbSession dbSession, ProjectDto projectDto) {
+    return getQualityGate(dbSession, projectDto.getUuid());
   }
 
-  public Optional<QualityGateData> getQualityGate(DbSession dbSession, OrganizationDto organization, String projectUuid) {
-    Optional<QualityGateData> res = dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, projectUuid)
-      .map(qualityGateUuid -> dbClient.qualityGateDao().selectByUuid(dbSession, qualityGateUuid))
-      .map(qualityGateDto -> new QualityGateData(qualityGateDto, false));
+  public QualityGateData getQualityGate(DbSession dbSession, String projectUuid) {
+    Optional<QualityGateData> res = getQualityGateForProject(dbSession, projectUuid);
     if (res.isPresent()) {
-      return res;
+      return res.get();
     }
-    return ofNullable(dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, organization.getDefaultQualityGateUuid()))
-      .map(qualityGateDto -> new QualityGateData(qualityGateDto, true));
+    QualityGateDto defaultQualityGate = getDefault(dbSession);
+    return new QualityGateData(defaultQualityGate, true);
+  }
+
+  private Optional<QualityGateData> getQualityGateForProject(DbSession dbSession, String projectUuid) {
+    return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, projectUuid)
+      .map(qualityGateUuid -> dbClient.qualityGateDao().selectByUuid(dbSession, qualityGateUuid))
+      .map(qualityGateDto -> new QualityGateData(qualityGateDto, false));
   }
 
-  public QualityGateDto getDefault(DbSession dbSession, OrganizationDto organization) {
-    QGateWithOrgDto qgate = dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, organization.getDefaultQualityGateUuid());
-    checkState(qgate != null, "Default quality gate [%s] is missing on organization [%s]", organization.getDefaultQualityGateUuid(), organization.getUuid());
-    return qgate;
+  public QualityGateDto getDefault(DbSession dbSession) {
+    PropertyDto qGateDefaultUuidProperty = dbClient.propertiesDao().selectGlobalProperty(dbSession, DEFAULT_QUALITY_GATE_PROPERTY_NAME);
+    checkState(qGateDefaultUuidProperty != null, "Default quality gate property is missing");
+    dbClient.qualityGateDao().selectByUuid(dbSession, qGateDefaultUuidProperty.getValue());
+    return Optional.ofNullable(dbClient.qualityGateDao().selectByUuid(dbSession, qGateDefaultUuidProperty.getValue()))
+      .orElseThrow(() -> new IllegalStateException("Default quality gate is missing"));
   }
 
   public QualityGateDto getBuiltInQualityGate(DbSession dbSession) {
index dc402af8bd23bce105177100f677e1f33c30bc65..34bbb8675e0d89fa4143bcea2908e27481894ed6 100644 (file)
  */
 package org.sonar.server.qualitygate;
 
-import java.util.Optional;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 
-import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 public class QualityGateFinderTest {
 
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbSession dbSession = db.getSession();
+  private final DbSession dbSession = db.getSession();
 
-  private QualityGateFinder underTest = new QualityGateFinder(db.getDbClient());
+  private final QualityGateFinder underTest = new QualityGateFinder(db.getDbClient());
 
   @Test
   public void return_default_quality_gate_for_project() {
     ProjectDto project = db.components().insertPrivateProjectDto();
-    QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(db.getDefaultOrganization(), qg -> qg.setName("Sonar way"));
+    QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(qg -> qg.setName("Sonar way"));
 
-    Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project);
+    QualityGateFinder.QualityGateData result = underTest.getQualityGate(dbSession, project);
 
-    assertThat(result).isPresent();
-    assertThat(result.get().getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid());
-    assertThat(result.get().isDefault()).isTrue();
+    assertThat(result.getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid());
+    assertThat(result.isDefault()).isTrue();
   }
 
   @Test
   public void return_project_quality_gate_over_default() {
     ProjectDto project = db.components().insertPrivateProjectDto();
-    db.qualityGates().createDefaultQualityGate(db.getDefaultOrganization(), qg -> qg.setName("Sonar way"));
-    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization(), qg -> qg.setName("My team QG"));
+    db.qualityGates().createDefaultQualityGate(qg -> qg.setName("Sonar way"));
+    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
     db.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
 
-    Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project);
+    QualityGateFinder.QualityGateData result = underTest.getQualityGate(dbSession, project);
 
-    assertThat(result).isPresent();
-    assertThat(result.get().getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid());
-    assertThat(result.get().isDefault()).isFalse();
+    assertThat(result.getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid());
+    assertThat(result.isDefault()).isFalse();
   }
 
   @Test
-  public void fail_when_default_qgate_defined_does_not_exists() {
+  public void fail_when_default_qgate_defined_does_not_exist() {
     ProjectDto project = db.components().insertPrivateProjectDto();
-    QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(db.getDefaultOrganization(), qg -> qg.setName("Sonar way"));
+    QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(qg -> qg.setName("Sonar way"));
     db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
     db.commit();
 
-    assertThat(underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project)).isEmpty();
+    assertThatThrownBy(() -> underTest.getQualityGate(dbSession, project))
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Default quality gate is missing");
   }
 
   @Test
-  public void fail_when_project_qgate_defined_does_not_exists() {
+  public void fail_when_project_qgate_defined_does_not_exist() {
     ProjectDto project = db.components().insertPrivateProjectDto();
-    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization(), qg -> qg.setName("My team QG"));
+    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
+    db.qualityGates().setDefaultQualityGate(dbQualityGate);
     db.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
     db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
 
-    assertThat(underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project)).isEmpty();
+    assertThatThrownBy(() -> underTest.getQualityGate(dbSession, project))
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Default quality gate is missing");
   }
 
   @Test
-  public void fail_when_default_quality_gate_does_not_exists() {
-    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization(), qg -> qg.setName("My team QG"));
-    db.qualityGates().setDefaultQualityGate(db.getDefaultOrganization(), dbQualityGate);
+  public void fail_when_qgate_property_does_not_exist() {
+    ProjectDto project = db.components().insertPrivateProjectDto();
+    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
     db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
 
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage(format("Default quality gate [%s] is missing on organization [%s]", dbQualityGate.getUuid(), db.getDefaultOrganization().getUuid()));
+    assertThatThrownBy(() -> underTest.getQualityGate(dbSession, project))
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Default quality gate property is missing");
+  }
+
+  @Test
+  public void fail_when_default_quality_gate_does_not_exists() {
+    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
+    db.qualityGates().setDefaultQualityGate(dbQualityGate);
+    db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
 
-    underTest.getDefault(dbSession, db.getDefaultOrganization());
+    assertThatThrownBy(() -> underTest.getDefault(dbSession))
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Default quality gate is missing");
   }
 
 }
index d9b5d0ea0cdf7d4b4f7f8f176a1f64b6976e5375..31db257bfc2e2e014b5902bd5b7bea8935cd93bb 100644 (file)
@@ -68,7 +68,7 @@ import static org.sonar.server.organization.OrganizationUpdater.NewOrganization.
 public class OrganizationUpdaterImplTest {
   private static final long A_DATE = 12893434L;
 
-  private OrganizationUpdater.NewOrganization FULL_POPULATED_NEW_ORGANIZATION = newOrganizationBuilder()
+  private final OrganizationUpdater.NewOrganization FULL_POPULATED_NEW_ORGANIZATION = newOrganizationBuilder()
     .setName("a-name")
     .setKey("a-key")
     .setDescription("a-description")
@@ -76,9 +76,9 @@ public class OrganizationUpdaterImplTest {
     .setAvatarUrl("a-avatar")
     .build();
 
-  private System2 system2 = new TestSystem2().setNow(A_DATE);
+  private final System2 system2 = new TestSystem2().setNow(A_DATE);
 
-  private static Consumer<OrganizationDto> EMPTY_ORGANIZATION_CONSUMER = o -> {
+  private static final Consumer<OrganizationDto> EMPTY_ORGANIZATION_CONSUMER = o -> {
   };
 
   @Rule
@@ -90,20 +90,20 @@ public class OrganizationUpdaterImplTest {
   @Rule
   public BuiltInQProfileRepositoryRule builtInQProfileRepositoryRule = new BuiltInQProfileRepositoryRule();
 
-  private DbSession dbSession = db.getSession();
+  private final DbSession dbSession = db.getSession();
 
-  private IllegalArgumentException exceptionThrownByOrganizationValidation = new IllegalArgumentException("simulate IAE thrown by OrganizationValidation");
-  private DbClient dbClient = db.getDbClient();
-  private UuidFactory uuidFactory = new SequenceUuidFactory();
-  private OrganizationValidation organizationValidation = mock(OrganizationValidation.class);
-  private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
-  private UserIndex userIndex = new UserIndex(es.client(), system2);
-  private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient, uuidFactory, TestDefaultOrganizationProvider.from(db));
+  private final IllegalArgumentException exceptionThrownByOrganizationValidation = new IllegalArgumentException("simulate IAE thrown by OrganizationValidation");
+  private final DbClient dbClient = db.getDbClient();
+  private final UuidFactory uuidFactory = new SequenceUuidFactory();
+  private final OrganizationValidation organizationValidation = mock(OrganizationValidation.class);
+  private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
+  private final UserIndex userIndex = new UserIndex(es.client(), system2);
+  private final DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient, uuidFactory, TestDefaultOrganizationProvider.from(db));
 
-  private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
-  private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+  private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+  private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
 
-  private OrganizationUpdaterImpl underTest = new OrganizationUpdaterImpl(dbClient, system2, uuidFactory, organizationValidation, userIndexer,
+  private final OrganizationUpdaterImpl underTest = new OrganizationUpdaterImpl(dbClient, system2, uuidFactory, organizationValidation, userIndexer,
     builtInQProfileRepositoryRule, defaultGroupCreator, permissionService);
 
   @Test
@@ -200,19 +200,6 @@ public class OrganizationUpdaterImplTest {
     db.commit();
   }
 
-  @Test
-  public void create_associates_to_built_in_quality_gate() throws OrganizationUpdater.KeyConflictException {
-    QualityGateDto builtInQualityGate = db.qualityGates().insertBuiltInQualityGate();
-    builtInQProfileRepositoryRule.initialize();
-    UserDto user = db.users().insertUser();
-
-    underTest.create(dbSession, user, FULL_POPULATED_NEW_ORGANIZATION, o -> {
-    });
-
-    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, FULL_POPULATED_NEW_ORGANIZATION.getKey()).get();
-    assertThat(dbClient.qualityGateDao().selectDefault(dbSession, organization).getUuid()).isEqualTo(builtInQualityGate.getUuid());
-  }
-
   @Test
   public void create_calls_consumer() throws OrganizationUpdater.KeyConflictException {
     UserDto user = db.users().insertUser();
index 239cc0c72f5b4d0358e2c105583144ee8fcce158..acd120fba34d6bf5a8768cb2fd372ef6b6c4a896 100644 (file)
@@ -40,7 +40,6 @@ import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.LiveMeasureComparator;
 import org.sonar.db.measure.LiveMeasureDto;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.server.es.ProjectIndexer;
 import org.sonar.server.es.ProjectIndexers;
@@ -95,7 +94,6 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
     // load all the components to be refreshed, including their ancestors
     List<ComponentDto> components = loadTreeOfComponents(dbSession, touchedComponents);
     ComponentDto branchComponent = findBranchComponent(components);
-    OrganizationDto organization = loadOrganization(dbSession, branchComponent);
     BranchDto branch = loadBranch(dbSession, branchComponent);
     ProjectDto project = loadProject(dbSession, branch.getProjectUuid());
     Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, branchComponent.uuid());
@@ -103,7 +101,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
       return Optional.empty();
     }
 
-    QualityGate qualityGate = qGateComputer.loadQualityGate(dbSession, organization, project, branch);
+    QualityGate qualityGate = qGateComputer.loadQualityGate(dbSession, project, branch);
     Collection<String> metricKeys = getKeysOfAllInvolvedMetrics(qualityGate);
 
     List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, metricKeys);
@@ -226,12 +224,6 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
       .orElseThrow(() -> new IllegalStateException("Project not found: " + uuid));
   }
 
-  private OrganizationDto loadOrganization(DbSession dbSession, ComponentDto project) {
-    String organizationUuid = project.getOrganizationUuid();
-    return dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
-      .orElseThrow(() -> new IllegalStateException("No organization with UUID " + organizationUuid));
-  }
-
   private static class FormulaContextImpl implements IssueMetricFormula.Context {
     private final MeasureMatrix matrix;
     private final DebtRatingGrid debtRatingGrid;
index 0e133da2a95e458411ed6d757c6a24cef3465c5f..f29c3795ae7234ec72aff24cbea8a6acde03b204 100644 (file)
@@ -24,7 +24,6 @@ import org.sonar.api.server.ServerSide;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.server.qualitygate.EvaluatedQualityGate;
 import org.sonar.server.qualitygate.QualityGate;
@@ -32,7 +31,7 @@ import org.sonar.server.qualitygate.QualityGate;
 @ServerSide
 public interface LiveQualityGateComputer {
 
-  QualityGate loadQualityGate(DbSession dbSession, OrganizationDto organization, ProjectDto project, BranchDto branch);
+  QualityGate loadQualityGate(DbSession dbSession, ProjectDto project, BranchDto branch);
 
   EvaluatedQualityGate refreshGateStatus(ComponentDto project, QualityGate gate, MeasureMatrix measureMatrix);
 
index 03a87e0eaad081208ee4e4e11b014ab018d2e7c4..9166beacef3bfbd11a1fb63987a22c720d55e33b 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.measure.LiveMeasureDto;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
@@ -46,7 +45,6 @@ import org.sonar.server.qualitygate.QualityGateConverter;
 import org.sonar.server.qualitygate.QualityGateEvaluator;
 import org.sonar.server.qualitygate.QualityGateFinder;
 
-import static java.lang.String.format;
 import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 
@@ -63,9 +61,8 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
   }
 
   @Override
-  public QualityGate loadQualityGate(DbSession dbSession, OrganizationDto organization, ProjectDto project, BranchDto branch) {
-    QualityGateDto gateDto = qGateFinder.getQualityGate(dbSession, organization, project)
-      .orElseThrow(() -> new IllegalStateException(format("Quality Gate not found for project %s", project.getKey())))
+  public QualityGate loadQualityGate(DbSession dbSession, ProjectDto project, BranchDto branch) {
+    QualityGateDto gateDto = qGateFinder.getQualityGate(dbSession, project)
       .getQualityGate();
     Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getUuid());
     Set<String> metricUuids = conditionDtos.stream().map(QualityGateConditionDto::getMetricUuid)
index ceee7526d03391665b5e67fb68f959a01e6bcf25..859adc1203adcfdebc889cbf66366a820974dce6 100644 (file)
@@ -23,7 +23,6 @@ import org.sonar.core.util.UuidFactory;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 
@@ -40,40 +39,38 @@ public class QualityGateUpdater {
     this.uuidFactory = uuidFactory;
   }
 
-  public QualityGateDto create(DbSession dbSession, OrganizationDto organizationDto, String name) {
-    validateQualityGate(dbSession, organizationDto, name);
+  public QualityGateDto create(DbSession dbSession, String name) {
+    validateQualityGate(dbSession, name);
     QualityGateDto newQualityGate = new QualityGateDto()
       .setName(name)
       .setBuiltIn(false)
       .setUuid(uuidFactory.create());
     dbClient.qualityGateDao().insert(dbSession, newQualityGate);
-    dbClient.qualityGateDao().associate(dbSession, uuidFactory.create(), organizationDto, newQualityGate);
+    dbClient.qualityGateDao().associate(dbSession, uuidFactory.create(), newQualityGate);
     return newQualityGate;
   }
 
-  public QualityGateDto copy(DbSession dbSession, OrganizationDto organizationDto, QualityGateDto qualityGateDto, String destinationName) {
-
-    QualityGateDto destinationGate = create(dbSession, organizationDto, destinationName);
-
+  public QualityGateDto copy(DbSession dbSession, QualityGateDto qualityGateDto, String destinationName) {
+    QualityGateDto destinationGate = create(dbSession, destinationName);
     for (QualityGateConditionDto sourceCondition : dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getUuid())) {
       dbClient.gateConditionDao().insert(new QualityGateConditionDto()
-          .setUuid(Uuids.create())
-          .setQualityGateUuid(destinationGate.getUuid())
-          .setMetricUuid(sourceCondition.getMetricUuid())
-          .setOperator(sourceCondition.getOperator())
-          .setErrorThreshold(sourceCondition.getErrorThreshold()),
+        .setUuid(Uuids.create())
+        .setQualityGateUuid(destinationGate.getUuid())
+        .setMetricUuid(sourceCondition.getMetricUuid())
+        .setOperator(sourceCondition.getOperator())
+        .setErrorThreshold(sourceCondition.getErrorThreshold()),
         dbSession);
     }
 
     return destinationGate;
   }
 
-  private void validateQualityGate(DbSession dbSession, OrganizationDto organizationDto, String name) {
-    checkQualityGateDoesNotAlreadyExist(dbSession, organizationDto, name);
+  private void validateQualityGate(DbSession dbSession, String name) {
+    checkQualityGateDoesNotAlreadyExist(dbSession, name);
   }
 
-  private void checkQualityGateDoesNotAlreadyExist(DbSession dbSession, OrganizationDto organizationDto, String name) {
-    QualityGateDto existingQgate = dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organizationDto, name);
-    checkArgument(existingQgate == null, IS_ALREADY_USED_MESSAGE, "Name");
+  private void checkQualityGateDoesNotAlreadyExist(DbSession dbSession, String name) {
+    QualityGateDto existingQGate = dbClient.qualityGateDao().selectByName(dbSession, name);
+    checkArgument(existingQGate == null, IS_ALREADY_USED_MESSAGE, "Name");
   }
 }
index db21c61415dde6899070a14deb5449720c3d9db6..e4b6e141667a081429c09518f53efdd79dfb21e1 100644 (file)
@@ -25,7 +25,6 @@ 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.QualityGateUpdater;
 import org.sonar.server.user.UserSession;
@@ -84,8 +83,6 @@ public class CopyAction implements QualityGatesWsAction {
       .setDescription("The name of the quality gate to create")
       .setRequired(true)
       .setExampleValue("My New Quality Gate");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
@@ -98,15 +95,14 @@ public class CopyAction implements QualityGatesWsAction {
 
     try (DbSession dbSession = dbClient.openSession(false)) {
 
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
       userSession.checkPermission(ADMINISTER_QUALITY_GATES);
       QualityGateDto qualityGate;
       if (uuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid);
+        qualityGate = wsSupport.getByUuid(dbSession, uuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, sourceName);
+        qualityGate = wsSupport.getByName(dbSession, sourceName);
       }
-      QualityGateDto copy = qualityGateUpdater.copy(dbSession, organization, qualityGate, destinationName);
+      QualityGateDto copy = qualityGateUpdater.copy(dbSession, qualityGate, destinationName);
       dbSession.commit();
 
       writeProtobuf(newBuilder()
index 33234f6b3c37e2f34a48da0f3edbf0d81ffbd24d..f85ca7e8022f1438be80bab7597dbd38512cfed1 100644 (file)
@@ -25,7 +25,6 @@ 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.permission.GlobalPermission;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.QualityGateUpdater;
@@ -43,14 +42,11 @@ public class CreateAction implements QualityGatesWsAction {
   private final DbClient dbClient;
   private final UserSession userSession;
   private final QualityGateUpdater qualityGateUpdater;
-  private final QualityGatesWsSupport wsSupport;
 
-  public CreateAction(DbClient dbClient, UserSession userSession, QualityGateUpdater qualityGateUpdater,
-    QualityGatesWsSupport wsSupport) {
+  public CreateAction(DbClient dbClient, UserSession userSession, QualityGateUpdater qualityGateUpdater) {
     this.dbClient = dbClient;
     this.userSession = userSession;
     this.qualityGateUpdater = qualityGateUpdater;
-    this.wsSupport = wsSupport;
   }
 
   @Override
@@ -70,20 +66,16 @@ public class CreateAction implements QualityGatesWsAction {
       .setMaximumLength(NAME_MAXIMUM_LENGTH)
       .setDescription("The name of the quality gate to create")
       .setExampleValue("My Quality Gate");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
   public void handle(Request request, Response response) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organizationDto = wsSupport.getOrganization(dbSession, request);
-
       userSession.checkPermission(GlobalPermission.ADMINISTER_QUALITY_GATES);
 
       String name = request.mandatoryParam(PARAM_NAME);
 
-      QualityGateDto newQualityGate = qualityGateUpdater.create(dbSession, organizationDto, name);
+      QualityGateDto newQualityGate = qualityGateUpdater.create(dbSession, name);
       CreateResponse.Builder createResponse = CreateResponse.newBuilder()
         .setId(newQualityGate.getUuid())
         .setName(newQualityGate.getName());
index 09f5a497a00c62d6a82f40701c316dcbc00b2aa3..d3f30ee5be2b1b1657f2d5df7487097c67bc2ccb 100644 (file)
@@ -25,9 +25,8 @@ 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.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
+import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.QualityGateConditionsUpdater;
 import org.sonarqube.ws.Qualitygates.CreateConditionResponse;
 
@@ -83,7 +82,6 @@ public class CreateConditionAction implements QualityGatesWsAction {
       .setExampleValue("SonarSource way");
 
     addConditionParams(createCondition);
-    wsSupport.createOrganizationParam(createCondition);
   }
 
   @Override
@@ -96,12 +94,11 @@ public class CreateConditionAction implements QualityGatesWsAction {
     checkArgument(gateName != null ^ gateUuid != null, "One of 'gateId' or 'gateName' must be provided, and not both");
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-      QGateWithOrgDto qualityGate;
+      QualityGateDto qualityGate;
       if (gateUuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, gateUuid);
+        qualityGate = wsSupport.getByUuid(dbSession, gateUuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, gateName);
+        qualityGate = wsSupport.getByName(dbSession, gateName);
       }
       wsSupport.checkCanEdit(qualityGate);
       QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, error);
index 68b57d214442f3a26e950a42e18cc0706e0465e6..9f3850a3b0a7c04de48ba0944cd21dff209f6f8c 100644 (file)
@@ -24,9 +24,8 @@ 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.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
+import org.sonar.db.qualitygate.QualityGateDto;
 
 import static com.google.common.base.Preconditions.checkState;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
@@ -55,17 +54,14 @@ public class DeleteConditionAction implements QualityGatesWsAction {
       .setRequired(true)
       .setDescription("Condition UUID")
       .setExampleValue("2");
-
-    wsSupport.createOrganizationParam(createCondition);
   }
 
   @Override
   public void handle(Request request, Response response) {
     String conditionUuid = request.mandatoryParam(PARAM_ID);
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
       QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionUuid);
-      QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, condition.getQualityGateUuid());
+      QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByUuid(dbSession, condition.getQualityGateUuid());
       checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionUuid, condition.getQualityGateUuid());
       wsSupport.checkCanEdit(qualityGateDto);
 
index 2829a412d774e09f5ec5e634673da72ce188b5d5..011b6f1c4d4e9cd5a049da158fbd3cb09019ba3a 100644 (file)
@@ -25,7 +25,6 @@ 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.project.ProjectDto;
 
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY;
@@ -61,15 +60,12 @@ public class DeselectAction implements QualityGatesWsAction {
       .setDescription("Project key")
       .setExampleValue(KEY_PROJECT_EXAMPLE_001)
       .setSince("6.1");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
   public void handle(Request request, Response response) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-      ProjectDto project = wsSupport.getProject(dbSession, organization, request.mandatoryParam(PARAM_PROJECT_KEY));
+      ProjectDto project = wsSupport.getProject(dbSession, request.mandatoryParam(PARAM_PROJECT_KEY));
       dissociateProject(dbSession, project);
       response.noContent();
     }
index b82c0b230cc7a4f0e4707c98bc0d54d193b60b90..ca520d2b3682ac1c48b1599f64585f886d1cac3a 100644 (file)
@@ -25,8 +25,6 @@ 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.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.QualityGateFinder;
 
@@ -70,8 +68,6 @@ public class DestroyAction implements QualityGatesWsAction {
       .setMaximumLength(NAME_MAXIMUM_LENGTH)
       .setSince("8.4")
       .setExampleValue("SonarSource Way");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
@@ -82,17 +78,15 @@ public class DestroyAction implements QualityGatesWsAction {
     checkArgument(name != null ^ uuid != null, "One of 'id' or 'name' must be provided, and not both");
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-
-      QGateWithOrgDto qualityGate;
+      QualityGateDto qualityGate;
 
       if (uuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid);
+        qualityGate = wsSupport.getByUuid(dbSession, uuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, name);
+        qualityGate = wsSupport.getByName(dbSession, name);
       }
 
-      QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization);
+      QualityGateDto defaultQualityGate = finder.getDefault(dbSession);
       checkArgument(!defaultQualityGate.getUuid().equals(qualityGate.getUuid()), "The default quality gate cannot be removed");
       wsSupport.checkCanEdit(qualityGate);
 
index 9c543309f7a060f7bda420e05d78440b64fc9f9d..a5e93f551419c0d1dfd2f34db2cef145118f0ba1 100644 (file)
@@ -25,17 +25,14 @@ 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.project.ProjectDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.qualitygate.QualityGateFinder.QualityGateData;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.Qualitygates.GetByProjectResponse;
 
-import static java.lang.String.format;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_GET_BY_PROJECT;
@@ -50,14 +47,12 @@ public class GetByProjectAction implements QualityGatesWsAction {
   private final DbClient dbClient;
   private final ComponentFinder componentFinder;
   private final QualityGateFinder qualityGateFinder;
-  private final QualityGatesWsSupport wsSupport;
 
-  public GetByProjectAction(UserSession userSession, DbClient dbClient, ComponentFinder componentFinder, QualityGateFinder qualityGateFinder, QualityGatesWsSupport wsSupport) {
+  public GetByProjectAction(UserSession userSession, DbClient dbClient, ComponentFinder componentFinder, QualityGateFinder qualityGateFinder) {
     this.userSession = userSession;
     this.dbClient = dbClient;
     this.componentFinder = componentFinder;
     this.qualityGateFinder = qualityGateFinder;
-    this.wsSupport = wsSupport;
   }
 
   @Override
@@ -84,25 +79,19 @@ public class GetByProjectAction implements QualityGatesWsAction {
       .setDescription("Project key")
       .setExampleValue(KEY_PROJECT_EXAMPLE_001)
       .setRequired(true);
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
   public void handle(Request request, Response response) throws Exception {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
       ProjectDto project = componentFinder.getProjectByKey(dbSession, request.mandatoryParam(PARAM_PROJECT));
-      // As ComponentFinder doesn't handle organization yet, we only check here that the project belongs to the organization
-      wsSupport.checkProjectBelongsToOrganization(organization, project);
 
       if (!userSession.hasProjectPermission(USER, project) &&
         !userSession.hasProjectPermission(ADMIN, project)) {
         throw insufficientPrivilegesException();
       }
 
-      QualityGateData data = qualityGateFinder.getQualityGate(dbSession, organization, project)
-        .orElseThrow(() -> new NotFoundException(format("Quality gate not found for project %s", project.getKey())));
+      QualityGateData data = qualityGateFinder.getQualityGate(dbSession, project);
 
       writeProtobuf(buildResponse(data), request, response);
     }
index 416e8e9e93548418fb8773f83d6dcf5ff6ce3fee..ea1709ecd5987a30f3a0dc7aa4f34fceefc5022e 100644 (file)
@@ -28,7 +28,6 @@ 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 +51,7 @@ public class ListAction implements QualityGatesWsAction {
 
   @Override
   public void define(WebService.NewController controller) {
-    WebService.NewAction action = controller.createAction("list")
+    controller.createAction("list")
       .setDescription("Get a list of quality gates")
       .setSince("4.3")
       .setResponseExample(Resources.getResource(this.getClass(), "list-example.json"))
@@ -63,15 +62,13 @@ 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);
-      QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization);
-      Collection<QualityGateDto> qualityGates = dbClient.qualityGateDao().selectAll(dbSession, organization);
+      QualityGateDto defaultQualityGate = finder.getDefault(dbSession);
+      Collection<QualityGateDto> qualityGates = dbClient.qualityGateDao().selectAll(dbSession);
       writeProtobuf(buildResponse(qualityGates, defaultQualityGate), request, response);
     }
   }
index 8c7d8f7ab7a6e9c3e4ca58fdf67e5845b5b6e478..2f0c89ac29de726ca18f3ef130e9077b9308f2fb 100644 (file)
@@ -30,7 +30,6 @@ public class QualityGatesWsParameters {
   public static final String ACTION_CREATE_CONDITION = "create_condition";
   public static final String ACTION_UPDATE_CONDITION = "update_condition";
 
-  static final String PARAM_ORGANIZATION = "organization";
   public static final String PARAM_ANALYSIS_ID = "analysisId";
   public static final String PARAM_BRANCH = "branch";
   public static final String PARAM_PULL_REQUEST = "pullRequest";
index 2375b98264e818d3172cf52c970ab4a6996cec06..dffc4164741c43c4a0713b4ab376e683351aa270 100644 (file)
 package org.sonar.server.qualitygate.ws;
 
 import java.util.Objects;
-import java.util.Optional;
 import javax.annotation.Nullable;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WebService.NewAction;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.Qualitygates;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static java.lang.String.format;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.server.exceptions.NotFoundException.checkFound;
-import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
 
 public class QualityGatesWsSupport {
 
   private final DbClient dbClient;
   private final UserSession userSession;
-  private final DefaultOrganizationProvider defaultOrganizationProvider;
   private final ComponentFinder componentFinder;
 
-  public QualityGatesWsSupport(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider, ComponentFinder componentFinder) {
+  public QualityGatesWsSupport(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder) {
     this.dbClient = dbClient;
     this.userSession = userSession;
-    this.defaultOrganizationProvider = defaultOrganizationProvider;
     this.componentFinder = componentFinder;
   }
 
-  public QGateWithOrgDto getByOrganizationAndUuid(DbSession dbSession, OrganizationDto organization, String qualityGateUuid) {
+  public QualityGateDto getByUuid(DbSession dbSession, String qualityGateUuid) {
     return checkFound(
-      dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGateUuid),
-      "No quality gate has been found for id %s in organization %s", qualityGateUuid, organization.getName());
+      dbClient.qualityGateDao().selectByUuid(dbSession, qualityGateUuid),
+      "No quality gate has been found for id %s", qualityGateUuid);
   }
 
-  public QGateWithOrgDto getByOrganizationAndName(DbSession dbSession, OrganizationDto organization, String qualityGateName) {
-    return checkFound(
-      dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, qualityGateName),
-      "No quality gate has been found for name %s in organization %s", qualityGateName, organization.getName());
+  public QualityGateDto getByName(DbSession dbSession, String qualityGateName) {
+    return checkFound(dbClient.qualityGateDao().selectByName(dbSession, qualityGateName),
+      "No quality gate has been found for name %s", qualityGateName);
   }
 
   QualityGateConditionDto getCondition(DbSession dbSession, String uuid) {
@@ -81,16 +67,6 @@ public class QualityGatesWsSupport {
     return userSession.hasPermission(ADMINISTER_QUALITY_GATES);
   }
 
-  WebService.NewParam createOrganizationParam(NewAction action) {
-    return action
-      .createParam(PARAM_ORGANIZATION)
-      .setDescription("Organization key. If no organization is provided, the default organization is used.")
-      .setSince("7.0")
-      .setRequired(false)
-      .setInternal(false)
-      .setExampleValue("my-org");
-  }
-
   Qualitygates.Actions getActions(QualityGateDto qualityGate, @Nullable QualityGateDto defaultQualityGate) {
     boolean isDefault = defaultQualityGate != null && Objects.equals(defaultQualityGate.getUuid(), qualityGate.getUuid());
     boolean isBuiltIn = qualityGate.isBuiltIn();
@@ -105,22 +81,7 @@ public class QualityGatesWsSupport {
       .build();
   }
 
-  OrganizationDto getDefaultOrganization(DbSession dbSession) {
-    return getOrganization(dbSession, defaultOrganizationProvider.get().getKey());
-  }
-
-  OrganizationDto getOrganization(DbSession dbSession, String key) {
-    Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByKey(dbSession, key);
-    return checkFoundWithOptional(organizationDto, "No organization with key '%s'", key);
-  }
-
-  OrganizationDto getOrganization(DbSession dbSession, Request request) {
-    String organizationKey = Optional.ofNullable(request.param(PARAM_ORGANIZATION))
-      .orElseGet(() -> defaultOrganizationProvider.get().getKey());
-    return getOrganization(dbSession, organizationKey);
-  }
-
-  void checkCanEdit(QGateWithOrgDto qualityGate) {
+  void checkCanEdit(QualityGateDto qualityGate) {
     checkNotBuiltIn(qualityGate);
     userSession.checkPermission(ADMINISTER_QUALITY_GATES);
   }
@@ -133,21 +94,11 @@ public class QualityGatesWsSupport {
     throw insufficientPrivilegesException();
   }
 
-  ProjectDto getProject(DbSession dbSession, OrganizationDto organization, String projectKey) {
-    ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
-    checkProjectBelongsToOrganization(organization, project);
-    return project;
-  }
-
-  void checkProjectBelongsToOrganization(OrganizationDto organization, ProjectDto project) {
-    if (project.getOrganizationUuid().equals(organization.getUuid())) {
-      return;
-    }
-    throw new NotFoundException(format("Project '%s' doesn't exist in organization '%s'", project.getKey(), organization.getKey()));
+  ProjectDto getProject(DbSession dbSession, String projectKey) {
+    return componentFinder.getProjectByKey(dbSession, projectKey);
   }
 
   private static void checkNotBuiltIn(QualityGateDto qualityGate) {
     checkArgument(!qualityGate.isBuiltIn(), "Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName());
   }
-
 }
index 4efdcf7fb9f6c2cd11597536e6ba4acdadb171a9..aa8bcbca69567bac404e5550f3ea8f6e02e559c0 100644 (file)
@@ -25,8 +25,6 @@ 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.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonarqube.ws.Qualitygates.QualityGate;
 
@@ -78,8 +76,6 @@ public class RenameAction implements QualityGatesWsAction {
       .setMaximumLength(NAME_MAXIMUM_LENGTH)
       .setDescription("New name of the quality gate")
       .setExampleValue("My New Quality Gate");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
@@ -90,15 +86,14 @@ public class RenameAction implements QualityGatesWsAction {
     checkArgument(uuid != null ^ currentName != null, "One of 'id' or 'currentName' must be provided, and not both");
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
 
-      QGateWithOrgDto qualityGate;
+      QualityGateDto qualityGate;
       if (uuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid);
+        qualityGate = wsSupport.getByUuid(dbSession, uuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, currentName);
+        qualityGate = wsSupport.getByName(dbSession, currentName);
       }
-      QualityGateDto renamedQualityGate = rename(dbSession, organization, qualityGate, request.mandatoryParam(PARAM_NAME));
+      QualityGateDto renamedQualityGate = rename(dbSession, qualityGate, request.mandatoryParam(PARAM_NAME));
       writeProtobuf(QualityGate.newBuilder()
         .setId(renamedQualityGate.getUuid())
         .setName(renamedQualityGate.getName())
@@ -106,17 +101,17 @@ public class RenameAction implements QualityGatesWsAction {
     }
   }
 
-  private QualityGateDto rename(DbSession dbSession, OrganizationDto organization, QGateWithOrgDto qualityGate, String name) {
+  private QualityGateDto rename(DbSession dbSession, QualityGateDto qualityGate, String name) {
     wsSupport.checkCanEdit(qualityGate);
-    checkNotAlreadyExists(dbSession, organization, qualityGate, name);
+    checkNotAlreadyExists(dbSession, qualityGate, name);
     qualityGate.setName(name);
     dbClient.qualityGateDao().update(qualityGate, dbSession);
     dbSession.commit();
     return qualityGate;
   }
 
-  private void checkNotAlreadyExists(DbSession dbSession, OrganizationDto organization, QualityGateDto qualityGate, String name) {
-    QualityGateDto existingQgate = dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name);
+  private void checkNotAlreadyExists(DbSession dbSession, QualityGateDto qualityGate, String name) {
+    QualityGateDto existingQgate = dbClient.qualityGateDao().selectByName(dbSession, name);
     boolean isModifyingCurrentQgate = existingQgate == null || existingQgate.getUuid().equals(qualityGate.getUuid());
     checkArgument(isModifyingCurrentQgate, "Name '%s' has already been taken", name);
   }
index e33db42e89a9459d62e9221cacd0343acdad9cf7..911924e04f42b9340426bda71e0161881752306f 100644 (file)
@@ -31,10 +31,9 @@ import org.sonar.api.web.UserRole;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualitygate.ProjectQgateAssociationDto;
 import org.sonar.db.qualitygate.ProjectQgateAssociationQuery;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
+import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.Qualitygates;
 
@@ -106,26 +105,22 @@ public class SearchAction implements QualityGatesWsAction {
     action.createParam(PARAM_PAGE_SIZE)
       .setDescription("Page size")
       .setExampleValue("10");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
   public void handle(Request request, Response response) {
     try (DbSession dbSession = dbClient.openSession(false)) {
 
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-
       String gateUuid = request.param(PARAM_GATE_ID);
       String gateName = request.param(PARAM_GATE_NAME);
 
       checkArgument(gateName != null ^ gateUuid != null, "One of 'gateId' or 'gateName' must be provided, and not both");
 
-      QGateWithOrgDto qualityGate;
+      QualityGateDto qualityGate;
       if (gateUuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, gateUuid);
+        qualityGate = wsSupport.getByUuid(dbSession, gateUuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, gateName);
+        qualityGate = wsSupport.getByName(dbSession, gateName);
       }
 
       ProjectQgateAssociationQuery projectQgateAssociationQuery = ProjectQgateAssociationQuery.builder()
index d5da28160b6284229ec149940b8cf485c2581807..8cfef102158d6deb1861bf2d6073896261434265 100644 (file)
@@ -25,9 +25,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.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -83,8 +81,6 @@ public class SelectAction implements QualityGatesWsAction {
       .setDescription("Project key")
       .setExampleValue(KEY_PROJECT_EXAMPLE_001)
       .setSince("6.1");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
@@ -96,14 +92,13 @@ public class SelectAction implements QualityGatesWsAction {
     checkArgument(gateName != null ^ gateUuid != null, "Either 'gateId' or 'gateName' must be provided, and not both");
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-      QGateWithOrgDto qualityGate;
+      QualityGateDto qualityGate;
       if (gateUuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, gateUuid);
+        qualityGate = wsSupport.getByUuid(dbSession, gateUuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, gateName);
+        qualityGate = wsSupport.getByName(dbSession, gateName);
       }
-      ProjectDto project = wsSupport.getProject(dbSession, organization, projectKey);
+      ProjectDto project = wsSupport.getProject(dbSession, projectKey);
       wsSupport.checkCanAdminProject(project);
 
       QualityGateDto currentQualityGate = dbClient.qualityGateDao().selectByProjectUuid(dbSession, project.getUuid());
index a66d3df2cbaf56ae91c67238faa47e06da4e6f55..04f9863a77add2e1b727e5bf01d0c4e28352327c 100644 (file)
@@ -25,7 +25,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.property.PropertyDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.user.UserSession;
 
@@ -37,6 +37,7 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME;
 
 public class SetAsDefaultAction implements QualityGatesWsAction {
+  private static final String DEFAULT_QUALITY_GATE_PROPERTY_NAME = "qualitygate.default";
 
   private final DbClient dbClient;
   private final UserSession userSession;
@@ -72,8 +73,6 @@ public class SetAsDefaultAction implements QualityGatesWsAction {
       .setMaximumLength(NAME_MAXIMUM_LENGTH)
       .setSince("8.4")
       .setExampleValue("SonarSource Way");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
@@ -83,17 +82,15 @@ public class SetAsDefaultAction implements QualityGatesWsAction {
     checkArgument(name != null ^ uuid != null, "One of 'id' or 'name' must be provided, and not both");
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getDefaultOrganization(dbSession);
       userSession.checkPermission(ADMINISTER_QUALITY_GATES);
       QualityGateDto qualityGate;
 
       if (uuid != null) {
-        qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid);
+        qualityGate = wsSupport.getByUuid(dbSession, uuid);
       } else {
-        qualityGate = wsSupport.getByOrganizationAndName(dbSession, organization, name);
+        qualityGate = wsSupport.getByName(dbSession, name);
       }
-      organization.setDefaultQualityGateUuid(qualityGate.getUuid());
-      dbClient.organizationDao().update(dbSession, organization);
+      dbClient.propertiesDao().saveProperty(new PropertyDto().setKey(DEFAULT_QUALITY_GATE_PROPERTY_NAME).setValue(qualityGate.getUuid()));
       dbSession.commit();
     }
 
index 79ba482f76e56c7b38063be4ed200eda11a5df33..b5e1060b88e844b6bc2230627b6babcafafb568a 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.QualityGateFinder;
@@ -45,7 +44,6 @@ import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
 import static org.sonar.core.util.stream.MoreCollectors.toList;
 import static org.sonar.core.util.stream.MoreCollectors.toSet;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
-import static org.sonar.server.exceptions.NotFoundException.checkFound;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
@@ -83,8 +81,6 @@ public class ShowAction implements QualityGatesWsAction {
     action.createParam(PARAM_NAME)
       .setDescription("Name of the quality gate. Either id or name must be set")
       .setExampleValue("My Quality Gate");
-
-    wsSupport.createOrganizationParam(action);
   }
 
   @Override
@@ -94,21 +90,20 @@ public class ShowAction implements QualityGatesWsAction {
     checkOneOfIdOrNamePresent(id, name);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
-      QualityGateDto qualityGate = getByNameOrUuid(dbSession, organization, name, id);
+      QualityGateDto qualityGate = getByNameOrUuid(dbSession, name, id);
       Collection<QualityGateConditionDto> conditions = getConditions(dbSession, qualityGate);
       Map<String, MetricDto> metricsByUuid = getMetricsByUuid(dbSession, conditions);
-      QualityGateDto defaultQualityGate = qualityGateFinder.getDefault(dbSession, organization);
+      QualityGateDto defaultQualityGate = qualityGateFinder.getDefault(dbSession);
       writeProtobuf(buildResponse(qualityGate, defaultQualityGate, conditions, metricsByUuid), request, response);
     }
   }
 
-  private QualityGateDto getByNameOrUuid(DbSession dbSession, OrganizationDto organization, @Nullable String name, @Nullable String uuid) {
+  private QualityGateDto getByNameOrUuid(DbSession dbSession, @Nullable String name, @Nullable String uuid) {
     if (name != null) {
-      return checkFound(dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name), "No quality gate has been found for name %s", name);
+      return wsSupport.getByName(dbSession, name);
     }
     if (uuid != null) {
-      return wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid);
+      return wsSupport.getByUuid(dbSession, uuid);
     }
     throw new IllegalArgumentException("No parameter has been set to identify a quality gate");
   }
index 8cc9dd81381f0a7ef634126db8d82fe6937de44f..60f6110921ad420df42f592a36bea9d9b280db3b 100644 (file)
@@ -25,9 +25,8 @@ 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.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
+import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.QualityGateConditionsUpdater;
 import org.sonarqube.ws.Qualitygates.UpdateConditionResponse;
 
@@ -74,7 +73,6 @@ public class UpdateConditionAction implements QualityGatesWsAction {
       .setExampleValue(UUID_EXAMPLE_01);
 
     addConditionParams(createCondition);
-    wsSupport.createOrganizationParam(createCondition);
   }
 
   @Override
@@ -85,9 +83,8 @@ public class UpdateConditionAction implements QualityGatesWsAction {
     String error = request.mandatoryParam(PARAM_ERROR);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
       QualityGateConditionDto condition = wsSupport.getCondition(dbSession, id);
-      QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, condition.getQualityGateUuid());
+      QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByUuid(dbSession, condition.getQualityGateUuid());
       checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", id, condition.getQualityGateUuid());
       wsSupport.checkCanEdit(qualityGateDto);
       QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator, error);
index 8350a1dae381058613b82810ca0cf8deada52d13..36607577f49a8606d9e46ff6962d63a1d590ee2b 100644 (file)
@@ -45,7 +45,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.LiveMeasureDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.property.PropertyDto;
 import org.sonar.db.property.PropertyQuery;
@@ -53,7 +52,6 @@ import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.project.Visibility;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.qualityprofile.QPMeasureData;
@@ -61,7 +59,6 @@ import org.sonar.server.qualityprofile.QualityProfile;
 import org.sonar.server.ui.PageRepository;
 import org.sonar.server.user.UserSession;
 
-import static java.lang.String.format;
 import static java.util.Collections.emptySortedSet;
 import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY;
 import static org.sonar.api.utils.DateUtils.formatDateTime;
@@ -246,11 +243,7 @@ public class ComponentAction implements NavigationWsAction {
   }
 
   private void writeQualityGate(JsonWriter json, DbSession session, ComponentDto component) {
-    // TODO:: remove while dropping for quality gate
-    OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(session, component.getOrganizationUuid())
-      .orElseThrow(IllegalStateException::new);
-    QualityGateFinder.QualityGateData qualityGateData = qualityGateFinder.getQualityGate(session, organizationDto, component.uuid())
-      .orElseThrow(() -> new NotFoundException(format("Quality Gate not found for %s", component.getKey())));
+    QualityGateFinder.QualityGateData qualityGateData = qualityGateFinder.getQualityGate(session, component.uuid());
     QualityGateDto qualityGateDto = qualityGateData.getQualityGate();
     json.name("qualityGate").beginObject()
       .prop("key", qualityGateDto.getUuid())
index 9e087c9ff47580f1b747ff72b383c6dd31d123eb..e626c7205d1f7fdd7c65230bafc07d3abf37f1be 100644 (file)
@@ -81,7 +81,7 @@ public class LiveMeasureComputerImplTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private TestProjectIndexers projectIndexer = new TestProjectIndexers();
+  private final TestProjectIndexers projectIndexer = new TestProjectIndexers();
   private MetricDto intMetric;
   private MetricDto ratingMetric;
   private MetricDto alertStatusMetric;
@@ -93,9 +93,9 @@ public class LiveMeasureComputerImplTest {
   private ComponentDto file2;
   private ComponentDto branch;
   private ComponentDto branchFile;
-  private LiveQualityGateComputer qGateComputer = mock(LiveQualityGateComputer.class);
-  private QualityGate qualityGate = mock(QualityGate.class);
-  private EvaluatedQualityGate newQualityGate = mock(EvaluatedQualityGate.class);
+  private final LiveQualityGateComputer qGateComputer = mock(LiveQualityGateComputer.class);
+  private final QualityGate qualityGate = mock(QualityGate.class);
+  private final EvaluatedQualityGate newQualityGate = mock(EvaluatedQualityGate.class);
 
   @Before
   public void setUp() {
@@ -370,7 +370,7 @@ public class LiveMeasureComputerImplTest {
       .extracting(QGChangeEvent::getQualityGateSupplier)
       .extracting(Supplier::get)
       .containsExactly(Optional.of(newQualityGate));
-    verify(qGateComputer).loadQualityGate(any(DbSession.class), eq(organization), argThat(p -> p.getUuid().equals(projectDto.getUuid())), eq(branch));
+    verify(qGateComputer).loadQualityGate(any(DbSession.class), argThat(p -> p.getUuid().equals(projectDto.getUuid())), eq(branch));
     verify(qGateComputer).getMetricsRelatedTo(qualityGate);
     verify(qGateComputer).refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class));
   }
@@ -395,7 +395,7 @@ public class LiveMeasureComputerImplTest {
   private List<QGChangeEvent> run(Collection<ComponentDto> components, IssueMetricFormula... formulas) {
     IssueMetricFormulaFactory formulaFactory = new TestIssueMetricFormulaFactory(asList(formulas));
 
-    when(qGateComputer.loadQualityGate(any(DbSession.class), any(OrganizationDto.class), any(ProjectDto.class), any(BranchDto.class)))
+    when(qGateComputer.loadQualityGate(any(DbSession.class), any(ProjectDto.class), any(BranchDto.class)))
       .thenReturn(qualityGate);
     when(qGateComputer.getMetricsRelatedTo(qualityGate)).thenReturn(singleton(CoreMetrics.ALERT_STATUS_KEY));
     when(qGateComputer.refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class)))
@@ -450,7 +450,7 @@ public class LiveMeasureComputerImplTest {
     assertThat(measure.getComponentUuid()).isEqualTo(component.uuid());
     assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid());
     assertThat(measure.getMetricUuid()).isEqualTo(ratingMetric.getUuid());
-    assertThat(measure.getVariation()).isEqualTo((double) expectedValue.getIndex());
+    assertThat(measure.getVariation()).isEqualTo(expectedValue.getIndex());
   }
 
   private IssueMetricFormula newIncrementalFormula() {
index 9829c51671ddf0a272ba1dbd6766fe25b75c2170..0416ed408b3f1deab6c9655dd6895ea80c4b466b 100644 (file)
@@ -35,10 +35,9 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.measure.LiveMeasureDto;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
+import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.Condition;
 import org.sonar.server.qualitygate.EvaluatedCondition;
 import org.sonar.server.qualitygate.EvaluatedQualityGate;
@@ -63,39 +62,37 @@ public class LiveQualityGateComputerImplTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private TestQualityGateEvaluator qualityGateEvaluator = new TestQualityGateEvaluator();
-  private LiveQualityGateComputerImpl underTest = new LiveQualityGateComputerImpl(db.getDbClient(), new QualityGateFinder(db.getDbClient()), qualityGateEvaluator);
+  private final TestQualityGateEvaluator qualityGateEvaluator = new TestQualityGateEvaluator();
+  private final LiveQualityGateComputerImpl underTest = new LiveQualityGateComputerImpl(db.getDbClient(), new QualityGateFinder(db.getDbClient()), qualityGateEvaluator);
 
   @Test
   public void loadQualityGate_returns_hardcoded_gate_for_pull_requests() {
-    OrganizationDto organization = db.organizations().insert();
-    ProjectDto project = db.components().insertPublicProjectDto(organization);
+    ProjectDto project = db.components().insertPublicProjectDto();
     BranchDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
     MetricDto metric1 = db.measures().insertMetric(m -> m.setKey("new_metric"));
     MetricDto metric2 = db.measures().insertMetric(m -> m.setKey("metric"));
 
-    QGateWithOrgDto gate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, gate);
+    QualityGateDto gate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(gate);
 
     db.qualityGates().addCondition(gate, metric1);
     db.qualityGates().addCondition(gate, metric2);
 
-    QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, branch);
+    QualityGate result = underTest.loadQualityGate(db.getSession(), project, branch);
     assertThat(result.getConditions()).extracting(Condition::getMetricKey).containsExactly("new_metric");
   }
 
   @Test
   public void loadQualityGate_on_branch_returns_organization_default_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    ProjectDto project = db.components().insertPublicProjectDto(organization);
+    ProjectDto project = db.components().insertPublicProjectDto();
     BranchDto branch = db.components().insertProjectBranch(project).setBranchType(BranchType.BRANCH);
 
     MetricDto metric = db.measures().insertMetric();
-    QGateWithOrgDto gate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, gate);
+    QualityGateDto gate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(gate);
     QualityGateConditionDto condition = db.qualityGates().addCondition(gate, metric);
 
-    QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, branch);
+    QualityGate result = underTest.loadQualityGate(db.getSession(), project, branch);
 
     assertThat(result.getId()).isEqualTo("" + gate.getUuid());
     assertThat(result.getConditions())
index 67af28d0249ce68b3caf833ad52f2f7d98e59aa8..8969a0fd54b5d766fd9442fa6525ea31b68ee495 100644 (file)
@@ -61,12 +61,12 @@ public class QualityGateConditionsUpdaterTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private QualityGateConditionsUpdater underTest = new QualityGateConditionsUpdater(db.getDbClient());
+  private final QualityGateConditionsUpdater underTest = new QualityGateConditionsUpdater(db.getDbClient());
 
   @Test
   public void create_error_condition() {
     MetricDto metric = insertMetric(INT, "new_coverage");
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", "80");
 
@@ -77,7 +77,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("valid_operators_and_direction")
   public void create_condition_with_valid_operators_and_direction(String operator, int direction) {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey("key").setValueType(INT.name()).setHidden(false).setDirection(direction));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), operator, "80");
 
@@ -87,7 +87,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void create_condition_throws_NPE_if_errorThreshold_is_null() {
     MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("errorThreshold can not be null");
@@ -98,7 +98,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void fail_to_create_condition_when_condition_on_same_metric_already_exist() {
     MetricDto metric = insertMetric(PERCENT);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     db.qualityGates().addCondition(qualityGate, metric);
 
     expectedException.expect(BadRequestException.class);
@@ -109,7 +109,7 @@ public class QualityGateConditionsUpdaterTest {
 
   @Test
   public void fail_to_create_condition_on_missing_metric() {
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("There is no metric with key=new_coverage");
@@ -121,7 +121,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("invalid_metrics")
   public void fail_to_create_condition_on_invalid_metric(String metricKey, Metric.ValueType valueType, boolean hidden) {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(metricKey).setValueType(valueType.name()).setHidden(hidden).setDirection(0));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Metric '%s' cannot be used to define a condition", metric.getKey()));
@@ -133,7 +133,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("invalid_operators_and_direction")
   public void fail_to_create_condition_on_not_allowed_operator_for_metric_direction(String operator, int direction) {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey("key").setValueType(INT.name()).setHidden(false).setDirection(direction));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Operator %s is not allowed for this metric.", operator));
@@ -144,7 +144,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void create_condition_on_rating_metric() {
     MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "3");
 
@@ -154,7 +154,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void fail_to_create_error_condition_on_invalid_rating_metric() {
     MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("'80' is not a valid rating");
@@ -165,7 +165,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void fail_to_create_condition_on_rating_greater_than_E() {
     MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("There's no worse rating than E (5)");
@@ -177,7 +177,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("valid_values")
   public void create_error_condition(Metric.ValueType valueType, String value) {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false).setDirection(0));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", value);
 
@@ -188,7 +188,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("invalid_values")
   public void fail_to_create_error_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false).setDirection(0));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Invalid value '%s' for metric '%s'", value, metric.getShortName()));
@@ -199,7 +199,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void update_condition() {
     MetricDto metric = insertMetric(PERCENT);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
 
@@ -211,7 +211,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void update_condition_throws_NPE_if_errorThreshold_is_null() {
     MetricDto metric = insertMetric(PERCENT);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
 
@@ -224,7 +224,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void update_condition_on_rating_metric() {
     MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
 
@@ -237,7 +237,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("update_invalid_operators_and_direction")
   public void fail_to_update_condition_on_not_allowed_operator_for_metric_direction(String validOperator, String updatedOperator, int direction) {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(PERCENT.name()).setHidden(false).setDirection(direction));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator(validOperator).setErrorThreshold("80"));
 
@@ -250,7 +250,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void fail_to_update_condition_on_rating_metric_on_new_code_period() {
     MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("3"));
 
@@ -262,7 +262,7 @@ public class QualityGateConditionsUpdaterTest {
   @Test
   public void fail_to_update_condition_on_rating_metric_on_not_core_rating_metric() {
     MetricDto metric = insertMetric(RATING, "not_core_rating_metric");
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("3"));
 
@@ -276,7 +276,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("invalid_metrics")
   public void fail_to_update_condition_on_invalid_metric(String metricKey, Metric.ValueType valueType, boolean hidden) {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(metricKey).setValueType(valueType.name()).setHidden(hidden));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
 
@@ -290,7 +290,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("valid_values")
   public void update_error_condition(Metric.ValueType valueType, String value) {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false).setDirection(0));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
 
@@ -303,7 +303,7 @@ public class QualityGateConditionsUpdaterTest {
   @UseDataProvider("invalid_values")
   public void fail_to_update_error_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false).setDirection(0));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
 
index 3c0df4855cddea6ab8aff33e93b1e1401c8a24a9..8c0005251968d40bbd5f7404a0cd0ddcd6204f91 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -42,15 +41,13 @@ public class QualityGateUpdaterTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-  private QualityGateUpdater underTest = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance());
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final QualityGateUpdater underTest = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance());
 
   @Test
   public void create_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-
-    QualityGateDto result = underTest.create(dbSession, organization, QGATE_NAME);
+    QualityGateDto result = underTest.create(dbSession, QGATE_NAME);
 
     assertThat(result).isNotNull();
     assertThat(result.getName()).isEqualTo(QGATE_NAME);
@@ -62,12 +59,11 @@ public class QualityGateUpdaterTest {
 
   @Test
   public void fail_to_create_when_name_already_exists() {
-    OrganizationDto org = db.organizations().insert();
-    underTest.create(dbSession, org, QGATE_NAME);
+    underTest.create(dbSession, QGATE_NAME);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name has already been taken");
 
-    underTest.create(dbSession, org, QGATE_NAME);
+    underTest.create(dbSession, QGATE_NAME);
   }
 }
index fc5578b59eb55edb155e7c5c867dd28585f8a985..22e6acc4ea367853d0854a2a9b4392f7730b9b80 100644 (file)
@@ -64,16 +64,16 @@ public class RegisterQualityGatesTest {
 
   private static final String BUILT_IN_NAME = "Sonar way";
 
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
 
-  private QualityGateDao qualityGateDao = dbClient.qualityGateDao();
-  private QualityGateConditionDao gateConditionDao = dbClient.gateConditionDao();
-  private MetricDao metricDao = dbClient.metricDao();
-  private QualityGateConditionsUpdater qualityGateConditionsUpdater = new QualityGateConditionsUpdater(dbClient);
-  private QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
+  private final QualityGateDao qualityGateDao = dbClient.qualityGateDao();
+  private final QualityGateConditionDao gateConditionDao = dbClient.gateConditionDao();
+  private final MetricDao metricDao = dbClient.metricDao();
+  private final QualityGateConditionsUpdater qualityGateConditionsUpdater = new QualityGateConditionsUpdater(dbClient);
+  private final QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
 
-  private RegisterQualityGates underTest = new RegisterQualityGates(dbClient, qualityGateConditionsUpdater,
+  private final RegisterQualityGates underTest = new RegisterQualityGates(dbClient, qualityGateConditionsUpdater,
     UuidFactoryFast.getInstance(), System2.INSTANCE);
 
   @Test
@@ -249,7 +249,6 @@ public class RegisterQualityGatesTest {
     MetricDto newDuplication = metricDao.selectByKey(dbSession, NEW_DUPLICATED_LINES_DENSITY_KEY);
     MetricDto newSecurityHotspots = metricDao.selectByKey(dbSession, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY);
 
-
     QualityGateDto qualityGateDto = qualityGateDao.selectByName(dbSession, BUILT_IN_NAME);
     assertThat(qualityGateDto).isNotNull();
     assertThat(qualityGateDto.getCreatedAt()).isNotNull();
index acdc55d28bb284de5c0c0df0759201dcecc589f7..ef9247975ffd8618bf61f6d93fb0c0da05865d76 100644 (file)
@@ -34,21 +34,17 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateUpdater;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.Qualitygates.QualityGate;
 
-import static java.lang.String.format;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.AssertionsForClassTypes.tuple;
@@ -56,7 +52,6 @@ import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 
 @RunWith(DataProviderRunner.class)
 public class CopyActionTest {
@@ -65,19 +60,18 @@ public class CopyActionTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
-  public UserSessionRule userSession = UserSessionRule.standalone();
+  public final UserSessionRule userSession = UserSessionRule.standalone();
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public final DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-  private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-  private QualityGateUpdater qualityGateUpdater = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance());
-  private QualityGatesWsSupport wsSupport = new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider, TestComponentFinder.from(db));
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final QualityGateUpdater qualityGateUpdater = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance());
+  private final QualityGatesWsSupport wsSupport = new QualityGatesWsSupport(dbClient, userSession, TestComponentFinder.from(db));
 
-  private CopyAction underTest = new CopyAction(dbClient, userSession, qualityGateUpdater, wsSupport);
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final CopyAction underTest = new CopyAction(dbClient, userSession, qualityGateUpdater, wsSupport);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void definition() {
@@ -92,27 +86,23 @@ public class CopyActionTest {
       .containsExactlyInAnyOrder(
         tuple("id", false),
         tuple("sourceName", false),
-        tuple("organization", false),
         tuple("name", true));
   }
 
   @Test
   public void copy() {
-
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
       .setParam(PARAM_NAME, "new-name")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
-    QGateWithOrgDto actual = db.getDbClient().qualityGateDao().selectByOrganizationAndName(dbSession, organization, "new-name");
+    QualityGateDto actual = db.getDbClient().qualityGateDao().selectByName(dbSession, "new-name");
     assertThat(actual).isNotNull();
     assertThat(actual.isBuiltIn()).isFalse();
     assertThat(actual.getUuid()).isNotEqualTo(qualityGate.getUuid());
@@ -123,32 +113,14 @@ public class CopyActionTest {
       .containsExactlyInAnyOrder(tuple(metric.getUuid(), condition.getErrorThreshold()));
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    OrganizationDto defaultOrganization = db.getDefaultOrganization();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(defaultOrganization);
-
-    ws.newRequest()
-      .setParam(PARAM_ID, qualityGate.getUuid())
-      .setParam(PARAM_NAME, "new-name")
-      .execute();
-
-    QGateWithOrgDto actual = db.getDbClient().qualityGateDao().selectByOrganizationAndName(dbSession, defaultOrganization, "new-name");
-    assertThat(actual).isNotNull();
-    assertThat(actual.getOrganizationUuid()).isEqualTo(defaultOrganization.getUuid());
-  }
-
   @Test
   public void copy_of_builtin_should_not_be_builtin() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qualityGateDto -> qualityGateDto.setBuiltIn(true));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qualityGateDto -> qualityGateDto.setBuiltIn(true));
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
       .setParam(PARAM_NAME, "new-name")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
     QualityGateDto actual = db.getDbClient().qualityGateDao().selectByName(dbSession, "new-name");
@@ -159,7 +131,7 @@ public class CopyActionTest {
   @Test
   public void response_contains_quality_gate() {
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     QualityGate response = ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
@@ -171,65 +143,22 @@ public class CopyActionTest {
     assertThat(response.getName()).isEqualTo("new-name");
   }
 
-  @Test
-  public void quality_gates_can_have_the_same_name_in_different_organization() {
-    OrganizationDto organization1 = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(organization1);
-
-    OrganizationDto organization2 = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(organization2);
-
-    assertThat(qualityGate1.getName()).isNotEqualTo(qualityGate2.getName());
-
-    ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization2.getKey())
-      .setParam(PARAM_ID, qualityGate2.getUuid())
-      .setParam(PARAM_NAME, qualityGate1.getName())
-      .execute();
-
-    QGateWithOrgDto actual = db.getDbClient().qualityGateDao().selectByOrganizationAndName(dbSession, organization2, qualityGate1.getName());
-    assertThat(actual).isNotNull();
-  }
-
-  @Test
-  public void quality_gate_from_external_organization_can_not_be_copied() {
-    OrganizationDto organization1 = db.organizations().insert();
-    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(organization1);
-
-    OrganizationDto organization2 = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate1.getUuid(), organization2.getName()));
-
-    ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization2.getKey())
-      .setParam(PARAM_ID, qualityGate1.getUuid())
-      .setParam(PARAM_NAME, "new-name")
-      .execute();
-  }
-
   @Test
   public void fail_when_missing_administer_quality_gate_permission() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES);
 
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
       .setParam(PARAM_NAME, "new-name")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_id_parameter_is_missing() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(IllegalArgumentException.class);
@@ -237,36 +166,30 @@ public class CopyActionTest {
 
     ws.newRequest()
       .setParam(PARAM_NAME, "new-name")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_quality_gate_id_is_not_found() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format(
-      "No quality gate has been found for id 123 in organization %s", organization.getName()));
+    expectedException.expectMessage("No quality gate has been found for id 123");
 
     ws.newRequest()
       .setParam(PARAM_ID, "123")
       .setParam(PARAM_NAME, "new-name")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   @UseDataProvider("nullOrEmpty")
   public void fail_when_name_parameter_is_missing(@Nullable String nameParameter) {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     TestRequest request = ws.newRequest()
-      .setParam(PARAM_ID, qualityGate.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey());
+      .setParam(PARAM_ID, qualityGate.getUuid());
     ofNullable(nameParameter).ifPresent(t -> request.setParam(PARAM_NAME, t));
 
     expectedException.expect(IllegalArgumentException.class);
@@ -285,11 +208,10 @@ public class CopyActionTest {
   }
 
   @Test
-  public void fail_when_name_parameter_match_existing_quality_gate_in_the_same_organization() {
-    OrganizationDto organization = db.organizations().insert();
+  public void fail_when_name_parameter_match_existing_quality_gate() {
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QualityGateDto existingQualityGate = db.qualityGates().insertQualityGate(organization);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto existingQualityGate = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name has already been taken");
@@ -297,7 +219,6 @@ public class CopyActionTest {
     ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
       .setParam(PARAM_NAME, existingQualityGate.getName())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 }
index ff1c60240f206f960af1ca8ebc4e6a11c054e70b..4ada3cf575b7c9eafaafdfdd016d8d20fa40fd99 100644 (file)
@@ -34,14 +34,8 @@ import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDbTester;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
-import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateUpdater;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
@@ -51,7 +45,6 @@ import org.sonarqube.ws.Qualitygates.CreateResponse;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 
 @RunWith(DataProviderRunner.class)
 public class CreateActionTest {
@@ -65,62 +58,41 @@ public class CreateActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private OrganizationDbTester organizationDbTester = new OrganizationDbTester(db);
-  private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-  private CreateAction underTest = new CreateAction(dbClient, userSession, new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance()),
-    new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider, TestComponentFinder.from(db)));
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final CreateAction underTest = new CreateAction(dbClient, userSession, new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance()));
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
-  public void default_organization_is_used_when_no_parameter() {
-    logInAsQualityGateAdmin(db.getDefaultOrganization());
+  public void default_is_used_when_no_parameter() {
+    logInAsQualityGateAdmin();
 
     String qgName = "Default";
-    CreateResponse response = executeRequest(Optional.empty(), qgName);
+    CreateResponse response = executeRequest(qgName);
 
     assertThat(response.getName()).isEqualTo(qgName);
     assertThat(response.getId()).isNotNull();
     dbSession.commit();
 
-    QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, db.getDefaultOrganization(), qgName);
+    QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByName(dbSession, qgName);
     assertThat(qualityGateDto).isNotNull();
   }
 
   @Test
-  public void create_quality_gate_with_organization() {
-    OrganizationDto organizationDto = organizationDbTester.insert();
-    logInAsQualityGateAdmin(organizationDto);
+  public void create_quality_gate() {
+    logInAsQualityGateAdmin();
 
     String qgName = "Default";
-    CreateResponse response = executeRequest(Optional.of(organizationDto), qgName);
+    CreateResponse response = executeRequest(qgName);
 
     assertThat(response.getName()).isEqualTo(qgName);
     assertThat(response.getId()).isNotNull();
     dbSession.commit();
 
-    QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organizationDto, qgName);
+    QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByName(dbSession, qgName);
     assertThat(qualityGateDto).isNotNull();
   }
 
-  @Test
-  public void creating_a_qg_with_a_name_used_in_another_organization_should_work() {
-    OrganizationDto anOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(anOrganization);
-    OrganizationDto anotherOrganization = db.organizations().insert();
-
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-
-    CreateResponse response = ws.newRequest()
-      .setParam(PARAM_NAME, qualityGate.getName())
-      .setParam(PARAM_ORGANIZATION, anotherOrganization.getKey())
-      .executeProtobuf(CreateResponse.class);
-
-    assertThat(response.getName()).isEqualTo(qualityGate.getName());
-    assertThat(response.getId()).isNotEqualTo(qualityGate.getUuid());
-  }
-
   @Test
   public void test_ws_definition() {
     WebService.Action action = ws.getDef();
@@ -128,10 +100,9 @@ public class CreateActionTest {
     assertThat(action.isInternal()).isFalse();
     assertThat(action.isPost()).isTrue();
     assertThat(action.responseExampleAsString()).isNotEmpty();
-    assertThat(action.params()).hasSize(2);
+    assertThat(action.params()).hasSize(1);
   }
 
-
   @Test
   public void throw_ForbiddenException_if_not_gate_administrator() {
     userSession.logIn();
@@ -139,42 +110,27 @@ public class CreateActionTest {
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
 
-    executeRequest(Optional.empty(), "Default");
-  }
-
-  @Test
-  public void throw_ForbiddenException_if_unknown_organization() {
-    OrganizationDto org = new OrganizationDto().setName("Unknown organization").setKey("unknown_key");
-
-    userSession.logIn();
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("No organization with key 'unknown_key'");
-
-    executeRequest(Optional.of(org), "Default");
+    executeRequest("Default");
   }
 
   @Test
   public void throw_BadRequestException_if_name_is_already_used() {
-    OrganizationDto org = db.organizations().insert();
     userSession.logIn().addPermission(ADMINISTER_QUALITY_GATES);
 
-    executeRequest(Optional.of(org), "Default");
+    executeRequest("Default");
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Name has already been taken");
 
-    executeRequest(Optional.of(org), "Default");
+    executeRequest("Default");
   }
 
   @Test
   @UseDataProvider("nullOrEmpty")
   public void fail_when_name_parameter_is_empty(@Nullable String nameParameter) {
-    OrganizationDto org = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
-    TestRequest request = ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, org.getKey());
+    TestRequest request = ws.newRequest();
     Optional.ofNullable(nameParameter).ifPresent(t -> request.setParam(PARAM_NAME, ""));
 
     expectedException.expect(IllegalArgumentException.class);
@@ -192,20 +148,13 @@ public class CreateActionTest {
     };
   }
 
-  private CreateResponse executeRequest(Optional<OrganizationDto> organization, String qualitGateName) {
-    if (organization.isPresent()) {
-      return ws.newRequest()
-        .setParam("name", qualitGateName)
-        .setParam("organization", organization.get().getKey())
-        .executeProtobuf(CreateResponse.class);
-    } else {
-      return ws.newRequest()
-        .setParam("name", qualitGateName)
-        .executeProtobuf(CreateResponse.class);
-    }
+  private CreateResponse executeRequest(String qualitGateName) {
+    return ws.newRequest()
+      .setParam("name", qualitGateName)
+      .executeProtobuf(CreateResponse.class);
   }
 
-  private void logInAsQualityGateAdmin(OrganizationDto organizationDto) {
+  private void logInAsQualityGateAdmin() {
     userSession.logIn().addPermission(ADMINISTER_QUALITY_GATES);
   }
 }
index 3b1aeff9bb22ab9d3ce0794f5b24e26f6bb69390..9e06daccba89b1ca9abcab2817c5a837db5f9e19 100644 (file)
@@ -32,14 +32,11 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateConditionsUpdater;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -54,7 +51,6 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ERR
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 
 @RunWith(DataProviderRunner.class)
 public class CreateConditionActionTest {
@@ -68,19 +64,17 @@ public class CreateConditionActionTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-  private CreateConditionAction underTest = new CreateConditionAction(dbClient, new QualityGateConditionsUpdater(dbClient),
-    new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider, TestComponentFinder.from(db)));
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final CreateConditionAction underTest = new CreateConditionAction(dbClient, new QualityGateConditionsUpdater(dbClient),
+    new QualityGatesWsSupport(dbClient, userSession, TestComponentFinder.from(db)));
 
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void create_error_condition() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    logInAsQualityGateAdmin();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
 
     ws.newRequest()
@@ -88,7 +82,6 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
     assertCondition(qualityGate, metric, "LT", "90");
@@ -96,9 +89,8 @@ public class CreateConditionActionTest {
 
   @Test
   public void create_condition_over_new_code_period() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    logInAsQualityGateAdmin();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
 
     ws.newRequest()
@@ -106,36 +98,15 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
     assertCondition(qualityGate, metric, "LT", "90");
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    logInAsQualityGateAdmin(db.getDefaultOrganization());
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-
-    MetricDto metric = insertMetric();
-
-    ws.newRequest()
-      .setParam(PARAM_GATE_ID, qualityGate.getUuid())
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_ERROR, "10")
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "10");
-  }
-
   @Test
   public void fail_to_update_built_in_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
+    logInAsQualityGateAdmin();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
     MetricDto metric = insertMetric();
 
     expectedException.expect(IllegalArgumentException.class);
@@ -146,15 +117,13 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_with_unknown_operator() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    logInAsQualityGateAdmin();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(INT.name()).setHidden(false).setDirection(0));
 
     expectedException.expect(IllegalArgumentException.class);
@@ -165,16 +134,14 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "ABC")
       .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   @UseDataProvider("invalid_operators_for_direction")
   public void fail_with_invalid_operators_for_direction(String operator, int direction) {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    logInAsQualityGateAdmin();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(INT.name()).setHidden(false).setDirection(direction));
 
     expectedException.expect(BadRequestException.class);
@@ -185,15 +152,13 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, operator)
       .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void test_response() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    logInAsQualityGateAdmin();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
 
     CreateConditionResponse response = ws.newRequest()
@@ -201,7 +166,6 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "45")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .executeProtobuf(CreateConditionResponse.class);
 
     QualityGateConditionDto condition = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid())).get(0);
@@ -213,8 +177,7 @@ public class CreateConditionActionTest {
 
   @Test
   public void throw_ForbiddenException_if_not_gate_administrator() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
     userSession.logIn();
 
@@ -226,7 +189,6 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
@@ -244,8 +206,7 @@ public class CreateConditionActionTest {
         tuple("gateName", false),
         tuple("metric", true),
         tuple("error", true),
-        tuple("op", false),
-        tuple("organization", false));
+        tuple("op", false));
   }
 
   @DataProvider
@@ -263,7 +224,7 @@ public class CreateConditionActionTest {
       .containsExactlyInAnyOrder(tuple(qualityGate.getUuid(), metric.getUuid(), operator, error));
   }
 
-  private void logInAsQualityGateAdmin(OrganizationDto organization) {
+  private void logInAsQualityGateAdmin() {
     userSession.logIn().addPermission(ADMINISTER_QUALITY_GATES);
   }
 
index 80edcc1c8e88928014aa2cd844f36711f41935a1..97de012c9882518a1069283bc5f42bfd2f85c092 100644 (file)
@@ -26,14 +26,11 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
@@ -45,7 +42,6 @@ import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 
 public class DeleteConditionActionTest {
 
@@ -56,10 +52,8 @@ public class DeleteConditionActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private TestDefaultOrganizationProvider organizationProvider = TestDefaultOrganizationProvider.from(db);
-
-  private WsActionTester ws = new WsActionTester(
-    new DeleteConditionAction(db.getDbClient(), new QualityGatesWsSupport(db.getDbClient(), userSession, organizationProvider, TestComponentFinder.from(db))));
+  private final WsActionTester ws = new WsActionTester(
+    new DeleteConditionAction(db.getDbClient(), new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db))));
 
   @Test
   public void definition() {
@@ -70,30 +64,13 @@ public class DeleteConditionActionTest {
     assertThat(action.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
-        tuple("id", true),
-        tuple("organization", false));
+        tuple("id", true));
   }
 
   @Test
   public void delete_condition() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = db.measures().insertMetric();
-    QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
-
-    ws.newRequest()
-      .setParam(PARAM_ID, qualityGateCondition.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .execute();
-
-    assertThat(searchConditionsOf(qualityGate)).isEmpty();
-  }
-
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
@@ -106,15 +83,13 @@ public class DeleteConditionActionTest {
 
   @Test
   public void no_content() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
     TestResponse result = ws.newRequest()
       .setParam(PARAM_ID, qualityGateCondition.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
     assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT);
@@ -122,9 +97,8 @@ public class DeleteConditionActionTest {
 
   @Test
   public void fail_if_built_in_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
@@ -133,15 +107,13 @@ public class DeleteConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGateCondition.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_if_not_quality_gate_administrator() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
 
@@ -149,15 +121,13 @@ public class DeleteConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGateCondition.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_if_condition_uuid_is_not_found() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric();
     QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
     String unknownConditionUuid = "unknown";
@@ -167,13 +137,11 @@ public class DeleteConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ID, unknownConditionUuid)
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_condition_match_unknown_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_PROFILES);
     QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setMetricUuid("metric").setQualityGateUuid("123");
     db.getDbClient().gateConditionDao().insert(condition, db.getSession());
@@ -184,25 +152,6 @@ public class DeleteConditionActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ID, condition.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .execute();
-  }
-
-  @Test
-  public void fail_when_condition_match_quality_gate_on_other_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_PROFILES);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-    MetricDto metric = db.measures().insertMetric();
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
-
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), qualityGate.getUuid()));
-
-    ws.newRequest()
-      .setParam(PARAM_ID, condition.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
index 77e537585689fc804c9dfd74f07b1d1f75402195..38c4aab502763746405bcc86f99c3aa8df2dcc6f 100644 (file)
@@ -29,15 +29,12 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 
@@ -56,23 +53,20 @@ public class DeselectActionTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private DbClient dbClient = db.getDbClient();
-  private TestDefaultOrganizationProvider organizationProvider = TestDefaultOrganizationProvider.from(db);
-  private ComponentFinder componentFinder = TestComponentFinder.from(db);
-  private DeselectAction underTest = new DeselectAction(dbClient, new QualityGatesWsSupport(db.getDbClient(), userSession, organizationProvider, componentFinder));
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final DbClient dbClient = db.getDbClient();
+  private final ComponentFinder componentFinder = TestComponentFinder.from(db);
+  private final DeselectAction underTest = new DeselectAction(dbClient, new QualityGatesWsSupport(db.getDbClient(), userSession, componentFinder));
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void deselect_by_key() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
     associateProjectToQualityGate(project, qualityGate);
 
     ws.newRequest()
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertDeselected(project);
@@ -80,15 +74,13 @@ public class DeselectActionTest {
 
   @Test
   public void project_admin() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
     associateProjectToQualityGate(project, qualityGate);
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     ws.newRequest()
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertDeselected(project);
@@ -96,18 +88,16 @@ public class DeselectActionTest {
 
   @Test
   public void other_project_should_not_be_updated() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
     associateProjectToQualityGate(project, qualityGate);
     // Another project
-    ProjectDto anotherProject = db.components().insertPrivateProjectDto(organization);
+    ProjectDto anotherProject = db.components().insertPrivateProjectDto();
     associateProjectToQualityGate(anotherProject, qualityGate);
 
     ws.newRequest()
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertDeselected(project);
@@ -115,11 +105,10 @@ public class DeselectActionTest {
   }
 
   @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    OrganizationDto organization = db.getDefaultOrganization();
+  public void default_is_used() {
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project = db.components().insertPrivateProjectDto();
     associateProjectToQualityGate(project, qualityGate);
 
     ws.newRequest()
@@ -129,67 +118,44 @@ public class DeselectActionTest {
     assertDeselected(project);
   }
 
-  @Test
-  public void fail_when_project_belongs_to_another_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    OrganizationDto anotherOrganization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(anotherOrganization);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("Project '%s' doesn't exist in organization '%s'", project.getKey(), organization.getKey()));
-
-    ws.newRequest()
-      .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
-      .execute();
-  }
-
   @Test
   public void fail_when_no_project_key() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(NotFoundException.class);
 
     ws.newRequest()
       .setParam("projectKey", "unknown")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_anonymous() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.anonymous();
 
     expectedException.expect(ForbiddenException.class);
     ws.newRequest()
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_not_project_admin() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project);
 
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_not_quality_gates_admin() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
 
     userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES);
 
@@ -197,14 +163,12 @@ public class DeselectActionTest {
 
     ws.newRequest()
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_using_branch_db_key() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPublicProject(organization);
+    ComponentDto project = db.components().insertPublicProject();
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
 
@@ -213,7 +177,6 @@ public class DeselectActionTest {
 
     ws.newRequest()
       .setParam("projectKey", branch.getDbKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
@@ -231,8 +194,7 @@ public class DeselectActionTest {
     assertThat(def.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
-        tuple("projectKey", true),
-        tuple("organization", false));
+        tuple("projectKey", true));
   }
 
   private void associateProjectToQualityGate(ProjectDto project, QualityGateDto qualityGate) {
@@ -247,7 +209,7 @@ public class DeselectActionTest {
       .isEmpty();
   }
 
-  private void assertSelected(QGateWithOrgDto qualityGate, ProjectDto project) {
+  private void assertSelected(QualityGateDto qualityGate, ProjectDto project) {
     Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
     assertThat(qGateUuid)
       .isNotNull()
index 68e47b68c89789a2029a392093febc51c6bf10e9..08968ed41aa5788a6b8175cb92ab62ca4eba88e2 100644 (file)
@@ -28,14 +28,11 @@ import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -48,7 +45,6 @@ import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 
 public class DestroyActionTest {
 
@@ -59,59 +55,52 @@ public class DestroyActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbClient dbClient = db.getDbClient();
-  private TestDefaultOrganizationProvider organizationProvider = TestDefaultOrganizationProvider.from(db);
-  private QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
-  private QualityGatesWsSupport wsSupport = new QualityGatesWsSupport(db.getDbClient(), userSession, organizationProvider, TestComponentFinder.from(db));
+  private final DbClient dbClient = db.getDbClient();
+  private final QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
+  private final QualityGatesWsSupport wsSupport = new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db));
 
-  private DbSession dbSession = db.getSession();
-  private DestroyAction underTest = new DestroyAction(dbClient, wsSupport, qualityGateFinder);
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final DbSession dbSession = db.getSession();
+  private final DestroyAction underTest = new DestroyAction(dbClient, wsSupport, qualityGateFinder);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void delete_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    db.qualityGates().createDefaultQualityGate(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    db.qualityGates().createDefaultQualityGate();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
-    assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull();
+    assertThat(db.getDbClient().qualityGateDao().selectByUuid(dbSession, qualityGate.getUuid())).isNull();
   }
 
   @Test
   public void delete_quality_gate_if_non_default_when_a_default_exist() {
-    OrganizationDto organization = db.organizations().insert();
-    db.qualityGates().createDefaultQualityGate(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    db.qualityGates().createDefaultQualityGate();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     ws.newRequest()
       .setParam(PARAM_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
-    assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull();
+    assertThat(db.getDbClient().qualityGateDao().selectByUuid(dbSession, qualityGate.getUuid())).isNull();
   }
 
   @Test
   public void delete_quality_gate_and_any_association_to_any_project() {
-    OrganizationDto organization = db.organizations().insert();
-    db.qualityGates().createDefaultQualityGate(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto prj1 = db.components().insertPublicProjectDto(organization);
-    ProjectDto prj2 = db.components().insertPublicProjectDto(organization);
+    db.qualityGates().createDefaultQualityGate();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto prj1 = db.components().insertPublicProjectDto();
+    ProjectDto prj2 = db.components().insertPublicProjectDto();
     db.qualityGates().associateProjectToQualityGate(prj1, qualityGate);
     db.qualityGates().associateProjectToQualityGate(prj2, qualityGate);
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     ws.newRequest()
       .setParam(PARAM_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
     assertThat(db.getDbClient().projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, prj1.getUuid()))
@@ -127,10 +116,9 @@ public class DestroyActionTest {
 
   @Test
   public void does_not_delete_built_in_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    db.qualityGates().createDefaultQualityGate(organization);
+    db.qualityGates().createDefaultQualityGate();
     QualityGateDto builtInQualityGate = db.qualityGates().insertBuiltInQualityGate();
-    db.getDbClient().qualityGateDao().associate(db.getSession(), Uuids.createFast(), organization, builtInQualityGate);
+    db.getDbClient().qualityGateDao().associate(db.getSession(), Uuids.createFast(), builtInQualityGate);
     db.commit();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
@@ -139,43 +127,23 @@ public class DestroyActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ID, valueOf(builtInQualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    OrganizationDto defaultOrganization = db.getDefaultOrganization();
-    db.qualityGates().createDefaultQualityGate(defaultOrganization);
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(defaultOrganization);
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-
-    ws.newRequest()
-      .setParam(PARAM_ID, valueOf(qualityGate.getUuid()))
-      .execute();
-
-    assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndUuid(dbSession, defaultOrganization, qualityGate.getUuid())).isNull();
-  }
-
   @Test
   public void fail_when_missing_id() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(NotFoundException.class);
 
     ws.newRequest()
       .setParam(PARAM_ID, EMPTY)
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_to_delete_default_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto defaultQualityGate = db.qualityGates().createDefaultQualityGate(organization);
+    QualityGateDto defaultQualityGate = db.qualityGates().createDefaultQualityGate();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(IllegalArgumentException.class);
@@ -183,35 +151,30 @@ public class DestroyActionTest {
 
     ws.newRequest()
       .setParam(PARAM_ID, valueOf(defaultQualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_on_unknown_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(NotFoundException.class);
 
     ws.newRequest()
       .setParam(PARAM_ID, "123")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_not_quality_gates_administer() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().createDefaultQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().createDefaultQualityGate();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_PROFILES);
 
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
       .setParam(PARAM_ID, qualityGate.getUuid())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
@@ -226,8 +189,7 @@ public class DestroyActionTest {
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
         tuple("id", false),
-        tuple("name", false),
-        tuple("organization", false));
+        tuple("name", false));
   }
 
 }
index 406dcf9f899e351b3447560bf4ac2d082ed0f904..cececb4d030b7f118d358cee8d88398ce9c57a5f 100644 (file)
@@ -28,14 +28,11 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -55,11 +52,10 @@ public class GetByProjectActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbClient dbClient = db.getDbClient();
+  private final DbClient dbClient = db.getDbClient();
 
-  private WsActionTester ws = new WsActionTester(
-    new GetByProjectAction(userSession, dbClient, TestComponentFinder.from(db), new QualityGateFinder(dbClient),
-      new QualityGatesWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db), TestComponentFinder.from(db))));
+  private final WsActionTester ws = new WsActionTester(
+    new GetByProjectAction(userSession, dbClient, TestComponentFinder.from(db), new QualityGateFinder(dbClient)));
 
   @Test
   public void definition() {
@@ -71,21 +67,18 @@ public class GetByProjectActionTest {
     assertThat(action.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
-        tuple("project", true),
-        tuple("organization", false));
+        tuple("project", true));
   }
 
   @Test
   public void json_example() {
-    OrganizationDto organization = db.organizations().insert();
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("My team QG"));
+    ProjectDto project = db.components().insertPrivateProjectDto();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
     db.qualityGates().associateProjectToQualityGate(project, qualityGate);
     logInAsProjectUser(project);
 
     String result = ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute()
       .getInput();
 
@@ -96,15 +89,13 @@ public class GetByProjectActionTest {
 
   @Test
   public void default_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
-    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, dbQualityGate);
+    ProjectDto project = db.components().insertPrivateProjectDto();
+    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(dbQualityGate);
     logInAsProjectUser(project);
 
     GetByProjectResponse result = ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(GetByProjectResponse.class);
 
     Qualitygates.QualityGate qualityGate = result.getQualityGate();
@@ -115,17 +106,15 @@ public class GetByProjectActionTest {
 
   @Test
   public void project_quality_gate_over_default() {
-    OrganizationDto organization = db.organizations().insert();
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
-    QGateWithOrgDto defaultDbQualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, defaultDbQualityGate);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    ProjectDto project = db.components().insertPrivateProjectDto();
+    QualityGateDto defaultDbQualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(defaultDbQualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     db.qualityGates().associateProjectToQualityGate(project, qualityGate);
     logInAsProjectUser(project);
 
     GetByProjectResponse result = ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(GetByProjectResponse.class);
 
     Qualitygates.QualityGate reloaded = result.getQualityGate();
@@ -135,16 +124,14 @@ public class GetByProjectActionTest {
 
   @Test
   public void get_by_project_key() {
-    OrganizationDto organization = db.organizations().insert();
-    ProjectDto project = db.components().insertPrivateProjectDto(organization);
+    ProjectDto project = db.components().insertPrivateProjectDto();
 
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization(), qg -> qg.setName("My team QG"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
     db.qualityGates().associateProjectToQualityGate(project, qualityGate);
     logInAsProjectUser(project);
 
     GetByProjectResponse result = ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(GetByProjectResponse.class);
 
     assertThat(result.getQualityGate().getName()).isEqualTo(qualityGate.getName());
@@ -152,15 +139,13 @@ public class GetByProjectActionTest {
 
   @Test
   public void get_with_project_admin_permission() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    ComponentDto project = db.components().insertPrivateProject();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     GetByProjectResponse result = ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(GetByProjectResponse.class);
 
     assertThat(result.getQualityGate().getName()).isEqualTo(qualityGate.getName());
@@ -168,26 +153,9 @@ public class GetByProjectActionTest {
 
   @Test
   public void get_with_project_user_permission() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
-    userSession.logIn().addProjectPermission(UserRole.USER, project);
-
-    GetByProjectResponse result = ws.newRequest()
-      .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
-      .executeProtobuf(GetByProjectResponse.class);
-
-    assertThat(result.getQualityGate().getName()).isEqualTo(qualityGate.getName());
-  }
-
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    OrganizationDto organization = db.getDefaultOrganization();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    ComponentDto project = db.components().insertPrivateProject();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
     userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     GetByProjectResponse result = ws.newRequest()
@@ -199,48 +167,38 @@ public class GetByProjectActionTest {
 
   @Test
   public void fail_when_insufficient_permission() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    db.qualityGates().setDefaultQualityGate(db.getDefaultOrganization(), dbQualityGate);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(dbQualityGate);
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_project_does_not_exist() {
-    OrganizationDto organization = db.organizations().insert();
-
     expectedException.expect(NotFoundException.class);
 
     ws.newRequest()
       .setParam("project", "Unknown")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_missing_project_parameter() {
-    OrganizationDto organization = db.organizations().insert();
-
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'project' parameter is missing");
 
-    ws.newRequest()
-      .setParam("organization", organization.getKey())
-      .execute();
+    ws.newRequest().execute();
   }
 
   @Test
   public void fail_when_using_branch_db_key() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPublicProject(organization);
+    ComponentDto project = db.components().insertPublicProject();
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
 
@@ -249,7 +207,6 @@ public class GetByProjectActionTest {
 
     ws.newRequest()
       .setParam("project", branch.getDbKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
index c8e43a55fb6eff30f58818d7083acfb8250755d7..59bf3ce65a2fa09b94de03421f82efa4f3746435 100644 (file)
@@ -25,13 +25,8 @@ import org.junit.rules.ExpectedException;
 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.db.user.UserDto;
 import org.sonar.server.component.TestComponentFinder;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -39,7 +34,6 @@ import org.sonarqube.ws.Qualitygates.ListWsResponse.QualityGate;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.AssertionsForClassTypes.tuple;
-import static org.sonar.db.organization.OrganizationDto.Subscription.PAID;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonar.test.JsonAssert.assertJson;
@@ -54,22 +48,19 @@ public class ListActionTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private DbClient dbClient = db.getDbClient();
-  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-  private QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
+  private final DbClient dbClient = db.getDbClient();
+  private final QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
 
-  private WsActionTester ws = new WsActionTester(new ListAction(db.getDbClient(),
-    new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider, TestComponentFinder.from(db)), qualityGateFinder));
+  private final WsActionTester ws = new WsActionTester(new ListAction(db.getDbClient(),
+    new QualityGatesWsSupport(dbClient, userSession, TestComponentFinder.from(db)), qualityGateFinder));
 
   @Test
   public void list_quality_gates() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization);
-    QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, defaultQualityGate);
+    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate();
+    QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(defaultQualityGate);
 
     ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ListWsResponse.class);
 
     assertThat(response.getQualitygatesList())
@@ -79,31 +70,13 @@ public class ListActionTest {
         tuple(otherQualityGate.getUuid(), otherQualityGate.getName(), false));
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    db.qualityGates().setDefaultQualityGate(db.getDefaultOrganization(), qualityGate);
-
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-    db.qualityGates().setDefaultQualityGate(otherOrganization, otherQualityGate);
-
-    ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
-
-    assertThat(response.getQualitygatesList())
-      .extracting(QualityGate::getId)
-      .containsExactly(qualityGate.getUuid());
-  }
-
   @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));
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate1);
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setBuiltIn(true));
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setBuiltIn(false));
+    db.qualityGates().setDefaultQualityGate(qualityGate1);
 
     ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ListWsResponse.class);
 
     assertThat(response.getQualitygatesList())
@@ -115,12 +88,10 @@ public class ListActionTest {
 
   @Test
   public void test_deprecated_default_field() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, defaultQualityGate);
+    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(defaultQualityGate);
 
     ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ListWsResponse.class);
 
     assertThat(response.getDefault()).isEqualTo(defaultQualityGate.getUuid());
@@ -128,29 +99,24 @@ public class ListActionTest {
 
   @Test
   public void no_default_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(IllegalStateException.class);
 
     ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ListWsResponse.class);
 
   }
 
   @Test
   public void actions_with_quality_gate_administer_permission() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    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(organization, defaultQualityGate);
+    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));
+    db.qualityGates().setDefaultQualityGate(defaultQualityGate);
 
-    ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
-      .executeProtobuf(ListWsResponse.class);
+    ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
 
     assertThat(response.getActions())
       .extracting(ListWsResponse.RootActions::getCreate)
@@ -167,15 +133,12 @@ public class ListActionTest {
 
   @Test
   public void actions_without_quality_gate_administer_permission() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_PROFILES);
-    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(organization, defaultQualityGate);
+    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));
+    db.qualityGates().setDefaultQualityGate(defaultQualityGate);
 
-    ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
-      .executeProtobuf(ListWsResponse.class);
+    ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
 
     assertThat(response.getActions())
       .extracting(ListWsResponse.RootActions::getCreate)
@@ -189,34 +152,14 @@ public class ListActionTest {
         tuple(otherQualityGate.getName(), false, false, false, false, false, false));
   }
 
-  @Test
-  public void list_quality_gates_on_paid_organization() {
-    OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(PAID));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
-    UserDto user = db.users().insertUser();
-
-    ListWsResponse response = ws.newRequest()
-      .setParam("organization", organization.getKey())
-      .executeProtobuf(ListWsResponse.class);
-
-    assertThat(response.getQualitygatesList())
-      .extracting(QualityGate::getName)
-      .containsExactlyInAnyOrder(qualityGate.getName());
-  }
-
   @Test
   public void json_example() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("admin").addPermission(ADMINISTER_QUALITY_GATES);
-    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(organization, defaultQualityGate);
+    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setName("Sonar way").setBuiltIn(true));
+    db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setName("Sonar way - Without Coverage").setBuiltIn(false));
+    db.qualityGates().setDefaultQualityGate(defaultQualityGate);
 
-    String response = ws.newRequest()
-      .setParam("organization", organization.getKey())
-      .execute()
-      .getInput();
+    String response = ws.newRequest().execute().getInput();
 
     assertJson(response).ignoreFields("id", "default")
       .isSimilarTo(getClass().getResource("list-example.json"));
@@ -230,8 +173,7 @@ public class ListActionTest {
     assertThat(action.isPost()).isFalse();
     assertThat(action.isInternal()).isFalse();
     assertThat(action.changelog()).isNotEmpty();
-    assertThat(action.params()).extracting(WebService.Param::key, WebService.Param::isRequired)
-      .containsExactlyInAnyOrder(tuple("organization", false));
+    assertThat(action.params()).extracting(WebService.Param::key, WebService.Param::isRequired).isEmpty();
   }
 
 }
index 8d909e4910e44277a1909867542c62dc075256da..fd3071091d33ef03bd6fb46f9055a5b7bd753932 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -55,7 +54,6 @@ import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
 import static org.sonar.db.metric.MetricTesting.newMetricDto;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ANALYSIS_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_BRANCH;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PULL_REQUEST;
@@ -71,10 +69,10 @@ public class ProjectStatusActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
 
-  private WsActionTester ws = new WsActionTester(new ProjectStatusAction(dbClient, TestComponentFinder.from(db), userSession));
+  private final WsActionTester ws = new WsActionTester(new ProjectStatusAction(dbClient, TestComponentFinder.from(db), userSession));
 
   @Test
   public void test_definition() {
@@ -91,8 +89,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void test_json_example() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.USER, project);
     MetricDto gateDetailsMetric = insertGateDetailMetric();
 
@@ -114,8 +111,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_past_status_when_project_is_referenced_by_past_analysis_id() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     SnapshotDto pastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
       .setLast(false)
       .setPeriodMode("last_version")
@@ -145,8 +141,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_live_status_when_project_is_referenced_by_its_id() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
       .setPeriodMode("last_version")
       .setPeriodParam("2015-12-07")
@@ -167,8 +162,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_past_status_when_branch_is_referenced_by_past_analysis_id() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project);
     SnapshotDto pastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(branch)
       .setLast(false)
@@ -199,8 +193,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_live_status_when_project_is_referenced_by_its_key() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
       .setPeriodMode("last_version")
       .setPeriodParam("2015-12-07")
@@ -221,8 +214,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_live_status_when_branch_is_referenced_by_its_key() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project);
 
     dbClient.snapshotDao().insert(dbSession, newAnalysis(branch)
@@ -246,8 +238,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_live_status_when_pull_request_is_referenced_by_its_key() throws IOException {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     ComponentDto pr = db.components().insertProjectBranch(project, branch -> branch.setBranchType(BranchType.PULL_REQUEST));
 
     dbClient.snapshotDao().insert(dbSession, newAnalysis(pr)
@@ -271,8 +262,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_undefined_status_if_specified_analysis_is_not_found() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
     userSession.addProjectPermission(UserRole.USER, project);
@@ -287,8 +277,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void return_undefined_status_if_project_is_not_analyzed() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.USER, project);
 
     ProjectStatusResponse result = ws.newRequest()
@@ -301,8 +290,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void project_administrator_is_allowed_to_get_project_status() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
     userSession.addProjectPermission(UserRole.ADMIN, project);
@@ -314,8 +302,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void project_user_is_allowed_to_get_project_status() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
     userSession.addProjectPermission(UserRole.USER, project);
@@ -325,22 +312,8 @@ public class ProjectStatusActionTest {
       .executeProtobuf(ProjectStatusResponse.class);
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    OrganizationDto organization = db.getDefaultOrganization();
-    ComponentDto project = db.components().insertPrivateProject(organization);
-    userSession.logIn().addProjectPermission(UserRole.USER, project);
-
-    ProjectStatusResponse result = ws.newRequest()
-      .setParam(PARAM_PROJECT_ID, project.uuid())
-      .executeProtobuf(ProjectStatusResponse.class);
-
-    assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE);
-  }
-
   @Test
   public void fail_if_no_snapshot_id_found() {
-    OrganizationDto organization = db.organizations().insert();
     logInAsSystemAdministrator();
 
     expectedException.expect(NotFoundException.class);
@@ -353,8 +326,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void fail_if_insufficient_privileges() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
     userSession.logIn();
@@ -368,8 +340,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void fail_if_project_id_and_ce_task_id_provided() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     logInAsSystemAdministrator();
 
     expectedException.expect(BadRequestException.class);
@@ -378,14 +349,12 @@ public class ProjectStatusActionTest {
     ws.newRequest()
       .setParam(PARAM_ANALYSIS_ID, "analysis-id")
       .setParam(PARAM_PROJECT_ID, "project-uuid")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute().getInput();
   }
 
   @Test
   public void fail_if_branch_key_and_pull_request_id_provided() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     logInAsSystemAdministrator();
 
     expectedException.expect(BadRequestException.class);
@@ -395,7 +364,6 @@ public class ProjectStatusActionTest {
       .setParam(PARAM_PROJECT_KEY, "key")
       .setParam(PARAM_BRANCH, "branch")
       .setParam(PARAM_PULL_REQUEST, "pr")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute().getInput();
   }
 
@@ -413,8 +381,7 @@ public class ProjectStatusActionTest {
 
   @Test
   public void fail_when_using_branch_db_key() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPublicProject(organization);
+    ComponentDto project = db.components().insertPublicProject();
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
     SnapshotDto snapshot = db.components().insertSnapshot(branch);
@@ -424,14 +391,12 @@ public class ProjectStatusActionTest {
 
     ws.newRequest()
       .setParam(PARAM_PROJECT_KEY, branch.getDbKey())
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_using_branch_uuid() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPublicProject(organization);
+    ComponentDto project = db.components().insertPublicProject();
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
     SnapshotDto snapshot = db.components().insertSnapshot(branch);
index 64a115c90b78d8df8d271273ddc8d75b4318a5cb..694ac8fa98c5fcece223c57f7c56f529d4ce5256 100644 (file)
@@ -25,13 +25,10 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 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.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.Qualitygates.QualityGate;
@@ -51,10 +48,8 @@ public class RenameActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-
-  private WsActionTester ws = new WsActionTester(
-    new RenameAction(db.getDbClient(), new QualityGatesWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider, TestComponentFinder.from(db))));
+  private final WsActionTester ws = new WsActionTester(
+    new RenameAction(db.getDbClient(), new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db))));
 
   @Test
   public void verify_definition() {
@@ -67,20 +62,17 @@ public class RenameActionTest {
       .containsExactlyInAnyOrder(
         tuple("id", false),
         tuple("currentName", false),
-        tuple("name", true),
-        tuple("organization", false));
+        tuple("name", true));
   }
 
   @Test
   public void rename() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("old name"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("old name"));
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
 
     ws.newRequest()
       .setParam("id", qualityGate.getUuid())
       .setParam("name", "new name")
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertThat(db.getDbClient().qualityGateDao().selectByUuid(db.getSession(), qualityGate.getUuid()).getName()).isEqualTo("new name");
@@ -88,14 +80,12 @@ public class RenameActionTest {
 
   @Test
   public void response_contains_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("old name"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("old name"));
 
     QualityGate result = ws.newRequest()
       .setParam("id", qualityGate.getUuid())
       .setParam("name", "new name")
-      .setParam("organization", organization.getKey())
       .executeProtobuf(QualityGate.class);
 
     assertThat(result.getId()).isEqualTo(qualityGate.getUuid());
@@ -104,40 +94,21 @@ public class RenameActionTest {
 
   @Test
   public void rename_with_same_name() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("name"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("name"));
 
     ws.newRequest()
       .setParam("id", qualityGate.getUuid())
       .setParam("name", "name")
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertThat(db.getDbClient().qualityGateDao().selectByUuid(db.getSession(), qualityGate.getUuid()).getName()).isEqualTo("name");
   }
 
-  @Test
-  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);
-    userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-
-    QualityGate result = ws.newRequest()
-      .setParam("id", qualityGate.getUuid())
-      .setParam("name", "new name")
-      .executeProtobuf(QualityGate.class);
-
-    assertThat(result.getId()).isEqualTo(qualityGate.getUuid());
-    assertThat(result.getName()).isEqualTo("new name");
-  }
-
   @Test
   public void fail_on_built_in_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName()));
@@ -145,15 +116,13 @@ public class RenameActionTest {
     ws.newRequest()
       .setParam("id", qualityGate.getUuid())
       .setParam("name", "name")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_on_empty_name() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'name' parameter is missing");
@@ -161,16 +130,14 @@ public class RenameActionTest {
     ws.newRequest()
       .setParam("id", qualityGate.getUuid())
       .setParam("name", "")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_using_existing_name() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage(format("Name '%s' has already been taken", qualityGate2.getName()));
@@ -178,13 +145,11 @@ public class RenameActionTest {
     ws.newRequest()
       .setParam("id", qualityGate1.getUuid())
       .setParam("name", qualityGate2.getName())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_on_unknown_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
 
     expectedException.expect(NotFoundException.class);
@@ -192,22 +157,19 @@ public class RenameActionTest {
     ws.newRequest()
       .setParam("id", "123")
       .setParam("name", "new name")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_not_quality_gates_administer() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_PROFILES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("old name"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("old name"));
 
     expectedException.expect(ForbiddenException.class);
 
     ws.newRequest()
       .setParam("id", qualityGate.getUuid())
       .setParam("name", "new name")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
index 51a450dbd4d34087f04aae236b871c87a70549ef..182b20a101862d9b7190c6cccfa8edb60353e234 100644 (file)
@@ -26,19 +26,16 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.Qualitygates.SearchResponse;
 import org.sonarqube.ws.Qualitygates.SearchResponse.Result;
 
-import static java.lang.String.format;
 import static java.lang.String.valueOf;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.AssertionsForClassTypes.tuple;
@@ -48,7 +45,6 @@ import static org.sonar.api.server.ws.WebService.SelectionMode.SELECTED;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_ID;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PAGE;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PAGE_SIZE;
 import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SELECTED;
@@ -64,35 +60,15 @@ public class SearchActionTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private DbClient dbClient = db.getDbClient();
-  private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-
-  private SearchAction underTest = new SearchAction(dbClient, userSession,
-    new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider, TestComponentFinder.from(db)));
-  private WsActionTester ws = new WsActionTester(underTest);
-
-  @Test
-  public void search_projects_of_a_quality_gate_from_an_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPublicProject(organization);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate);
-
-    SearchResponse response = ws.newRequest()
-      .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .executeProtobuf(SearchResponse.class);
-
-    assertThat(response.getResultsList())
-      .extracting(Result::getKey, Result::getName)
-      .containsExactlyInAnyOrder(tuple(project.getKey(), project.name()));
-  }
+  private final DbClient dbClient = db.getDbClient();
+  private final SearchAction underTest = new SearchAction(dbClient, userSession,
+    new QualityGatesWsSupport(dbClient, userSession, TestComponentFinder.from(db)));
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
-  public void search_on_default_organization_when_none_is_provided() {
-    OrganizationDto defaultOrganization = db.getDefaultOrganization();
-    ComponentDto project = db.components().insertPublicProject(defaultOrganization);
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(defaultOrganization);
+  public void search_projects_of_a_quality_gate() {
+    ComponentDto project = db.components().insertPublicProject();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate);
 
     SearchResponse response = ws.newRequest()
@@ -106,12 +82,10 @@ public class SearchActionTest {
 
   @Test
   public void return_empty_association() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .executeProtobuf(SearchResponse.class);
 
     assertThat(response.getResultsList()).isEmpty();
@@ -119,15 +93,13 @@ public class SearchActionTest {
 
   @Test
   public void return_all_projects() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto unassociatedProject = db.components().insertPublicProjectDto(organization);
-    ProjectDto associatedProject = db.components().insertPublicProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto unassociatedProject = db.components().insertPublicProjectDto();
+    ProjectDto associatedProject = db.components().insertPublicProjectDto();
     db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate);
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .executeProtobuf(SearchResponse.class);
 
@@ -140,15 +112,13 @@ public class SearchActionTest {
 
   @Test
   public void return_only_associated_project() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto associatedProject = db.components().insertPublicProjectDto(organization);
-    ProjectDto unassociatedProject = db.components().insertPublicProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto associatedProject = db.components().insertPublicProjectDto();
+    ProjectDto unassociatedProject = db.components().insertPublicProjectDto();
     db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate);
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, SELECTED.value())
       .executeProtobuf(SearchResponse.class);
 
@@ -160,15 +130,13 @@ public class SearchActionTest {
 
   @Test
   public void return_only_unassociated_project() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto associatedProject = db.components().insertPublicProjectDto(organization);
-    ProjectDto unassociatedProject = db.components().insertPublicProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto associatedProject = db.components().insertPublicProjectDto();
+    ProjectDto unassociatedProject = db.components().insertPublicProjectDto();
     db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate);
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, DESELECTED.value())
       .executeProtobuf(SearchResponse.class);
 
@@ -180,10 +148,9 @@ public class SearchActionTest {
 
   @Test
   public void return_only_authorized_projects() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project1 = db.components().insertPrivateProject(organization);
-    ComponentDto project2 = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project1 = db.components().insertPrivateProject();
+    ComponentDto project2 = db.components().insertPrivateProject();
     UserDto user = db.users().insertUser();
     // User can only see project1 1
     db.users().insertProjectPermissionOnUser(user, USER, project1);
@@ -191,7 +158,6 @@ public class SearchActionTest {
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .executeProtobuf(SearchResponse.class);
 
@@ -203,14 +169,12 @@ public class SearchActionTest {
 
   @Test
   public void root_user() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn().setRoot();
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .executeProtobuf(SearchResponse.class);
 
@@ -221,87 +185,79 @@ public class SearchActionTest {
 
   @Test
   public void test_paging() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ProjectDto project1 = db.components().insertPublicProjectDto(organization);
-    ProjectDto project2 = db.components().insertPublicProjectDto(organization);
-    ProjectDto project3 = db.components().insertPublicProjectDto(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ProjectDto project1 = db.components().insertPublicProjectDto();
+    ProjectDto project2 = db.components().insertPublicProjectDto();
+    ProjectDto project3 = db.components().insertPublicProjectDto();
     db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
 
     // Return partial result on first page
     assertThat(ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .setParam(PARAM_PAGE, "1")
       .setParam(PARAM_PAGE_SIZE, "1")
       .executeProtobuf(SearchResponse.class)
       .getResultsList())
-      .extracting(Result::getName)
-      .containsExactlyInAnyOrder(project1.getName());
+        .extracting(Result::getName)
+        .containsExactlyInAnyOrder(project1.getName());
 
     // Return partial result on second page
     assertThat(ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .setParam(PARAM_PAGE, "2")
       .setParam(PARAM_PAGE_SIZE, "1")
       .executeProtobuf(SearchResponse.class)
       .getResultsList())
-      .extracting(Result::getName)
-      .containsExactlyInAnyOrder(project2.getName());
+        .extracting(Result::getName)
+        .containsExactlyInAnyOrder(project2.getName());
 
     // Return partial result on first page
     assertThat(ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .setParam(PARAM_PAGE, "1")
       .setParam(PARAM_PAGE_SIZE, "2")
       .executeProtobuf(SearchResponse.class)
       .getResultsList())
-      .extracting(Result::getName)
-      .containsExactlyInAnyOrder(project1.getName(), project2.getName());
+        .extracting(Result::getName)
+        .containsExactlyInAnyOrder(project1.getName(), project2.getName());
 
     // Return all result on first page
     assertThat(ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .setParam(PARAM_PAGE, "1")
       .setParam(PARAM_PAGE_SIZE, "3")
       .executeProtobuf(SearchResponse.class)
       .getResultsList())
-      .extracting(Result::getName)
-      .containsExactlyInAnyOrder(project1.getName(), project2.getName(), project3.getName());
+        .extracting(Result::getName)
+        .containsExactlyInAnyOrder(project1.getName(), project2.getName(), project3.getName());
 
     // Return no result as page index is off limit
     assertThat(ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_SELECTED, ALL.value())
       .setParam(PARAM_PAGE, "3")
       .setParam(PARAM_PAGE_SIZE, "3")
       .executeProtobuf(SearchResponse.class)
       .getResultsList())
-      .extracting(Result::getName)
-      .isEmpty();
+        .extracting(Result::getName)
+        .isEmpty();
   }
 
   @Test
   public void test_pagination_on_many_pages() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     for (int i = 0; i < 20; i++) {
-      ProjectDto project = db.components().insertPublicProjectDto(organization);
+      ProjectDto project = db.components().insertPublicProjectDto();
       db.qualityGates().associateProjectToQualityGate(project, qualityGate);
     }
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_PAGE_SIZE, valueOf(5))
       .setParam(PARAM_PAGE, valueOf(2))
       .executeProtobuf(SearchResponse.class);
@@ -316,17 +272,15 @@ public class SearchActionTest {
 
   @Test
   public void test_pagination_on_one_page() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     for (int i = 0; i < 20; i++) {
-      ProjectDto project = db.components().insertPublicProjectDto(organization);
+      ProjectDto project = db.components().insertPublicProjectDto();
       db.qualityGates().associateProjectToQualityGate(project, qualityGate);
     }
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
 
     SearchResponse response = ws.newRequest()
       .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_PAGE_SIZE, valueOf(100))
       .setParam(PARAM_PAGE, valueOf(1))
       .executeProtobuf(SearchResponse.class);
@@ -339,53 +293,13 @@ public class SearchActionTest {
       .contains(false, 1, 100, 20);
   }
 
-  @Test
-  public void return_only_projects_from_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-    ProjectDto project = db.components().insertPublicProjectDto(organization);
-    ProjectDto otherProject = db.components().insertPublicProjectDto(otherOrganization);
-    db.qualityGates().associateProjectToQualityGate(project, qualityGate);
-    db.qualityGates().associateProjectToQualityGate(otherProject, otherQualityGate);
-
-    SearchResponse response = ws.newRequest()
-      .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_SELECTED, ALL.value())
-      .executeProtobuf(SearchResponse.class);
-
-    assertThat(response.getResultsList())
-      .extracting(Result::getName)
-      .containsExactlyInAnyOrder(project.getName());
-  }
-
   @Test
   public void fail_on_unknown_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
-
     expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("No quality gate has been found for id 42 in organization %s", organization.getName()));
+    expectedException.expectMessage("No quality gate has been found for id 42");
 
     ws.newRequest()
       .setParam(PARAM_GATE_ID, "42")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .executeProtobuf(SearchResponse.class);
-  }
-
-  @Test
-  public void fail_when_quality_gates_does_not_belong_to_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getUuid(), organization.getName()));
-
-    ws.newRequest()
-      .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid()))
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .executeProtobuf(SearchResponse.class);
   }
 
@@ -403,7 +317,6 @@ public class SearchActionTest {
         tuple("gateId", false),
         tuple("gateName", false),
         tuple("query", false),
-        tuple("organization", false),
         tuple("selected", false),
         tuple("page", false),
         tuple("pageSize", false));
index 2a733e6e172fa5f7076641787d56d1440f932614..7df012695f27b589a9e01bdbd56f005f3a2a4dbb 100644 (file)
@@ -27,14 +27,11 @@ import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 
@@ -53,22 +50,21 @@ public class SelectActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbClient dbClient = db.getDbClient();
-  private ComponentFinder componentFinder = TestComponentFinder.from(db);
-  private SelectAction underTest = new SelectAction(dbClient, new QualityGatesWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db), componentFinder));
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final DbClient dbClient = db.getDbClient();
+  private final ComponentFinder componentFinder = TestComponentFinder.from(db);
+  private final SelectAction underTest = new SelectAction(dbClient,
+    new QualityGatesWsSupport(db.getDbClient(), userSession, componentFinder));
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void select_by_key() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
 
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertSelected(qualityGate, project);
@@ -76,22 +72,19 @@ public class SelectActionTest {
 
   @Test
   public void change_quality_gate_for_project() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto initialQualityGate = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto secondQualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto initialQualityGate = db.qualityGates().insertQualityGate();
+    QualityGateDto secondQualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
 
     ws.newRequest()
       .setParam("gateId", initialQualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     ws.newRequest()
       .setParam("gateId", secondQualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertSelected(secondQualityGate, project);
@@ -99,21 +92,18 @@ public class SelectActionTest {
 
   @Test
   public void select_same_quality_gate_for_project_twice() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto initialQualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto initialQualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
 
     ws.newRequest()
       .setParam("gateId", initialQualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     ws.newRequest()
       .setParam("gateId", initialQualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertSelected(initialQualityGate, project);
@@ -121,15 +111,13 @@ public class SelectActionTest {
 
   @Test
   public void project_admin() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn().addProjectPermission(ADMIN, project);
 
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertSelected(qualityGate, project);
@@ -137,132 +125,86 @@ public class SelectActionTest {
 
   @Test
   public void gate_administrator_can_associate_a_gate_to_a_project() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
 
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
 
     assertSelected(qualityGate, project);
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    OrganizationDto organization = db.getDefaultOrganization();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
-
-    ws.newRequest()
-      .setParam("gateId", qualityGate.getUuid())
-      .setParam("projectKey", project.getKey())
-      .execute();
-
-    assertSelected(qualityGate, project);
-  }
-
-  @Test
-  public void fail_when_project_belongs_to_another_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    OrganizationDto anotherOrganization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(anotherOrganization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("Project '%s' doesn't exist in organization '%s'", project.getKey(), organization.getKey()));
-
-    ws.newRequest()
-      .setParam("gateId", qualityGate.getUuid())
-      .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
-      .execute();
-  }
-
   @Test
   public void fail_when_no_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
 
     expectedException.expect(NotFoundException.class);
 
     ws.newRequest()
       .setParam("gateId", "1")
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_no_project_key() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(NotFoundException.class);
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", "unknown")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_anonymous() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.anonymous();
 
     expectedException.expect(ForbiddenException.class);
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", project.getKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_not_project_admin() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn().addProjectPermission(ISSUE_ADMIN, project);
 
     expectedException.expect(ForbiddenException.class);
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", project.getDbKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_not_quality_gates_admin() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn();
 
     expectedException.expect(ForbiddenException.class);
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", project.getDbKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_using_branch_db_key() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    ComponentDto project = db.components().insertPublicProject(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    ComponentDto project = db.components().insertPublicProject();
     userSession.logIn().addProjectPermission(ADMIN, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
 
@@ -272,7 +214,6 @@ public class SelectActionTest {
     ws.newRequest()
       .setParam("gateId", qualityGate.getUuid())
       .setParam("projectKey", branch.getDbKey())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
index 009c9df9c38965a8176d3a3baca44ac780282e26..e77505b84c104a110ba9095685f1a2a391492382 100644 (file)
@@ -21,14 +21,11 @@ package org.sonar.server.qualitygate.ws;
 
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
+import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 
@@ -37,17 +34,13 @@ import static org.assertj.core.api.AssertionsForClassTypes.tuple;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 
 public class SetAsDefaultActionTest {
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-
-  private WsActionTester ws = new WsActionTester(
-    new SetAsDefaultAction(db.getDbClient(), userSession, new QualityGatesWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider, TestComponentFinder.from(db))));
+  private final WsActionTester ws = new WsActionTester(
+    new SetAsDefaultAction(db.getDbClient(), userSession, new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db))));
 
   @Test
   public void verify_definition() {
@@ -59,20 +52,19 @@ public class SetAsDefaultActionTest {
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
         tuple("id", false),
-        tuple("organization", false),
         tuple("name", false));
   }
 
   @Test
   public void set_default() {
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization(), qg -> qg.setName("name"));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("name"));
 
     ws.newRequest()
       .setParam("name", "name")
       .execute();
 
-    assertThat(db.getDbClient().organizationDao().selectByKey(db.getSession(), db.getDefaultOrganization().getKey()).get()
-      .getDefaultQualityGateUuid()).isEqualTo(qualityGate.getUuid());
+    assertThat(db.getDbClient().propertiesDao().selectGlobalProperty(db.getSession(), "qualitygate.default").getValue())
+      .isEqualTo(qualityGate.getUuid());
   }
 }
index 8224bfc5547841073b4308da6b006955e28d67ba..f2b541019fb9b59f814227c9030507e06c5ff315 100644 (file)
@@ -27,15 +27,10 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
-import org.sonar.db.user.UserDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -45,7 +40,6 @@ import org.sonarqube.ws.Qualitygates.ShowWsResponse.Condition;
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.AssertionsForClassTypes.tuple;
-import static org.sonar.db.organization.OrganizationDto.Subscription.PAID;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonar.test.JsonAssert.assertJson;
@@ -60,17 +54,14 @@ public class ShowActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-
-  private WsActionTester ws = new WsActionTester(
+  private final WsActionTester ws = new WsActionTester(
     new ShowAction(db.getDbClient(), new QualityGateFinder(db.getDbClient()),
-      new QualityGatesWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider, TestComponentFinder.from(db))));
+      new QualityGatesWsSupport(db.getDbClient(), userSession, TestComponentFinder.from(db))));
 
   @Test
   public void show() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
     MetricDto metric1 = db.measures().insertMetric();
     MetricDto metric2 = db.measures().insertMetric();
     QualityGateConditionDto condition1 = db.qualityGates().addCondition(qualityGate, metric1, c -> c.setOperator("GT"));
@@ -78,7 +69,6 @@ public class ShowActionTest {
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getId()).isEqualTo(qualityGate.getUuid());
@@ -92,29 +82,13 @@ public class ShowActionTest {
         tuple(condition2.getUuid(), metric2.getKey(), "LT", condition2.getErrorThreshold()));
   }
 
-  @Test
-  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);
-    db.qualityGates().setDefaultQualityGate(db.getDefaultOrganization(), qualityGate);
-
-    ShowWsResponse response = ws.newRequest()
-      .setParam("name", qualityGate.getName())
-      .executeProtobuf(ShowWsResponse.class);
-
-    assertThat(response.getId()).isEqualTo(qualityGate.getUuid());
-  }
-
   @Test
   public void show_built_in() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
+    db.qualityGates().setDefaultQualityGate(qualityGate);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getIsBuiltIn()).isTrue();
@@ -122,13 +96,11 @@ public class ShowActionTest {
 
   @Test
   public void show_by_id() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("id", qualityGate.getUuid())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getId()).isEqualTo(qualityGate.getUuid());
@@ -137,13 +109,11 @@ public class ShowActionTest {
 
   @Test
   public void no_condition() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getId()).isEqualTo(qualityGate.getUuid());
@@ -153,15 +123,13 @@ public class ShowActionTest {
 
   @Test
   public void actions() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate2);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate2);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
@@ -175,14 +143,12 @@ public class ShowActionTest {
 
   @Test
   public void actions_on_default() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
@@ -196,15 +162,13 @@ public class ShowActionTest {
 
   @Test
   public void actions_on_built_in() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(false));
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate2);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(false));
+    db.qualityGates().setDefaultQualityGate(qualityGate2);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
@@ -218,14 +182,12 @@ public class ShowActionTest {
 
   @Test
   public void actions_when_not_quality_gate_administer() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_PROFILES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
+    db.qualityGates().setDefaultQualityGate(qualityGate);
 
     ShowWsResponse response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
@@ -237,40 +199,19 @@ public class ShowActionTest {
     assertThat(actions.getAssociateProjects()).isFalse();
   }
 
-  @Test
-  public void show_on_paid_organization() {
-    OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(PAID));
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
-    MetricDto metric = db.measures().insertMetric();
-    db.qualityGates().addCondition(qualityGate, metric);
-    UserDto user = db.users().insertUser();
-
-    ShowWsResponse response = ws.newRequest()
-      .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
-      .executeProtobuf(ShowWsResponse.class);
-
-    assertThat(response.getConditionsList()).hasSize(1);
-  }
-
   @Test
   public void fail_when_no_name_or_id() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Either 'id' or 'name' must be provided");
 
-    ws.newRequest()
-      .setParam("organization", organization.getKey())
-      .execute();
+    ws.newRequest().execute();
   }
 
   @Test
   public void fail_when_both_name_or_id() {
-    OrganizationDto organization = db.organizations().insert();
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Either 'id' or 'name' must be provided");
@@ -278,15 +219,13 @@ public class ShowActionTest {
     ws.newRequest()
       .setParam("name", qualityGate.getName())
       .setParam("id", qualityGate.getUuid())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_condition_is_on_disabled_metric() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().setDefaultQualityGate(qualityGate);
     MetricDto metric = db.measures().insertMetric();
     db.qualityGates().addCondition(qualityGate, metric);
     db.getDbClient().metricDao().disableCustomByKey(db.getSession(), metric.getKey());
@@ -297,89 +236,39 @@ public class ShowActionTest {
 
     ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_quality_name_does_not_exist() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("No quality gate has been found for name UNKNOWN");
 
     ws.newRequest()
       .setParam("name", "UNKNOWN")
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void fail_when_quality_id_does_not_exist() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("No quality gate has been found for id 123");
 
     ws.newRequest()
       .setParam("id", "123")
-      .setParam("organization", organization.getKey())
-      .execute();
-  }
-
-  @Test
-  public void fail_when_organization_does_not_exist() {
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("No organization with key 'Unknown'");
-
-    ws.newRequest()
-      .setParam("name", qualityGate.getName())
-      .setParam("organization", "Unknown")
-      .execute();
-  }
-
-  @Test
-  public void fail_when_quality_gate_belongs_to_another_organization() {
-    OrganizationDto organization = db.organizations().insert();
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("No quality gate has been found for name %s", qualityGate.getName()));
-
-    ws.newRequest()
-      .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
-      .execute();
-  }
-
-  @Test
-  public void fail_when_quality_gate_belongs_to_another_organization_using_id_parameter() {
-    OrganizationDto organization = db.organizations().insert();
-    OrganizationDto otherOrganization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getUuid(), organization.getName()));
-
-    ws.newRequest()
-      .setParam("id", qualityGate.getUuid())
-      .setParam("organization", organization.getKey())
       .execute();
   }
 
   @Test
   public void json_example() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.logIn("admin").addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("My Quality Gate"));
-    QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("My Quality Gate 2"));
-    db.qualityGates().setDefaultQualityGate(organization, qualityGate2);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My Quality Gate"));
+    QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(qg -> qg.setName("My Quality Gate 2"));
+    db.qualityGates().setDefaultQualityGate(qualityGate2);
     MetricDto blockerViolationsMetric = db.measures().insertMetric(m -> m.setKey("blocker_violations"));
     MetricDto criticalViolationsMetric = db.measures().insertMetric(m -> m.setKey("tests"));
     db.qualityGates().addCondition(qualityGate, blockerViolationsMetric, c -> c.setOperator("GT").setErrorThreshold("0"));
@@ -387,7 +276,6 @@ public class ShowActionTest {
 
     String response = ws.newRequest()
       .setParam("name", qualityGate.getName())
-      .setParam("organization", organization.getKey())
       .execute()
       .getInput();
 
@@ -403,8 +291,7 @@ public class ShowActionTest {
       .extracting(Param::key, Param::isRequired)
       .containsExactlyInAnyOrder(
         tuple("id", false),
-        tuple("name", false),
-        tuple("organization", false));
+        tuple("name", false));
   }
 
 }
index f64c5dd9f695e80448d774129fd7a7fcdae34488..f31d9f307f462ee83dffcda1c256a0c68b2dd8d5 100644 (file)
@@ -32,15 +32,12 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualitygate.QGateWithOrgDto;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateConditionsUpdater;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
@@ -55,7 +52,6 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ERR
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
 
 @RunWith(DataProviderRunner.class)
 public class UpdateConditionActionTest {
@@ -69,25 +65,22 @@ public class UpdateConditionActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-  private UpdateConditionAction underTest = new UpdateConditionAction(dbClient, new QualityGateConditionsUpdater(dbClient),
-    new QualityGatesWsSupport(dbClient, userSession, defaultOrganizationProvider, TestComponentFinder.from(db)));
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final UpdateConditionAction underTest = new UpdateConditionAction(dbClient, new QualityGateConditionsUpdater(dbClient),
+    new QualityGatesWsSupport(dbClient, userSession, TestComponentFinder.from(db)));
 
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void update_error_condition() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("GT").setErrorThreshold("80"));
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
@@ -97,34 +90,15 @@ public class UpdateConditionActionTest {
     assertCondition(qualityGate, metric, "LT", "90");
   }
 
-  @Test
-  public void default_organization_is_used_when_no_organization_parameter() {
-    userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    MetricDto metric = insertMetric();
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
-
-    ws.newRequest()
-      .setParam(PARAM_ID, condition.getUuid())
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_ERROR, "10")
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "10");
-  }
-
   @Test
   public void test_response() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("GT").setErrorThreshold("80"));
 
     CreateConditionResponse response = ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
@@ -139,9 +113,8 @@ public class UpdateConditionActionTest {
 
   @Test
   public void fail_to_update_built_in_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setBuiltIn(true));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
 
@@ -149,7 +122,6 @@ public class UpdateConditionActionTest {
     expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName()));
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
@@ -159,9 +131,8 @@ public class UpdateConditionActionTest {
 
   @Test
   public void fail_on_unknown_condition() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
     db.qualityGates().addCondition(qualityGate, metric);
 
@@ -169,7 +140,6 @@ public class UpdateConditionActionTest {
     expectedException.expectMessage("No quality gate condition with uuid '123'");
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, "123")
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
@@ -179,7 +149,6 @@ public class UpdateConditionActionTest {
 
   @Test
   public void fail_when_condition_match_unknown_quality_gate() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid")
@@ -192,7 +161,6 @@ public class UpdateConditionActionTest {
     expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), 123L));
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
@@ -202,9 +170,8 @@ public class UpdateConditionActionTest {
 
   @Test
   public void fail_with_unknown_operator() {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(INT.name()).setHidden(false).setDirection(0));
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator("LT").setErrorThreshold("80"));
@@ -213,7 +180,6 @@ public class UpdateConditionActionTest {
     expectedException.expectMessage("Value of parameter 'op' (ABC) must be one of: [LT, GT]");
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "ABC")
@@ -224,9 +190,8 @@ public class UpdateConditionActionTest {
   @Test
   @UseDataProvider("update_invalid_operators_and_direction")
   public void fail_with_invalid_operators_for_direction(String validOperator, String updateOperator, int direction) {
-    OrganizationDto organization = db.organizations().insert();
     userSession.addPermission(ADMINISTER_QUALITY_GATES);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(INT.name()).setHidden(false).setDirection(direction));
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
       c -> c.setOperator(validOperator).setErrorThreshold("80"));
@@ -235,7 +200,6 @@ public class UpdateConditionActionTest {
     expectedException.expectMessage(format("Operator %s is not allowed for this metric.", updateOperator));
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, updateOperator)
@@ -246,8 +210,7 @@ public class UpdateConditionActionTest {
   @Test
   public void throw_ForbiddenException_if_not_gate_administrator() {
     userSession.logIn();
-    OrganizationDto organization = db.organizations().insert();
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
 
@@ -255,7 +218,6 @@ public class UpdateConditionActionTest {
     expectedException.expectMessage("Insufficient privileges");
 
     ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, condition.getUuid())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
@@ -276,8 +238,7 @@ public class UpdateConditionActionTest {
         tuple("id", true),
         tuple("metric", true),
         tuple("error", true),
-        tuple("op", false),
-        tuple("organization", false));
+        tuple("op", false));
   }
 
   @DataProvider