aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanos Gyerik <janos.gyerik@sonarsource.com>2018-01-09 11:21:50 +0100
committerGitHub <noreply@github.com>2018-01-09 11:21:50 +0100
commitadbc65a64befed967f581aaed8f5f6f31b5171db (patch)
tree99195bf4b25d9e6383927939eb3a7cc3c60181af
parentdc3d831194f360a17b235958b0a38c09b24b3072 (diff)
downloadsonarqube-adbc65a64befed967f581aaed8f5f6f31b5171db.tar.gz
sonarqube-adbc65a64befed967f581aaed8f5f6f31b5171db.zip
Relocate organizations enabled flag (#2945)
* Revert "SONAR-10223 add organizationsEnabled flag to Organization" * Add AnalysisMetadataHolder.isOrganizationsEnabled
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Organization.java18
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java24
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java11
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/OrganizationTest.java49
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/VerifyBillingStepTest.java3
14 files changed, 111 insertions, 97 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
index f5e69963a3b..97159e9875d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
@@ -26,6 +26,11 @@ import org.sonar.server.qualityprofile.QualityProfile;
public interface AnalysisMetadataHolder {
/**
+ * @throws IllegalStateException if organizations enabled flag has not been set
+ */
+ boolean isOrganizationsEnabled();
+
+ /**
* Returns the organization the analysis belongs to.
* @throws IllegalStateException if organization has not been set
*/
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
index 2fa37770c95..c26f123efdf 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
@@ -32,6 +32,7 @@ import static java.util.Objects.requireNonNull;
public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder {
private static final String BRANCH_NOT_SET = "Branch has not been set";
+ private final InitializedProperty<Boolean> organizationsEnabled = new InitializedProperty<>();
private final InitializedProperty<Organization> organization = new InitializedProperty<>();
private final InitializedProperty<String> uuid = new InitializedProperty<>();
private final InitializedProperty<Long> analysisDate = new InitializedProperty<>();
@@ -44,6 +45,19 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
private final InitializedProperty<Map<String, ScannerPlugin>> pluginsByKey = new InitializedProperty<>();
@Override
+ public MutableAnalysisMetadataHolder setOrganizationsEnabled(boolean isOrganizationsEnabled) {
+ checkState(!this.organizationsEnabled.isInitialized(), "Organization enabled flag has already been set");
+ this.organizationsEnabled.setProperty(isOrganizationsEnabled);
+ return this;
+ }
+
+ @Override
+ public boolean isOrganizationsEnabled() {
+ checkState(organizationsEnabled.isInitialized(), "Organizations enabled flag has not been set");
+ return organizationsEnabled.getProperty();
+ }
+
+ @Override
public MutableAnalysisMetadataHolder setOrganization(Organization organization) {
checkState(!this.organization.isInitialized(), "Organization has already been set");
requireNonNull(organization, "Organization can't be null");
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
index 3cf3704c84b..b4e4e541cfd 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
@@ -26,6 +26,11 @@ import org.sonar.server.qualityprofile.QualityProfile;
public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder {
/**
+ * @throws IllegalStateException if organizations enabled flag has already been set
+ */
+ MutableAnalysisMetadataHolder setOrganizationsEnabled(boolean isOrganizationsEnabled);
+
+ /**
* @throws IllegalStateException if the organization uuid has already been set
*/
MutableAnalysisMetadataHolder setOrganization(Organization organization);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Organization.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Organization.java
index 2c2372ee2c9..c48b07ab9fe 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Organization.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Organization.java
@@ -30,14 +30,12 @@ public class Organization {
private final String key;
private final String name;
private final String defaultQualityGateUuid;
- private final boolean organizationsEnabled;
- private Organization(String uuid, String key, String name, String defaultQualityGateUuid, boolean organizationsEnabled) {
+ private Organization(String uuid, String key, String name, String defaultQualityGateUuid) {
this.uuid = requireNonNull(uuid, "uuid can't be null");
this.key = requireNonNull(key, "key can't be null");
this.name = requireNonNull(name, "name can't be null");
this.defaultQualityGateUuid = requireNonNull(defaultQualityGateUuid, "defaultQualityGateUuid can't be null");
- this.organizationsEnabled = organizationsEnabled;
}
public String getUuid() {
@@ -56,10 +54,6 @@ public class Organization {
return defaultQualityGateUuid;
}
- public boolean isOrganizationsEnabled() {
- return organizationsEnabled;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -84,7 +78,6 @@ public class Organization {
", key='" + key + '\'' +
", name='" + name + '\'' +
", defaultQualityGateUuid='" + defaultQualityGateUuid + '\'' +
- ", organizationsEnabled=" + organizationsEnabled +
'}';
}
@@ -96,13 +89,8 @@ public class Organization {
.setDefaultQualityGateUuid(defaultQualityGateUuid);
}
- public static Organization from(OrganizationDto organizationDto, boolean organizationsEnabled) {
- return new Organization(
- organizationDto.getUuid(),
- organizationDto.getKey(),
- organizationDto.getName(),
- organizationDto.getDefaultQualityGateUuid(),
- organizationsEnabled);
+ public static Organization from(OrganizationDto organizationDto) {
+ return new Organization(organizationDto.getUuid(), organizationDto.getKey(), organizationDto.getName(), organizationDto.getDefaultQualityGateUuid());
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
index cfbc4c03446..7e2c720470d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
@@ -129,11 +129,11 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
@CheckForNull
private Organization createOrganization() {
- org.sonar.server.computation.task.projectanalysis.analysis.Organization organization = analysisMetadataHolder.getOrganization();
- if (organization.isOrganizationsEnabled()) {
- return new OrganizationImpl(organization.getName(), organization.getKey());
+ if (!analysisMetadataHolder.isOrganizationsEnabled()) {
+ return null;
}
- return null;
+ org.sonar.server.computation.task.projectanalysis.analysis.Organization organization = analysisMetadataHolder.getOrganization();
+ return new OrganizationImpl(organization.getName(), organization.getKey());
}
private Optional<Analysis> getAnalysis() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
index 12b1a3121ba..52d459ee2a5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
@@ -70,7 +70,8 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
private final OrganizationFlags organizationFlags;
public LoadReportAnalysisMetadataHolderStep(CeTask ceTask, BatchReportReader reportReader, MutableAnalysisMetadataHolder analysisMetadata,
- DefaultOrganizationProvider defaultOrganizationProvider, DbClient dbClient, BranchLoader branchLoader, PluginRepository pluginRepository, OrganizationFlags organizationFlags) {
+ DefaultOrganizationProvider defaultOrganizationProvider, DbClient dbClient, BranchLoader branchLoader, PluginRepository pluginRepository,
+ OrganizationFlags organizationFlags) {
this.ceTask = ceTask;
this.reportReader = reportReader;
this.analysisMetadata = analysisMetadata;
@@ -112,10 +113,13 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
}
private Organization loadOrganization(ScannerReport.Metadata reportMetadata) {
- Organization organization = toOrganization(ceTask.getOrganizationUuid());
- checkOrganizationKeyConsistency(reportMetadata, organization);
- analysisMetadata.setOrganization(organization);
- return organization;
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ Organization organization = toOrganization(dbSession, ceTask.getOrganizationUuid());
+ checkOrganizationKeyConsistency(reportMetadata, organization);
+ analysisMetadata.setOrganization(organization);
+ analysisMetadata.setOrganizationsEnabled(organizationFlags.isEnabled(dbSession));
+ return organization;
+ }
}
private void loadQualityProfiles(ScannerReport.Metadata reportMetadata, Organization organization) {
@@ -204,12 +208,10 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
return organizationKey == null || organizationKey.isEmpty();
}
- private Organization toOrganization(String organizationUuid) {
- try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
- checkState(organizationDto.isPresent(), "Organization with uuid '%s' can't be found", organizationUuid);
- return Organization.from(organizationDto.get(), organizationFlags.isEnabled(dbSession));
- }
+ private Organization toOrganization(DbSession dbSession, String organizationUuid) {
+ Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
+ checkState(organizationDto.isPresent(), "Organization with uuid '%s' can't be found", organizationUuid);
+ return Organization.from(organizationDto.get());
}
private ComponentDto toProject(String projectKey) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
index f1cc20ebdc6..f458005bc70 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.computation.task.projectanalysis.analysis;
-import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -63,9 +62,7 @@ public class AnalysisMetadataHolderImplTest {
@Test
public void setOrganization_throws_ISE_if_called_twice() {
- Organization organization = Organization.from(
- new OrganizationDto().setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("anyuuidr"),
- new Random().nextBoolean());
+ Organization organization = Organization.from(new OrganizationDto().setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("anyuuidr"));
underTest.setOrganization(organization);
expectedException.expect(IllegalStateException.class);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
index 0d22c0f314f..cf89ba5747c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
@@ -35,6 +35,8 @@ import static java.util.Objects.requireNonNull;
public class AnalysisMetadataHolderRule extends ExternalResource implements MutableAnalysisMetadataHolder {
+ private final InitializedProperty<Boolean> organizationsEnabled = new InitializedProperty<>();
+
private final InitializedProperty<Organization> organization = new InitializedProperty<>();
private final InitializedProperty<String> uuid = new InitializedProperty<>();
@@ -56,6 +58,18 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta
private final InitializedProperty<Map<String, ScannerPlugin>> pluginsByKey = new InitializedProperty<>();
@Override
+ public AnalysisMetadataHolderRule setOrganizationsEnabled(boolean isOrganizationsEnabled) {
+ this.organizationsEnabled.setProperty(isOrganizationsEnabled);
+ return this;
+ }
+
+ @Override
+ public boolean isOrganizationsEnabled() {
+ checkState(organizationsEnabled.isInitialized(), "Organizations enabled flag has not been set");
+ return organizationsEnabled.getProperty();
+ }
+
+ @Override
public AnalysisMetadataHolderRule setOrganization(Organization organization) {
requireNonNull(organization, "organization can't be null");
this.organization.setProperty(organization);
@@ -64,13 +78,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta
public AnalysisMetadataHolderRule setOrganizationUuid(String uuid, String defaultQualityGateUuid) {
requireNonNull(uuid, "organization uuid can't be null");
- this.organization.setProperty(Organization.from(
- new OrganizationDto()
- .setUuid(uuid)
- .setKey("key_" + uuid)
- .setName("name_" + uuid)
- .setDefaultQualityGateUuid(defaultQualityGateUuid),
- false));
+ this.organization.setProperty(Organization.from(new OrganizationDto().setUuid(uuid).setKey("key_" + uuid).setName("name_" + uuid).setDefaultQualityGateUuid(defaultQualityGateUuid)));
return this;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
index 4a10bba6cdf..9935ae33d25 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
@@ -35,6 +35,17 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen
}
@Override
+ public boolean isOrganizationsEnabled() {
+ return delegate.isOrganizationsEnabled();
+ }
+
+ @Override
+ public MutableAnalysisMetadataHolderRule setOrganizationsEnabled(boolean isOrganizationsEnabled) {
+ delegate.setOrganizationsEnabled(isOrganizationsEnabled);
+ return this;
+ }
+
+ @Override
public MutableAnalysisMetadataHolderRule setOrganization(Organization organization) {
delegate.setOrganization(organization);
return this;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/OrganizationTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/OrganizationTest.java
index 2767fb4aa60..9699cd6d654 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/OrganizationTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/OrganizationTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.computation.task.projectanalysis.analysis;
-import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -37,7 +36,7 @@ public class OrganizationTest {
public void build_throws_NPE_if_dto_is_null() {
expectedException.expect(NullPointerException.class);
- Organization.from(null, new Random().nextBoolean());
+ Organization.from(null);
}
@Test
@@ -45,7 +44,7 @@ public class OrganizationTest {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("uuid can't be null");
- Organization.from(underTest, new Random().nextBoolean());
+ Organization.from(underTest);
}
@Test
@@ -55,7 +54,7 @@ public class OrganizationTest {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("key can't be null");
- Organization.from(underTest, new Random().nextBoolean());
+ Organization.from(underTest);
}
@Test
@@ -65,7 +64,7 @@ public class OrganizationTest {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("defaultQualityGateUuid can't be null");
- Organization.from(underTest, new Random().nextBoolean());
+ Organization.from(underTest);
}
@Test
@@ -75,58 +74,42 @@ public class OrganizationTest {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("name can't be null");
- Organization.from(underTest, new Random().nextBoolean());
+ Organization.from(underTest);
}
@Test
public void verify_getters() {
- boolean organizationsEnabled = new Random().nextBoolean();
- Organization organization = Organization.from(
- underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"),
- organizationsEnabled);
+ Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
assertThat(organization.getUuid()).isEqualTo("uuid");
assertThat(organization.getKey()).isEqualTo("key");
assertThat(organization.getName()).isEqualTo("name");
assertThat(organization.getDefaultQualityGateUuid()).isEqualTo("uuid1");
- assertThat(organization.isOrganizationsEnabled()).isEqualTo(organizationsEnabled);
}
@Test
public void verify_toString() {
- Organization organization = Organization.from(
- underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"),
- false);
+ Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
- assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name', defaultQualityGateUuid='uuid1', organizationsEnabled=false}");
+ assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name', defaultQualityGateUuid='uuid1'}");
}
@Test
public void equals_is_based_on_uuid_only() {
- boolean organizationsEnabled = new Random().nextBoolean();
- Organization organization = Organization.from(
- underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"),
- organizationsEnabled);
-
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"), organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"), !organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("other key").setName("name").setDefaultQualityGateUuid("uuid1"), organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("other key").setName("name").setDefaultQualityGateUuid("uuid1"), !organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("other name").setDefaultQualityGateUuid("uuid1"), organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("other name").setDefaultQualityGateUuid("uuid1"), !organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("other uuid"), organizationsEnabled));
- assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("other uuid"), !organizationsEnabled));
- assertThat(organization)
- .isNotEqualTo(Organization.from(underTest.setUuid("other uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"), organizationsEnabled));
- assertThat(organization).isNotEqualTo(
- Organization.from(underTest.setUuid("other uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"), !organizationsEnabled));
+ Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
+
+ assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1")));
+ assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("other key").setName("name").setDefaultQualityGateUuid("uuid1")));
+ assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("other name").setDefaultQualityGateUuid("uuid1")));
+ assertThat(organization).isEqualTo(Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("other uuid")));
+ assertThat(organization).isNotEqualTo(Organization.from(underTest.setUuid("other uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1")));
assertThat(organization).isNotEqualTo(null);
assertThat(organization).isNotEqualTo("toto");
}
@Test
public void hashcode_is_based_on_uuid_only() {
- Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"), new Random().nextBoolean());
+ Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
assertThat(organization.hashCode()).isEqualTo("uuid".hashCode());
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
index c5ef8cda1c3..119e9885d7d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
@@ -109,10 +109,11 @@ public class PostProjectAnalysisTasksExecutorTest {
CONDITION_2, ConditionStatus.NO_VALUE_STATUS));
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(BranchType.LONG);
- analysisMetadataHolder.setBranch(branch);
- analysisMetadataHolder.setOrganization(Organization.from(
- new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"),
- new Random().nextBoolean()));
+ analysisMetadataHolder
+ .setBranch(branch)
+ .setOrganizationsEnabled(new Random().nextBoolean())
+ .setOrganization(Organization.from(
+ new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo")));
}
@Test
@@ -146,9 +147,10 @@ public class PostProjectAnalysisTasksExecutorTest {
@Test
@UseDataProvider("booleanValues")
public void organization_is_null_when_organization_are_disabled(boolean allStepsExecuted) {
- analysisMetadataHolder.setOrganization(Organization.from(
- new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"),
- false));
+ analysisMetadataHolder
+ .setOrganizationsEnabled(false)
+ .setOrganization(Organization.from(
+ new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo")));
underTest.finished(allStepsExecuted);
verify(postProjectAnalysisTask).finished(projectAnalysisArgumentCaptor.capture());
@@ -159,9 +161,10 @@ public class PostProjectAnalysisTasksExecutorTest {
@Test
@UseDataProvider("booleanValues")
public void organization_is_not_null_when_organization_are_enabled(boolean allStepsExecuted) {
- analysisMetadataHolder.setOrganization(Organization.from(
- new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"),
- true));
+ analysisMetadataHolder
+ .setOrganizationsEnabled(true)
+ .setOrganization(Organization.from(
+ new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo")));
underTest.finished(allStepsExecuted);
verify(postProjectAnalysisTask).finished(projectAnalysisArgumentCaptor.capture());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java
index d429fb7fa1e..ef0a8bb554c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/DefaultAssigneeTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.computation.task.projectanalysis.issue;
-import java.util.Random;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -55,8 +54,7 @@ public class DefaultAssigneeTest {
public void setUp() throws Exception {
organizationDto = db.organizations().insertForUuid(ORGANIZATION_UUID);
analysisMetadataHolder.setOrganization(Organization.from(
- new OrganizationDto().setUuid(ORGANIZATION_UUID).setKey("Organization key").setName("Organization name").setDefaultQualityGateUuid(QUALITY_GATE_UUID),
- new Random().nextBoolean()));
+ new OrganizationDto().setUuid(ORGANIZATION_UUID).setKey("Organization key").setName("Organization name").setDefaultQualityGateUuid(QUALITY_GATE_UUID)));
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
index b05a1b09df8..6bd9523036e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
@@ -44,11 +44,12 @@ import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader
import org.sonar.server.computation.task.projectanalysis.component.BranchLoader;
import org.sonar.server.computation.task.step.ComputationStep;
import org.sonar.server.organization.DefaultOrganizationProvider;
+import org.sonar.server.organization.OrganizationFlags;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
-import org.sonar.server.organization.TestOrganizationFlags;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -69,9 +70,9 @@ public class LoadReportAnalysisMetadataHolderStepTest {
private DbClient dbClient = db.getDbClient();
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
private PluginRepository pluginRepository = mock(PluginRepository.class);
private ComputationStep underTest;
+ private OrganizationFlags organizationFlags = mock(OrganizationFlags.class);
@Before
public void setUp() {
@@ -220,7 +221,7 @@ public class LoadReportAnalysisMetadataHolderStepTest {
newBatchReportBuilder()
.setOrganizationKey(db.getDefaultOrganization().getKey())
.build());
- organizationFlags.setEnabled(organizationEnabled);
+ when(organizationFlags.isEnabled(any())).thenReturn(organizationEnabled);
underTest.execute();
@@ -229,7 +230,7 @@ public class LoadReportAnalysisMetadataHolderStepTest {
assertThat(organization.getUuid()).isEqualTo(defaultOrganization.getUuid());
assertThat(organization.getKey()).isEqualTo(defaultOrganization.getKey());
assertThat(organization.getName()).isEqualTo(defaultOrganization.getName());
- assertThat(organization.isOrganizationsEnabled()).isEqualTo(organizationEnabled);
+ assertThat(analysisMetadataHolder.isOrganizationsEnabled()).isEqualTo(organizationEnabled);
}
@Test
@@ -242,7 +243,7 @@ public class LoadReportAnalysisMetadataHolderStepTest {
.setOrganizationKey(nonDefaultOrganizationDto.getKey())
.setProjectKey(project.getDbKey())
.build());
- organizationFlags.setEnabled(organizationEnabled);
+ when(organizationFlags.isEnabled(any())).thenReturn(organizationEnabled);
ComputationStep underTest = createStep(createCeTask(project.getDbKey(), nonDefaultOrganizationDto.getUuid()));
@@ -252,14 +253,14 @@ public class LoadReportAnalysisMetadataHolderStepTest {
assertThat(organization.getUuid()).isEqualTo(nonDefaultOrganizationDto.getUuid());
assertThat(organization.getKey()).isEqualTo(nonDefaultOrganizationDto.getKey());
assertThat(organization.getName()).isEqualTo(nonDefaultOrganizationDto.getName());
- assertThat(organization.isOrganizationsEnabled()).isEqualTo(organizationEnabled);
+ assertThat(analysisMetadataHolder.isOrganizationsEnabled()).isEqualTo(organizationEnabled);
}
@DataProvider
public static Object[][] organizationEnabledFlags() {
return new Object[][] {
- { true },
- { false }
+ {true},
+ {false}
};
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/VerifyBillingStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/VerifyBillingStepTest.java
index 337a60e1b93..925e1069471 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/VerifyBillingStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/VerifyBillingStepTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -47,7 +46,7 @@ public class VerifyBillingStepTest {
private OrganizationDto organization = newOrganizationDto();
@Rule
public MutableAnalysisMetadataHolderRule analysisMetadata = new MutableAnalysisMetadataHolderRule()
- .setOrganization(Organization.from(organization, new Random().nextBoolean()));
+ .setOrganization(Organization.from(organization));
private BillingValidationsProxy validations = mock(BillingValidationsProxy.class);