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) {
+ private Organization(String uuid, String key, String name, String defaultQualityGateUuid, boolean organizationsEnabled) {
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() {
return defaultQualityGateUuid;
}
+ public boolean isOrganizationsEnabled() {
+ return organizationsEnabled;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
", key='" + key + '\'' +
", name='" + name + '\'' +
", defaultQualityGateUuid='" + defaultQualityGateUuid + '\'' +
+ ", organizationsEnabled=" + organizationsEnabled +
'}';
}
.setDefaultQualityGateUuid(defaultQualityGateUuid);
}
- public static Organization from(OrganizationDto organizationDto) {
- return new Organization(organizationDto.getUuid(), organizationDto.getKey(), organizationDto.getName(), organizationDto.getDefaultQualityGateUuid());
+ public static Organization from(OrganizationDto organizationDto, boolean organizationsEnabled) {
+ return new Organization(
+ organizationDto.getUuid(),
+ organizationDto.getKey(),
+ organizationDto.getName(),
+ organizationDto.getDefaultQualityGateUuid(),
+ organizationsEnabled);
}
}
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.qualityprofile.QualityProfile;
import static com.google.common.base.Preconditions.checkState;
private final DbClient dbClient;
private final BranchLoader branchLoader;
private final PluginRepository pluginRepository;
+ private final OrganizationFlags organizationFlags;
public LoadReportAnalysisMetadataHolderStep(CeTask ceTask, BatchReportReader reportReader, MutableAnalysisMetadataHolder analysisMetadata,
- DefaultOrganizationProvider defaultOrganizationProvider, DbClient dbClient, BranchLoader branchLoader, PluginRepository pluginRepository) {
+ DefaultOrganizationProvider defaultOrganizationProvider, DbClient dbClient, BranchLoader branchLoader, PluginRepository pluginRepository, OrganizationFlags organizationFlags) {
this.ceTask = ceTask;
this.reportReader = reportReader;
this.analysisMetadata = analysisMetadata;
this.dbClient = dbClient;
this.branchLoader = branchLoader;
this.pluginRepository = pluginRepository;
+ this.organizationFlags = organizationFlags;
}
@Override
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());
+ return Organization.from(organizationDto.get(), organizationFlags.isEnabled(dbSession));
}
}
*/
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;
@Test
public void setOrganization_throws_ISE_if_called_twice() {
- Organization organization = Organization.from(new OrganizationDto().setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("anyuuidr"));
+ Organization organization = Organization.from(
+ new OrganizationDto().setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("anyuuidr"),
+ new Random().nextBoolean());
underTest.setOrganization(organization);
expectedException.expect(IllegalStateException.class);
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)));
+ this.organization.setProperty(Organization.from(
+ new OrganizationDto()
+ .setUuid(uuid)
+ .setKey("key_" + uuid)
+ .setName("name_" + uuid)
+ .setDefaultQualityGateUuid(defaultQualityGateUuid),
+ false));
return this;
}
*/
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;
public void build_throws_NPE_if_dto_is_null() {
expectedException.expect(NullPointerException.class);
- Organization.from(null);
+ Organization.from(null, new Random().nextBoolean());
}
@Test
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("uuid can't be null");
- Organization.from(underTest);
+ Organization.from(underTest, new Random().nextBoolean());
}
@Test
public void build_throws_NPE_if_key_is_null() {
underTest.setUuid("uuid");
-
+
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("key can't be null");
- Organization.from(underTest);
+ Organization.from(underTest, new Random().nextBoolean());
}
@Test
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("defaultQualityGateUuid can't be null");
- Organization.from(underTest);
+ Organization.from(underTest, new Random().nextBoolean());
}
@Test
public void build_throws_NPE_if_name_is_null() {
underTest.setUuid("uuid").setKey("key");
-
+
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("name can't be null");
- Organization.from(underTest);
+ Organization.from(underTest, new Random().nextBoolean());
}
@Test
public void verify_getters() {
- Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"));
+ boolean organizationsEnabled = new Random().nextBoolean();
+ Organization organization = Organization.from(
+ underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"),
+ organizationsEnabled);
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"));
+ Organization organization = Organization.from(
+ underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"),
+ false);
- assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name', defaultQualityGateUuid='uuid1'}");
+ assertThat(organization.toString()).isEqualTo("Organization{uuid='uuid', key='key', name='name', defaultQualityGateUuid='uuid1', organizationsEnabled=false}");
}
@Test
public void equals_is_based_on_uuid_only() {
- 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")));
+ 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));
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"));
+ Organization organization = Organization.from(underTest.setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("uuid1"), new Random().nextBoolean());
assertThat(organization.hashCode()).isEqualTo("uuid".hashCode());
}
*/
package org.sonar.server.computation.task.projectanalysis.issue;
+import java.util.Random;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
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 OrganizationDto().setUuid(ORGANIZATION_UUID).setKey("Organization key").setName("Organization name").setDefaultQualityGateUuid(QUALITY_GATE_UUID),
+ new Random().nextBoolean()));
}
@Test
*/
package org.sonar.server.computation.task.projectanalysis.step;
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.ce.queue.CeTask;
import org.sonar.server.computation.task.step.ComputationStep;
import org.sonar.server.organization.DefaultOrganizationProvider;
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.Mockito.mock;
import static org.mockito.Mockito.when;
+@RunWith(DataProviderRunner.class)
public class LoadReportAnalysisMetadataHolderStepTest {
private static final String PROJECT_KEY = "project_key";
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;
}
@Test
- public void execute_set_organization_from_ce_task_when_organizationKey_is_set_in_report() {
+ @UseDataProvider("organizationEnabledFlags")
+ public void execute_set_organization_from_ce_task_when_organizationKey_is_set_in_report(boolean organizationEnabled) {
reportReader.setMetadata(
newBatchReportBuilder()
.setOrganizationKey(db.getDefaultOrganization().getKey())
.build());
+ organizationFlags.setEnabled(organizationEnabled);
underTest.execute();
assertThat(organization.getUuid()).isEqualTo(defaultOrganization.getUuid());
assertThat(organization.getKey()).isEqualTo(defaultOrganization.getKey());
assertThat(organization.getName()).isEqualTo(defaultOrganization.getName());
+ assertThat(organization.isOrganizationsEnabled()).isEqualTo(organizationEnabled);
}
@Test
- public void execute_set_non_default_organization_from_ce_task() {
+ @UseDataProvider("organizationEnabledFlags")
+ public void execute_set_non_default_organization_from_ce_task(boolean organizationEnabled) {
OrganizationDto nonDefaultOrganizationDto = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject(nonDefaultOrganizationDto);
reportReader.setMetadata(
.setOrganizationKey(nonDefaultOrganizationDto.getKey())
.setProjectKey(project.getDbKey())
.build());
+ organizationFlags.setEnabled(organizationEnabled);
ComputationStep underTest = createStep(createCeTask(project.getDbKey(), nonDefaultOrganizationDto.getUuid()));
assertThat(organization.getUuid()).isEqualTo(nonDefaultOrganizationDto.getUuid());
assertThat(organization.getKey()).isEqualTo(nonDefaultOrganizationDto.getKey());
assertThat(organization.getName()).isEqualTo(nonDefaultOrganizationDto.getName());
+ assertThat(organization.isOrganizationsEnabled()).isEqualTo(organizationEnabled);
+ }
+
+ @DataProvider
+ public static Object[][] organizationEnabledFlags() {
+ return new Object[][] {
+ { true },
+ { false }
+ };
}
@Test
private LoadReportAnalysisMetadataHolderStep createStep(CeTask ceTask) {
return new LoadReportAnalysisMetadataHolderStep(ceTask, reportReader, analysisMetadataHolder,
- defaultOrganizationProvider, dbClient, new BranchLoader(analysisMetadataHolder), pluginRepository);
+ defaultOrganizationProvider, dbClient, new BranchLoader(analysisMetadataHolder), pluginRepository, organizationFlags);
}
private static ScannerReport.Metadata.Builder newBatchReportBuilder() {
*/
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;
private OrganizationDto organization = newOrganizationDto();
@Rule
public MutableAnalysisMetadataHolderRule analysisMetadata = new MutableAnalysisMetadataHolderRule()
- .setOrganization(Organization.from(organization));
+ .setOrganization(Organization.from(organization, new Random().nextBoolean()));
private BillingValidationsProxy validations = mock(BillingValidationsProxy.class);