From e42e2b18cdef809b793fe6f3b2d30f32dfb66674 Mon Sep 17 00:00:00 2001 From: Jacek Date: Thu, 17 Dec 2020 10:22:36 +0100 Subject: [PATCH] SONAR-13999 drop organization from CE steps --- .../java/org/sonar/ce/queue/CeQueueImpl.java | 11 +- .../org/sonar/ce/queue/CeQueueImplTest.java | 20 +-- .../analysis/AnalysisMetadataHolder.java | 11 -- .../analysis/AnalysisMetadataHolderImpl.java | 29 ----- .../MutableAnalysisMetadataHolder.java | 10 -- .../analysis/Organization.java | 96 -------------- .../PostProjectAnalysisTasksExecutor.java | 37 +----- .../measure/PostMeasuresComputationCheck.java | 9 -- .../PostMeasuresComputationChecksStep.java | 9 -- .../LoadReportAnalysisMetadataHolderStep.java | 65 +--------- .../step/PersistComponentsStep.java | 7 +- .../step/ReportComputationSteps.java | 1 - .../step/VerifyBillingStep.java | 57 -------- .../AnalysisMetadataHolderImplTest.java | 51 +------- .../analysis/OrganizationTest.java | 116 ----------------- .../PostProjectAnalysisTasksExecutorTest.java | 51 ++------ .../component/BranchPersisterImplTest.java | 10 +- .../component/ComponentTreeBuilderTest.java | 5 +- .../ConfigurationRepositoryTest.java | 3 +- .../component/ProjectPersisterTest.java | 6 +- .../filemove/FileMoveDetectionStepTest.java | 4 +- .../issue/ComponentIssuesLoaderTest.java | 13 +- .../issue/IntegrateIssuesVisitorTest.java | 10 +- .../issue/RuleRepositoryImplTest.java | 2 - .../issue/ScmAccountToUserLoaderTest.java | 2 - ...rackerReferenceBranchInputFactoryTest.java | 2 +- .../measure/MeasureRepositoryImplTest.java | 4 +- ...PostMeasuresComputationChecksStepTest.java | 3 +- .../step/BuildComponentTreeStepTest.java | 25 ++-- .../step/EnableAnalysisStepTest.java | 10 +- .../step/ExtractReportStepTest.java | 1 - ...ProjectDuplicationsRepositoryStepTest.java | 10 +- .../step/LoadPeriodsStepTest.java | 10 +- .../step/LoadQualityGateStepTest.java | 2 - ...dReportAnalysisMetadataHolderStepTest.java | 122 ++---------------- .../step/PersistComponentsStepTest.java | 4 +- .../step/PersistDuplicationDataStepTest.java | 3 +- .../step/PersistIssuesStepTest.java | 16 +-- .../step/PersistLiveMeasuresStepTest.java | 3 +- .../step/PersistMeasuresStepTest.java | 3 +- .../step/ReportPersistAnalysisStepTest.java | 32 ++--- .../step/ReportPersistComponentsStepTest.java | 30 ++--- .../step/SendIssueNotificationsStepTest.java | 15 +-- .../step/ValidateProjectStepTest.java | 8 +- .../step/VerifyBillingStepTest.java | 83 ------------ .../step/ViewsPersistAnalysisStepTest.java | 12 +- .../step/ViewsPersistComponentsStepTest.java | 72 +++++------ .../IgnoreOrphanBranchStepTest.java | 2 - .../taskprocessor/IndexIssuesStepTest.java | 2 - .../IssueSyncTaskProcessorTest.java | 1 - .../analysis/AnalysisMetadataHolderRule.java | 39 +----- .../MutableAnalysisMetadataHolderRule.java | 27 +--- .../main/java/org/sonar/ce/task/CeTask.java | 18 --- .../java/org/sonar/ce/task/CeTaskTest.java | 86 ++---------- .../ce/task/log/CeTaskMessagesImplTest.java | 1 - .../container/ComputeEngineContainerImpl.java | 8 +- .../sonar/ce/queue/InternalCeQueueImpl.java | 5 +- ...lureNotificationExecutionListenerTest.java | 7 +- .../ce/queue/InternalCeQueueImplTest.java | 32 +---- .../CeTaskProcessorRepositoryImplTest.java | 1 - .../ce/taskprocessor/CeWorkerImplTest.java | 23 +--- .../sonar/db/component/ComponentTesting.java | 1 + .../sonar/server/ce/ws/CancelActionTest.java | 7 +- .../sonar/server/ce/ws/SubmitActionTest.java | 1 - .../scanner/report/MetadataPublisher.java | 2 - .../scanner/report/MetadataPublisherTest.java | 14 -- .../src/main/protobuf/scanner_report.proto | 2 +- 67 files changed, 211 insertions(+), 1173 deletions(-) delete mode 100644 server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Organization.java delete mode 100644 server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java delete mode 100644 server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/OrganizationTest.java delete mode 100644 server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java index 8fe59104537..e0bd75db085 100644 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java @@ -49,7 +49,6 @@ import org.sonar.db.ce.CeTaskCharacteristicDto; import org.sonar.db.ce.DeleteIf; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.UserDto; -import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.property.InternalProperties; import static com.google.common.base.Preconditions.checkState; @@ -69,13 +68,11 @@ public class CeQueueImpl implements CeQueue { private final System2 system2; private final DbClient dbClient; private final UuidFactory uuidFactory; - private final DefaultOrganizationProvider defaultOrganizationProvider; - public CeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory, DefaultOrganizationProvider defaultOrganizationProvider) { + public CeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory) { this.system2 = system2; this.dbClient = dbClient; this.uuidFactory = uuidFactory; - this.defaultOrganizationProvider = defaultOrganizationProvider; } @Override @@ -356,7 +353,6 @@ public class CeQueueImpl implements CeQueue { String componentUuid = taskDto.getComponentUuid(); if (component != null) { builder.setComponent(new CeTask.Component(component.uuid(), component.getDbKey(), component.name())); - builder.setOrganizationUuid(component.getOrganizationUuid()); } else if (componentUuid != null) { builder.setComponent(new CeTask.Component(componentUuid, null, null)); } @@ -368,11 +364,6 @@ public class CeQueueImpl implements CeQueue { builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null)); } - // FIXME this should be set from the CeQueueDto - if (!builder.hasOrganizationUuid()) { - builder.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); - } - return builder.build(); } diff --git a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java index b2bdccb22a1..03970bd6ca8 100644 --- a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java +++ b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java @@ -44,8 +44,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserTesting; -import org.sonar.server.organization.DefaultOrganizationProvider; -import org.sonar.server.organization.TestDefaultOrganizationProvider; import static com.google.common.collect.ImmutableList.of; import static java.util.Arrays.asList; @@ -72,9 +70,8 @@ public class CeQueueImplTest { private DbSession session = db.getSession(); private UuidFactory uuidFactory = new SequenceUuidFactory(); - private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); - private CeQueue underTest = new CeQueueImpl(system2, db.getDbClient(), uuidFactory, defaultOrganizationProvider); + private CeQueue underTest = new CeQueueImpl(system2, db.getDbClient(), uuidFactory); @Test public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() { @@ -91,7 +88,7 @@ public class CeQueueImplTest { @Test public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() { - ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert(), "PROJECT_1")); + ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1")); CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto), null); CeTask task = underTest.submit(taskSubmit); @@ -226,7 +223,7 @@ public class CeQueueImplTest { @Test public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_exists() { - ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_1")); + ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1")); CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto1), null); CeTaskSubmit taskSubmit2 = createTaskSubmit("something", newComponent(randomAlphabetic(12)), null); @@ -239,7 +236,7 @@ public class CeQueueImplTest { @Test public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() { - ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_1")); + ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1")); ComponentDto branch1 = db.components().insertProjectBranch(project); ComponentDto branch2 = db.components().insertProjectBranch(project); CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1), null); @@ -510,11 +507,6 @@ public class CeQueueImplTest { } private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable ComponentDto mainComponentDto, @Nullable UserDto userDto) { - if (componentDto == null) { - assertThat(task.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); - } else { - assertThat(task.getOrganizationUuid()).isEqualTo(componentDto.getOrganizationUuid()); - } assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid()); if (componentDto != null) { CeTask.Component component = task.getComponent().get(); @@ -582,9 +574,7 @@ public class CeQueueImplTest { } private ComponentDto insertComponent(ComponentDto componentDto) { - db.getDbClient().componentDao().insert(session, componentDto); - session.commit(); - return componentDto; + return db.components().insertComponent(componentDto); } private UserDto insertUser(UserDto userDto) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolder.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolder.java index d5b3b9dbf61..4a01822403d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolder.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolder.java @@ -27,17 +27,6 @@ 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 - */ - Organization getOrganization(); - /** * Returns the UUID generated for this analysis. * @throws IllegalStateException if uuid has not been set diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java index ef17288e84e..9df84dd306b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java @@ -37,8 +37,6 @@ import static org.apache.commons.lang.StringUtils.defaultIfBlank; public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder { private static final String BRANCH_NOT_SET = "Branch has not been set"; - private final InitializedProperty organizationsEnabled = new InitializedProperty<>(); - private final InitializedProperty organization = new InitializedProperty<>(); private final InitializedProperty uuid = new InitializedProperty<>(); private final InitializedProperty analysisDate = new InitializedProperty<>(); private final InitializedProperty baseProjectSnapshot = new InitializedProperty<>(); @@ -58,33 +56,6 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder this.editionProvider = editionProvider; } - @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"); - this.organization.setProperty(organization); - return this; - } - - @Override - public Organization getOrganization() { - checkState(organization.isInitialized(), "Organization has not been set"); - return organization.getProperty(); - } - @Override public MutableAnalysisMetadataHolder setUuid(String s) { checkState(!uuid.isInitialized(), "Analysis uuid has already been set"); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java index 7ffa27cd47a..b2dd188756d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java @@ -26,16 +26,6 @@ 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); - /** * @throws IllegalStateException if the analysis uuid has already been set */ diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Organization.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Organization.java deleted file mode 100644 index e6597ff2136..00000000000 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Organization.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.ce.task.projectanalysis.analysis; - -import javax.annotation.concurrent.Immutable; -import org.sonar.db.organization.OrganizationDto; - -import static java.util.Objects.requireNonNull; - -@Immutable -public class Organization { - private final String uuid; - private final String key; - private final String name; - private final String defaultQualityGateUuid; - - 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"); - } - - public String getUuid() { - return uuid; - } - - public String getKey() { - return key; - } - - public String getName() { - return name; - } - - public String getDefaultQualityGateUuid() { - return defaultQualityGateUuid; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Organization that = (Organization) o; - return uuid.equals(that.uuid); - } - - @Override - public int hashCode() { - return uuid.hashCode(); - } - - @Override - public String toString() { - return "Organization{" + - "uuid='" + uuid + '\'' + - ", key='" + key + '\'' + - ", name='" + name + '\'' + - ", defaultQualityGateUuid='" + defaultQualityGateUuid + '\'' + - '}'; - } - - public OrganizationDto toDto() { - return new OrganizationDto() - .setName(name) - .setKey(key) - .setUuid(uuid) - .setDefaultQualityGateUuid(defaultQualityGateUuid); - } - - public static Organization from(OrganizationDto organizationDto) { - return new Organization(organizationDto.getUuid(), organizationDto.getKey(), organizationDto.getName(), organizationDto.getDefaultQualityGateUuid()); - } - -} diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java index 3ef9e5d5344..bfdd9f653b3 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java @@ -166,7 +166,6 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor private ProjectAnalysisImpl createProjectAnalysis(CeTask.Status status) { return new ProjectAnalysisImpl( - createOrganization(), new CeTaskImpl(this.ceTask.getUuid(), status), createProject(this.ceTask), getAnalysis().orElse(null), @@ -177,15 +176,6 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor reportReader.readMetadata().getScmRevisionId()); } - @CheckForNull - private Organization createOrganization() { - if (!analysisMetadataHolder.isOrganizationsEnabled()) { - return null; - } - org.sonar.ce.task.projectanalysis.analysis.Organization organization = analysisMetadataHolder.getOrganization(); - return new OrganizationImpl(organization.getName(), organization.getKey()); - } - private Optional getAnalysis() { Long analysisDate = getAnalysisDate(); @@ -254,8 +244,6 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor } private static class ProjectAnalysisImpl implements PostProjectAnalysisTask.ProjectAnalysis { - @Nullable - private final Organization organization; private final CeTask ceTask; private final Project project; private final long date; @@ -268,10 +256,9 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor private final Analysis analysis; private final String scmRevisionId; - private ProjectAnalysisImpl(@Nullable Organization organization, CeTask ceTask, Project project, + private ProjectAnalysisImpl(CeTask ceTask, Project project, @Nullable Analysis analysis, long date, ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch, String scmRevisionId) { - this.organization = organization; this.ceTask = requireNonNull(ceTask, "ceTask can not be null"); this.project = requireNonNull(project, "project can not be null"); this.analysis = analysis; @@ -284,7 +271,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor @Override public Optional getOrganization() { - return Optional.ofNullable(organization); + return empty(); } @Override @@ -373,24 +360,4 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor return revision; } } - - private static class OrganizationImpl implements Organization { - private final String name; - private final String key; - - private OrganizationImpl(String name, String key) { - this.name = requireNonNull(name, "name can't be null"); - this.key = requireNonNull(key, "key can't be null"); - } - - @Override - public String getName() { - return name; - } - - @Override - public String getKey() { - return key; - } - } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationCheck.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationCheck.java index 8693479050b..d108e3d3f03 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationCheck.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationCheck.java @@ -54,14 +54,5 @@ public interface PostMeasuresComputationCheck { */ int getNcloc(); - /** - * Return the organization - */ - String getOrganizationUuid(); - - /** - * Return the organization - */ - String getOrganizationKey(); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java index 99a90f42422..2cf9bf0d606 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java @@ -86,14 +86,5 @@ public class PostMeasuresComputationChecksStep implements ComputationStep { return nclocMeasure.map(Measure::getIntValue).orElse(0); } - @Override - public String getOrganizationUuid() { - return analysisMetadataHolder.getOrganization().getUuid(); - } - - @Override - public String getOrganizationKey() { - return analysisMetadataHolder.getOrganization().getKey(); - } } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java index 31b13e5d787..d8ddfc74ea2 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java @@ -22,11 +22,9 @@ package org.sonar.ce.task.projectanalysis.step; import java.util.Date; import java.util.Optional; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.sonar.api.utils.MessageException; import org.sonar.ce.task.CeTask; import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder; -import org.sonar.ce.task.projectanalysis.analysis.Organization; import org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin; import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; import org.sonar.ce.task.projectanalysis.component.BranchLoader; @@ -34,13 +32,10 @@ import org.sonar.ce.task.step.ComputationStep; import org.sonar.core.platform.PluginRepository; 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.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin; import org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile; -import org.sonar.server.organization.DefaultOrganizationProvider; -import org.sonar.server.organization.OrganizationFlags; import org.sonar.server.project.Project; import org.sonar.server.qualityprofile.QualityProfile; @@ -55,23 +50,18 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { private final CeTask ceTask; private final BatchReportReader reportReader; private final MutableAnalysisMetadataHolder analysisMetadata; - private final DefaultOrganizationProvider defaultOrganizationProvider; 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, - OrganizationFlags organizationFlags) { + DbClient dbClient, BranchLoader branchLoader, PluginRepository pluginRepository) { this.ceTask = ceTask; this.reportReader = reportReader; this.analysisMetadata = analysisMetadata; - this.defaultOrganizationProvider = defaultOrganizationProvider; this.dbClient = dbClient; this.branchLoader = branchLoader; this.pluginRepository = pluginRepository; - this.organizationFlags = organizationFlags; } @Override @@ -79,8 +69,7 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { ScannerReport.Metadata reportMetadata = reportReader.readMetadata(); loadMetadata(reportMetadata); - Organization organization = loadOrganization(reportMetadata); - Runnable projectValidation = loadProject(reportMetadata, organization); + Runnable projectValidation = loadProject(reportMetadata); loadQualityProfiles(reportMetadata); branchLoader.load(reportMetadata); projectValidation.run(); @@ -97,7 +86,7 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { /** * @return a {@link Runnable} to execute some checks on the project at the end of the step */ - private Runnable loadProject(ScannerReport.Metadata reportMetadata, Organization organization) { + private Runnable loadProject(ScannerReport.Metadata reportMetadata) { CeTask.Component mainComponent = mandatoryComponent(ceTask.getMainComponent()); String mainComponentKey = mainComponent.getKey() .orElseThrow(() -> MessageException.of(format( @@ -119,9 +108,6 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { reportMetadata.getProjectKey(), mainComponentKey)); } - if (!dto.getOrganizationUuid().equals(organization.getUuid())) { - throw MessageException.of(format("Project is not in the expected organization: %s", organization.getKey())); - } }; } @@ -130,16 +116,6 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { .orElseThrow(() -> new IllegalStateException("component missing on ce task")); } - private Organization loadOrganization(ScannerReport.Metadata reportMetadata) { - 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) { analysisMetadata.setQProfilesByLanguage(reportMetadata.getQprofilesPerLanguageMap().values().stream() .collect(toMap( @@ -161,41 +137,6 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { return pluginRepository.getPluginInfo(p.getKey()).getBasePlugin(); } - private void checkOrganizationKeyConsistency(ScannerReport.Metadata reportMetadata, Organization organization) { - String organizationKey = reportMetadata.getOrganizationKey(); - String resolveReportOrganizationKey = resolveReportOrganizationKey(organizationKey); - if (!resolveReportOrganizationKey.equals(organization.getKey())) { - if (reportBelongsToDefaultOrganization(organizationKey)) { - throw MessageException.of(format( - "Report does not specify an OrganizationKey but it has been submitted to another organization (%s) than the default one (%s)", - organization.getKey(), - defaultOrganizationProvider.get().getKey())); - } else { - throw MessageException.of(format( - "OrganizationKey in report (%s) is not consistent with organizationKey under which the report as been submitted (%s)", - resolveReportOrganizationKey, - organization.getKey())); - } - } - } - - private String resolveReportOrganizationKey(@Nullable String organizationKey) { - if (reportBelongsToDefaultOrganization(organizationKey)) { - return defaultOrganizationProvider.get().getKey(); - } - return organizationKey; - } - - private static boolean reportBelongsToDefaultOrganization(@Nullable String organizationKey) { - return organizationKey == null || organizationKey.isEmpty(); - } - - private Organization toOrganization(DbSession dbSession, String organizationUuid) { - Optional organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid); - checkState(organizationDto.isPresent(), "Organization with uuid '%s' can't be found", organizationUuid); - return Organization.from(organizationDto.get()); - } - private ProjectDto toProject(String projectKey) { try (DbSession dbSession = dbClient.openSession(false)) { Optional opt = dbClient.projectDao().selectProjectByKey(dbSession, projectKey); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java index 5903dd122fd..76df35f9e26 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java @@ -49,6 +49,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentUpdateDto; +import org.sonar.server.organization.DefaultOrganizationProvider; import static java.util.Optional.ofNullable; import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; @@ -67,10 +68,11 @@ public class PersistComponentsStep implements ComputationStep { private final AnalysisMetadataHolder analysisMetadataHolder; private final BranchPersister branchPersister; private final ProjectPersister projectPersister; + private final DefaultOrganizationProvider defaultOrganizationProvider; public PersistComponentsStep(DbClient dbClient, TreeRootHolder treeRootHolder, System2 system2, MutableDisabledComponentsHolder disabledComponentsHolder, AnalysisMetadataHolder analysisMetadataHolder, - BranchPersister branchPersister, ProjectPersister projectPersister) { + BranchPersister branchPersister, ProjectPersister projectPersister, DefaultOrganizationProvider defaultOrganizationProvider) { this.dbClient = dbClient; this.treeRootHolder = treeRootHolder; this.system2 = system2; @@ -78,6 +80,7 @@ public class PersistComponentsStep implements ComputationStep { this.analysisMetadataHolder = analysisMetadataHolder; this.branchPersister = branchPersister; this.projectPersister = projectPersister; + this.defaultOrganizationProvider = defaultOrganizationProvider; } @Override @@ -361,7 +364,7 @@ public class PersistComponentsStep implements ComputationStep { String componentUuid = component.getUuid(); ComponentDto componentDto = new ComponentDto(); - componentDto.setOrganizationUuid(analysisMetadataHolder.getOrganization().getUuid()); + componentDto.setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); componentDto.setUuid(componentUuid); componentDto.setDbKey(componentKey); componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java index 1860cec78f4..2436b2573be 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java @@ -45,7 +45,6 @@ public class ReportComputationSteps extends AbstractComputationSteps { // Builds Component tree LoadReportAnalysisMetadataHolderStep.class, ExecuteStatelessInitExtensionsStep.class, - VerifyBillingStep.class, BuildComponentTreeStep.class, ValidateProjectStep.class, diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java deleted file mode 100644 index e653dbe8db2..00000000000 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.ce.task.projectanalysis.step; - -import org.sonar.api.utils.MessageException; -import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; -import org.sonar.ce.task.projectanalysis.analysis.Organization; -import org.sonar.ce.task.step.ComputationStep; -import org.sonar.server.organization.BillingValidations; -import org.sonar.server.organization.BillingValidationsProxy; - -/** - * Verify that organization can execute analysis - */ -public class VerifyBillingStep implements ComputationStep { - - private final AnalysisMetadataHolder analysisMetadata; - private final BillingValidations billingValidations; - - public VerifyBillingStep(AnalysisMetadataHolder analysisMetadata, BillingValidationsProxy billingValidations) { - this.analysisMetadata = analysisMetadata; - this.billingValidations = billingValidations; - } - - @Override - public void execute(ComputationStep.Context context) { - try { - Organization organization = analysisMetadata.getOrganization(); - BillingValidations.Organization billingOrganization = new BillingValidations.Organization(organization.getKey(), organization.getUuid(), organization.getName()); - billingValidations.checkBeforeProjectAnalysis(billingOrganization); - } catch (BillingValidations.BillingValidationsException e) { - throw MessageException.of(e.getMessage()); - } - } - - @Override - public String getDescription() { - return "Verify billing"; - } -} diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java index 8f17bc111fb..54443706600 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java @@ -33,7 +33,6 @@ import org.junit.runner.RunWith; import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; import org.sonar.core.platform.PlatformEditionProvider; import org.sonar.db.component.BranchType; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.project.Project; import static org.assertj.core.api.Assertions.assertThat; @@ -41,57 +40,21 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.core.platform.EditionProvider.Edition; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; @RunWith(DataProviderRunner.class) public class AnalysisMetadataHolderImplTest { - private static Analysis baseProjectAnalysis = new Analysis.Builder() + private static final Analysis baseProjectAnalysis = new Analysis.Builder() .setUuid("uuid_1") .setCreatedAt(123456789L) .build(); - private static long SOME_DATE = 10000000L; + private static final long SOME_DATE = 10000000L; @Rule public ExpectedException expectedException = ExpectedException.none(); - private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); - private AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); - - @Test - public void getOrganization_throws_ISE_if_organization_is_not_set() { - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Organization has not been set"); - - underTest.getOrganization(); - } - - @Test - public void setOrganization_throws_NPE_is_parameter_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Organization can't be null"); - - underTest.setOrganization(null); - } - - @Test - public void setOrganization_throws_ISE_if_called_twice() { - Organization organization = Organization.from(new OrganizationDto().setUuid("uuid").setKey("key").setName("name").setDefaultQualityGateUuid("anyuuidr")); - underTest.setOrganization(organization); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Organization has already been set"); - - underTest.setOrganization(organization); - } - - @Test - public void getUuid_throws_ISE_if_organization_uuid_is_not_set() { - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Analysis uuid has not been set"); - - underTest.getUuid(); - } + private final PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); + private final AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); @Test public void setUuid_throws_NPE_is_parameter_is_null() { @@ -371,7 +334,7 @@ public class AnalysisMetadataHolderImplTest { public void set_and_get_project() { AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); - Project project = Project.from(newPrivateProjectDto(newOrganizationDto())); + Project project = Project.from(newPrivateProjectDto()); underTest.setProject(project); assertThat(underTest.getProject()).isSameAs(project); @@ -388,12 +351,12 @@ public class AnalysisMetadataHolderImplTest { @Test public void setProject_throws_ISE_when_called_twice() { AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); - underTest.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()))); + underTest.setProject(Project.from(newPrivateProjectDto())); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Project has already been set"); - underTest.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()))); + underTest.setProject(Project.from(newPrivateProjectDto())); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/OrganizationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/OrganizationTest.java deleted file mode 100644 index ea63a9812b2..00000000000 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/OrganizationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.ce.task.projectanalysis.analysis; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.db.organization.OrganizationDto; - -import static org.assertj.core.api.Assertions.assertThat; - -public class OrganizationTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private OrganizationDto underTest = new OrganizationDto(); - - @Test - public void build_throws_NPE_if_dto_is_null() { - expectedException.expect(NullPointerException.class); - - Organization.from(null); - } - - @Test - public void build_throws_NPE_if_uuid_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("uuid can't be null"); - - Organization.from(underTest); - } - - @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); - } - - @Test - public void build_throws_NPE_if_defaultQualityGateUuid_is_null() { - underTest.setUuid("uuid").setKey("key").setName("name"); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("defaultQualityGateUuid can't be null"); - - Organization.from(underTest); - } - - @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); - } - - @Test - public void verify_getters() { - 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"); - } - - @Test - public void verify_toString() { - 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'}"); - } - - @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"))); - 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")); - - assertThat(organization.hashCode()).isEqualTo("uuid".hashCode()); - } -} diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java index a30108130da..bcd48d07060 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java @@ -44,7 +44,6 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.ce.task.CeTask; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; import org.sonar.ce.task.projectanalysis.analysis.Branch; -import org.sonar.ce.task.projectanalysis.analysis.Organization; import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.qualitygate.Condition; @@ -54,7 +53,6 @@ import org.sonar.ce.task.projectanalysis.qualitygate.MutableQualityGateStatusHol import org.sonar.ce.task.projectanalysis.qualitygate.QualityGate; import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus; import org.sonar.db.component.BranchType; -import org.sonar.db.organization.OrganizationDto; import org.sonar.scanner.protocol.output.ScannerReport; import static com.google.common.collect.ImmutableList.of; @@ -89,21 +87,17 @@ public class PostProjectAnalysisTasksExecutorTest { @Rule public LogTester logTester = new LogTester(); - private String organizationUuid = "org1"; - private String organizationKey = organizationUuid + "_key"; - private String organizationName = organizationUuid + "_name"; - private System2 system2 = mock(System2.class); - private ArgumentCaptor taskContextCaptor = ArgumentCaptor.forClass(PostProjectAnalysisTask.Context.class); - private CeTask.Component component = new CeTask.Component("component uuid", "component key", "component name"); - private CeTask ceTask = new CeTask.Builder() - .setOrganizationUuid(organizationUuid) + private final System2 system2 = mock(System2.class); + private final ArgumentCaptor taskContextCaptor = ArgumentCaptor.forClass(PostProjectAnalysisTask.Context.class); + private final CeTask.Component component = new CeTask.Component("component uuid", "component key", "component name"); + private final CeTask ceTask = new CeTask.Builder() .setType("type") .setUuid("uuid") .setComponent(component) .setMainComponent(component) .build(); - private PostProjectAnalysisTask postProjectAnalysisTask = newPostProjectAnalysisTask("PT1"); - private PostProjectAnalysisTasksExecutor underTest = new PostProjectAnalysisTasksExecutor( + private final PostProjectAnalysisTask postProjectAnalysisTask = newPostProjectAnalysisTask("PT1"); + private final PostProjectAnalysisTasksExecutor underTest = new PostProjectAnalysisTasksExecutor( ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask}); @@ -117,10 +111,7 @@ public class PostProjectAnalysisTasksExecutorTest { Branch branch = mock(Branch.class); when(branch.getType()).thenReturn(BranchType.BRANCH); analysisMetadataHolder - .setBranch(branch) - .setOrganizationsEnabled(new Random().nextBoolean()) - .setOrganization(Organization.from( - new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"))); + .setBranch(branch); reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build()); } @@ -142,7 +133,7 @@ public class PostProjectAnalysisTasksExecutorTest { new PostProjectAnalysisTasksExecutor( ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2}) - .finished(allStepsExecuted); + .finished(allStepsExecuted); inOrder.verify(postProjectAnalysisTask1).finished(taskContextCaptor.capture()); inOrder.verify(postProjectAnalysisTask1).getDescription(); @@ -165,10 +156,6 @@ public class PostProjectAnalysisTasksExecutorTest { @Test @UseDataProvider("booleanValues") public void organization_is_null_when_organization_are_disabled(boolean allStepsExecuted) { - analysisMetadataHolder - .setOrganizationsEnabled(false) - .setOrganization(Organization.from( - new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"))); underTest.finished(allStepsExecuted); verify(postProjectAnalysisTask).finished(taskContextCaptor.capture()); @@ -176,22 +163,6 @@ public class PostProjectAnalysisTasksExecutorTest { assertThat(taskContextCaptor.getValue().getProjectAnalysis().getOrganization()).isEmpty(); } - @Test - @UseDataProvider("booleanValues") - public void organization_is_not_null_when_organization_are_enabled(boolean allStepsExecuted) { - analysisMetadataHolder - .setOrganizationsEnabled(true) - .setOrganization(Organization.from( - new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo"))); - underTest.finished(allStepsExecuted); - - verify(postProjectAnalysisTask).finished(taskContextCaptor.capture()); - - org.sonar.api.ce.posttask.Organization organization = taskContextCaptor.getValue().getProjectAnalysis().getOrganization().get(); - assertThat(organization.getKey()).isEqualTo(organizationKey); - assertThat(organization.getName()).isEqualTo(organizationName); - } - @Test @UseDataProvider("booleanValues") public void CeTask_status_depends_on_finished_method_argument_is_true_or_false(boolean allStepsExecuted) { @@ -346,7 +317,7 @@ public class PostProjectAnalysisTasksExecutorTest { org.sonar.api.ce.posttask.QualityGate qualityGate = taskContextCaptor.getValue().getProjectAnalysis().getQualityGate(); assertThat(qualityGate.getStatus()).isEqualTo(org.sonar.api.ce.posttask.QualityGate.Status.OK); - assertThat(qualityGate.getId()).isEqualTo(String.valueOf(QUALITY_GATE_UUID)); + assertThat(qualityGate.getId()).isEqualTo(QUALITY_GATE_UUID); assertThat(qualityGate.getName()).isEqualTo(QUALITY_GATE_NAME); assertThat(qualityGate.getConditions()).hasSize(2); } @@ -430,7 +401,7 @@ public class PostProjectAnalysisTasksExecutorTest { new PostProjectAnalysisTasksExecutor( ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2, new PostProjectAnalysisTask[] {logStatisticsTask}) - .finished(allStepsExecuted); + .finished(allStepsExecuted); verify(logStatisticsTask).finished(taskContextCaptor.capture()); @@ -458,7 +429,7 @@ public class PostProjectAnalysisTasksExecutorTest { new PostProjectAnalysisTasksExecutor( ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3}) - .finished(allStepsExecuted); + .finished(allStepsExecuted); inOrder.verify(postProjectAnalysisTask1).finished(taskContextCaptor.capture()); inOrder.verify(postProjectAnalysisTask1).getDescription(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java index 49dad20102f..bb4fe2dcf66 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java @@ -107,11 +107,10 @@ public class BranchPersisterImplTest { String branchName = "branch"; // add project and branch in table PROJECTS - ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey()); + ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setDbKey(MAIN.getKey()); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); - dbTester.getDbClient().componentDao().insert(dbTester.getSession(), mainComponent, component); - dbTester.commit(); + dbTester.components().insertComponents(mainComponent, component); // set project in metadata treeRootHolder.setRoot(BRANCH1); analysisMetadataHolder.setBranch(createBranch(BRANCH, false, branchName, mergeBranchUuid)); @@ -259,11 +258,10 @@ public class BranchPersisterImplTest { String pullRequestId = "pr-123"; // add project and branch in table PROJECTS - ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey()); + ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setDbKey(MAIN.getKey()); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(PULL_REQUEST)); - dbTester.getDbClient().componentDao().insert(dbTester.getSession(), mainComponent, component); - dbTester.commit(); + dbTester.components().insertComponents(mainComponent, component); // set project in metadata treeRootHolder.setRoot(BRANCH1); analysisMetadataHolder.setBranch(createBranch(PULL_REQUEST, false, pullRequestId, "mergeBanchUuid")); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java index ec57e263a87..9d1fe38af24 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java @@ -45,11 +45,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; +import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.PROJECT; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED; -import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; public class ComponentTreeBuilderTest { @@ -70,7 +69,7 @@ public class ComponentTreeBuilderTest { @Rule public ScannerComponentProvider scannerComponentProvider = new ScannerComponentProvider(); - private Project projectInDb = Project.from(newPrivateProjectDto(newOrganizationDto(), UUID_SUPPLIER.apply("K1")).setDbKey("K1").setDescription(null)); + private Project projectInDb = Project.from(newPrivateProjectDto(UUID_SUPPLIER.apply("K1")).setDbKey("K1").setDescription(null)); @Test public void build_throws_IAE_for_all_types_except_PROJECT_and_FILE() { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java index 301d92dbcae..5453eb601d9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java @@ -38,11 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class ConfigurationRepositoryTest { - private static Project PROJECT = Project.from(newPrivateProjectDto(newOrganizationDto())); + private static Project PROJECT = Project.from(newPrivateProjectDto()); @Rule public final DbTester db = DbTester.create(System2.INSTANCE); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java index af89af4648a..c59ee2cd04d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java @@ -78,7 +78,7 @@ public class ProjectPersisterTest { @Test public void update_description() { - ProjectDto p1 = dbTester.components().insertPublicProjectDto(dbTester.getDefaultOrganization(), + ProjectDto p1 = dbTester.components().insertPublicProjectDto( c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")); assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt()); @@ -88,7 +88,7 @@ public class ProjectPersisterTest { @Test public void update_name() { - ProjectDto p1 = dbTester.components().insertPublicProjectDto(dbTester.getDefaultOrganization(), + ProjectDto p1 = dbTester.components().insertPublicProjectDto( c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())); assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt()); @@ -98,7 +98,7 @@ public class ProjectPersisterTest { @Test public void dont_update() { - ProjectDto p1 = dbTester.components().insertPublicProjectDto(dbTester.getDefaultOrganization(), + ProjectDto p1 = dbTester.components().insertPublicProjectDto( c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName(ROOT.getName()).setDescription(ROOT.getDescription())); assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java index 3b288083b51..5cbf8021338 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java @@ -51,7 +51,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.source.FileSourceDto; import static java.util.Arrays.stream; @@ -236,8 +235,7 @@ public class FileMoveDetectionStepTest { @Before public void setUp() throws Exception { - OrganizationDto organization = dbTester.organizations().insert(); - project = dbTester.components().insertPrivateProject(organization); + project = dbTester.components().insertPrivateProject(); treeRootHolder.setRoot(builder(Component.Type.PROJECT, ROOT_REF).setUuid(project.uuid()).build()); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java index 09e165377ff..919f99a6ae4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java @@ -46,7 +46,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.issue.IssueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import static java.util.Collections.emptyList; @@ -75,8 +74,7 @@ public class ComponentIssuesLoaderTest { @Test public void loadClosedIssues_returns_single_DefaultIssue_by_issue_based_on_first_row() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date issueDate = addDays(NOW, -10); @@ -95,8 +93,7 @@ public class ComponentIssuesLoaderTest { @Test public void loadClosedIssues_returns_single_DefaultIssue_with_null_line_if_first_row_has_no_line_diff() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date issueDate = addDays(NOW, -10); @@ -115,8 +112,7 @@ public class ComponentIssuesLoaderTest { @Test public void loadClosedIssues_returns_only_closed_issues_with_close_date() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date issueDate = addDays(NOW, -10); @@ -184,8 +180,7 @@ public class ComponentIssuesLoaderTest { } private void loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago(ComponentIssuesLoader underTest) { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date[] issueDates = new Date[] { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java index 9554769ed3b..ba07f983b6d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java @@ -311,13 +311,13 @@ public class IntegrateIssuesVisitorTest { assertThat(issues.get(0).isNew()).isFalse(); assertThat(issues.get(0).isCopied()).isTrue(); assertThat(issues.get(0).changes()).hasSize(1); - assertThat(issues.get(0).changes().get(0).diffs()).contains(entry(IssueFieldsSetter.FROM_BRANCH, new FieldDiffs.Diff("master",null))); + assertThat(issues.get(0).changes().get(0).diffs()).contains(entry(IssueFieldsSetter.FROM_BRANCH, new FieldDiffs.Diff("master", null))); } private void addBaseIssue(RuleKey ruleKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID).setDbKey(PROJECT_KEY); + ComponentDto project = ComponentTesting.newPrivateProjectDto(PROJECT_UUID).setDbKey(PROJECT_KEY); ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setDbKey(FILE_KEY); - dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, file); + dbTester.components().insertComponents(project, file); RuleDto ruleDto = RuleTesting.newDto(ruleKey); dbTester.rules().insertRule(ruleDto); @@ -332,9 +332,9 @@ public class IntegrateIssuesVisitorTest { } private void addBaseIssueOnBranch(RuleKey ruleKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID_ON_BRANCH).setDbKey(PROJECT_KEY); + ComponentDto project = ComponentTesting.newPrivateProjectDto(PROJECT_UUID_ON_BRANCH).setDbKey(PROJECT_KEY); ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID_ON_BRANCH).setDbKey(FILE_KEY); - dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, file); + dbTester.components().insertComponents(project, file); RuleDto ruleDto = RuleTesting.newDto(ruleKey); dbTester.rules().insertRule(ruleDto); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java index 1204f361642..8402751c39d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java @@ -59,8 +59,6 @@ public class RuleRepositoryImplTest { private static final RuleKey DEPRECATED_KEY_OF_NON_EXITING_RULE = RuleKey.of("some_rep", "some_key"); private static final RuleKey AC_RULE_KEY = RuleKey.of("a", "c"); private static final String AC_RULE_UUID = "uuid-684"; - private static final String ORGANIZATION_UUID = "org-1"; - private static final String QUALITY_GATE_UUID = "QUALITY_GATE_UUID"; @org.junit.Rule public ExpectedException expectedException = ExpectedException.none(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java index 91477dfed95..265151783d9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java @@ -37,8 +37,6 @@ import static org.junit.Assert.fail; public class ScmAccountToUserLoaderTest { - private static final String ORGANIZATION_UUID = "my-organization"; - @Rule public DbTester db = DbTester.create(); @Rule diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java index ee470cf2799..a19423c7d5c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java @@ -56,7 +56,7 @@ public class TrackerReferenceBranchInputFactoryTest { DefaultIssue issue1 = new DefaultIssue(); when(referenceBranchComponentUuids.getComponentUuid(COMPONENT_KEY)).thenReturn(COMPONENT_UUID); when(componentIssuesLoader.loadOpenIssuesWithChanges(COMPONENT_UUID)).thenReturn(Collections.singletonList(issue1)); - ComponentDto fileDto = ComponentTesting.newFileDto(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization())).setUuid(COMPONENT_UUID); + ComponentDto fileDto = ComponentTesting.newFileDto(ComponentTesting.newPublicProjectDto()).setUuid(COMPONENT_UUID); db.fileSources().insertFileSource(fileDto, 3); Component component = mock(Component.class); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java index a43a7a4b006..079fa2bba63 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java @@ -49,7 +49,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.measure.MeasureDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue; @@ -141,8 +140,7 @@ public class MeasureRepositoryImplTest { @Test public void getBaseMeasure_returns_Measure_if_measure_of_last_snapshot_only_in_DB() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); dbTester.components().insertComponent(newFileDto(project).setUuid(FILE_COMPONENT.getUuid())); SnapshotDto lastAnalysis = dbTester.components().insertSnapshot(project, t -> t.setLast(true)); SnapshotDto oldAnalysis = dbTester.components().insertSnapshot(project, t -> t.setLast(false)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java index dee477693ab..10bc7d8ba0a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java @@ -43,7 +43,6 @@ import static org.mockito.Mockito.verify; import static org.sonar.api.measures.CoreMetrics.NCLOC; import static org.sonar.ce.task.projectanalysis.component.ReportComponent.DUMB_PROJECT; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class PostMeasuresComputationChecksStepTest { @@ -72,7 +71,7 @@ public class PostMeasuresComputationChecksStepTest { @Test public void context_contains_project_uuid_from_analysis_metada_holder() { - Project project = Project.from(newPrivateProjectDto(newOrganizationDto())); + Project project = Project.from(newPrivateProjectDto()); analysisMetadataHolder.setProject(project); PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java index 4a4cf3db828..b06d04efca2 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java @@ -43,7 +43,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; import org.sonar.scanner.protocol.output.ScannerReport.Component.FileStatus; @@ -59,7 +58,6 @@ import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.SnapshotTesting.newAnalysis; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.PROJECT; @@ -233,8 +231,7 @@ public class BuildComponentTreeStepTest { @Test public void return_existing_uuids() { setAnalysisMetadataHolder(); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); ComponentDto directory = newDirectory(project, "CDEF", REPORT_DIR_PATH_1); insertComponent(directory.setDbKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1)); insertComponent(newFileDto(project, directory, "DEFG") @@ -260,7 +257,7 @@ public class BuildComponentTreeStepTest { when(branch.generateKey(any(), any())).thenReturn("generated"); analysisMetadataHolder.setRootComponentRef(ROOT_REF) .setAnalysisDate(ANALYSIS_DATE) - .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY))) + .setProject(Project.from(newPrivateProjectDto().setDbKey(REPORT_PROJECT_KEY))) .setBranch(branch); BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF)); @@ -349,8 +346,7 @@ public class BuildComponentTreeStepTest { @Test public void set_no_base_project_snapshot_when_no_last_snapshot() { setAnalysisMetadataHolder(); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setLast(false)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -362,8 +358,7 @@ public class BuildComponentTreeStepTest { @Test public void set_base_project_snapshot_when_last_snapshot_exist() { setAnalysisMetadataHolder(); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setLast(true)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -386,8 +381,7 @@ public class BuildComponentTreeStepTest { @UseDataProvider("oneParameterNullNonNullCombinations") public void set_projectVersion_to_previous_analysis_when_not_set(@Nullable String previousAnalysisProjectVersion) { setAnalysisMetadataHolder(); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -420,8 +414,7 @@ public class BuildComponentTreeStepTest { String scannerProjectVersion = randomAlphabetic(12); setAnalysisMetadataHolder(); reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING)); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -559,9 +552,7 @@ public class BuildComponentTreeStepTest { } private ComponentDto insertComponent(ComponentDto component) { - dbClient.componentDao().insert(dbTester.getSession(), component); - dbTester.getSession().commit(); - return component; + return dbTester.components().insertComponent(component); } private SnapshotDto insertSnapshot(SnapshotDto snapshot) { @@ -579,7 +570,7 @@ public class BuildComponentTreeStepTest { analysisMetadataHolder.setRootComponentRef(ROOT_REF) .setAnalysisDate(ANALYSIS_DATE) .setBranch(branch) - .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY).setName(REPORT_PROJECT_KEY))); + .setProject(Project.from(newPrivateProjectDto().setDbKey(REPORT_PROJECT_KEY).setName(REPORT_PROJECT_KEY))); } public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String buildString) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java index d9ee40eef6a..da7e8401ccb 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java @@ -33,7 +33,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotTesting; -import org.sonar.db.organization.OrganizationDto; import static org.assertj.core.api.Assertions.assertThat; @@ -56,9 +55,8 @@ public class EnableAnalysisStepTest { @Test public void switch_islast_flag_and_mark_analysis_as_processed() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = ComponentTesting.newPrivateProjectDto(organization, REPORT_PROJECT.getUuid()); - db.getDbClient().componentDao().insert(db.getSession(), project); + ComponentDto project = ComponentTesting.newPrivateProjectDto(REPORT_PROJECT.getUuid()); + db.components().insertComponent(project); insertAnalysis(project, PREVIOUS_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, true); insertAnalysis(project, CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_UNPROCESSED, false); db.commit(); @@ -73,8 +71,8 @@ public class EnableAnalysisStepTest { @Test public void set_islast_flag_and_mark_as_processed_if_no_previous_analysis() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), REPORT_PROJECT.getUuid()); - db.getDbClient().componentDao().insert(db.getSession(), project); + ComponentDto project = ComponentTesting.newPrivateProjectDto(REPORT_PROJECT.getUuid()); + db.components().insertComponent(project); insertAnalysis(project, CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_UNPROCESSED, false); db.commit(); treeRootHolder.setRoot(REPORT_PROJECT); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java index 2948c939a4b..5e6086c0031 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java @@ -59,7 +59,6 @@ public class ExtractReportStepTest { private MutableBatchReportDirectoryHolder reportDirectoryHolder = new BatchReportDirectoryHolderImpl(); private CeTask ceTask = new CeTask.Builder() - .setOrganizationUuid("org1") .setType(CeTaskTypes.REPORT) .setUuid(TASK_UUID) .build(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java index 22edc104968..84c3b23bd83 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java @@ -106,8 +106,8 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { @Before public void setUp() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()); - dbClient.componentDao().insert(dbSession, project); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); + dbTester.components().insertComponent(project); SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project); dbClient.snapshotDao().insert(dbSession, projectSnapshot); dbSession.commit(); @@ -323,10 +323,8 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { } private ComponentDto createProject(String projectKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()).setDbKey(projectKey); - dbClient.componentDao().insert(dbSession, project); - dbSession.commit(); - return project; + ComponentDto project = ComponentTesting.newPrivateProjectDto().setDbKey(projectKey); + return dbTester.components().insertComponent(project); } private SnapshotDto createProjectSnapshot(ComponentDto project) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java index 56ec2a33de2..87d69673d46 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java @@ -56,7 +56,6 @@ import org.sonar.db.component.SnapshotDto; import org.sonar.db.event.EventTesting; import org.sonar.db.newcodeperiod.NewCodePeriodDao; import org.sonar.db.newcodeperiod.NewCodePeriodType; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.project.Project; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; @@ -92,7 +91,6 @@ public class LoadPeriodsStepTest extends BaseStepTest { private LoadPeriodsStep underTest = new LoadPeriodsStep(analysisMetadataHolder, dao, treeRootHolder, periodsHolder, dbTester.getDbClient(), newCodePeriodResolver); - private OrganizationDto organization; private ComponentDto project; @Override @@ -102,8 +100,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { @Before public void setUp() { - organization = dbTester.organizations().insert(); - project = dbTester.components().insertPublicProject(organization); + project = dbTester.components().insertPublicProject(); when(analysisMetadataHolder.isBranch()).thenReturn(true); when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); @@ -267,8 +264,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { @Test public void throw_ISE_when_specific_analysis_is_set_but_does_not_exist_in_DB() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPublicProject(organization); + ComponentDto project = dbTester.components().insertPublicProject(); setProjectPeriod(project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "nonexistent"); setupRoot(project); @@ -280,7 +276,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { @Test public void throw_ISE_when_specific_analysis_is_set_but_does_not_belong_to_current_project() { - ComponentDto otherProject = dbTester.components().insertPublicProject(organization); + ComponentDto otherProject = dbTester.components().insertPublicProject(); SnapshotDto otherProjectAnalysis = dbTester.components().insertSnapshot(otherProject); setBranchPeriod(project.uuid(), project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, otherProjectAnalysis.getUuid()); setupRoot(project); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java index 2b399921f9d..7569aba3674 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java @@ -26,7 +26,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; -import org.sonar.ce.task.projectanalysis.analysis.Organization; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricImpl; import org.sonar.ce.task.projectanalysis.qualitygate.Condition; @@ -56,7 +55,6 @@ public class LoadQualityGateStepTest { @Before public void setUp() { - when(analysisMetadataHolder.getOrganization()).thenReturn(mock(Organization.class)); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java index 8c4ebcc864f..15442de8641 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java @@ -19,9 +19,7 @@ */ package org.sonar.ce.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 java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -37,7 +35,6 @@ import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.ce.task.CeTask; import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule; -import org.sonar.ce.task.projectanalysis.analysis.Organization; import org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin; import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule; import org.sonar.ce.task.projectanalysis.component.BranchLoader; @@ -48,17 +45,12 @@ import org.sonar.core.platform.PluginRepository; 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.scanner.protocol.output.ScannerReport; -import org.sonar.server.organization.DefaultOrganizationProvider; -import org.sonar.server.organization.OrganizationFlags; -import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.project.Project; import static java.util.Arrays.stream; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -77,18 +69,16 @@ public class LoadReportAnalysisMetadataHolderStepTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private DbClient dbClient = db.getDbClient(); - private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); - private TestPluginRepository pluginRepository = new TestPluginRepository(); - private OrganizationFlags organizationFlags = mock(OrganizationFlags.class); + private final DbClient dbClient = db.getDbClient(); + private final TestPluginRepository pluginRepository = new TestPluginRepository(); private ComponentDto project; private ComputationStep underTest; @Before public void setUp() { - CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY, db.getDefaultOrganization().getUuid()); + CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY); underTest = createStep(defaultOrgCeTask); - project = db.components().insertPublicProject(db.getDefaultOrganization(), p -> p.setDbKey(PROJECT_KEY)); + project = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY)); } @Test @@ -182,7 +172,6 @@ public class LoadReportAnalysisMetadataHolderStepTest { public void execute_fails_with_ISE_if_component_is_null_in_CE_task() { CeTask res = mock(CeTask.class); when(res.getComponent()).thenReturn(Optional.empty()); - when(res.getOrganizationUuid()).thenReturn(defaultOrganizationProvider.get().getUuid()); reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build()); ComputationStep underTest = createStep(res); @@ -199,7 +188,6 @@ public class LoadReportAnalysisMetadataHolderStepTest { Optional component = Optional.of(new CeTask.Component("main_prj_uuid", null, null)); when(res.getComponent()).thenReturn(component); when(res.getMainComponent()).thenReturn(component); - when(res.getOrganizationUuid()).thenReturn(defaultOrganizationProvider.get().getUuid()); reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build()); ComputationStep underTest = createStep(res); @@ -217,7 +205,6 @@ public class LoadReportAnalysisMetadataHolderStepTest { Optional component = Optional.of(new CeTask.Component("prj_uuid", null, null)); when(res.getComponent()).thenReturn(component); when(res.getMainComponent()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null))); - when(res.getOrganizationUuid()).thenReturn(defaultOrganizationProvider.get().getUuid()); reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build()); ComputationStep underTest = createStep(res); @@ -230,8 +217,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { @Test public void execute_fails_with_MessageException_when_projectKey_in_report_is_different_from_componentKey_in_CE_task() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto otherProject = db.components().insertPublicProject(organization); + ComponentDto otherProject = db.components().insertPublicProject(); reportReader.setMetadata( ScannerReport.Metadata.newBuilder() .setProjectKey(otherProject.getDbKey()) @@ -246,8 +232,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { @Test public void execute_sets_branch_even_if_MessageException_is_thrown_because_projectKey_in_report_is_different_from_componentKey_in_CE_task() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto otherProject = db.components().insertPublicProject(organization); + ComponentDto otherProject = db.components().insertPublicProject(); reportReader.setMetadata( ScannerReport.Metadata.newBuilder() .setProjectKey(otherProject.getDbKey()) @@ -262,8 +247,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { @Test public void execute_sets_analysis_date_even_if_MessageException_is_thrown_because_projectKey_is_different_from_componentKey_in_CE_task() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto otherProject = db.components().insertPublicProject(organization); + ComponentDto otherProject = db.components().insertPublicProject(); reportReader.setMetadata( ScannerReport.Metadata.newBuilder() .setProjectKey(otherProject.getDbKey()) @@ -277,99 +261,16 @@ public class LoadReportAnalysisMetadataHolderStepTest { } } - @Test - public void execute_fails_with_MessageException_when_report_has_no_organizationKey_but_does_not_belong_to_the_default_organization() { - reportReader.setMetadata( - newBatchReportBuilder() - .build()); - OrganizationDto nonDefaultOrganizationDto = db.organizations().insert(); - - ComputationStep underTest = createStep(createCeTask(PROJECT_KEY, nonDefaultOrganizationDto.getUuid())); - - expectedException.expect(MessageException.class); - expectedException.expectMessage("Report does not specify an OrganizationKey but it has been submitted to another organization (" + - nonDefaultOrganizationDto.getKey() + ") than the default one (" + db.getDefaultOrganization().getKey() + ")"); - - underTest.execute(new TestComputationStepContext()); - } - - @Test - public void execute_set_organization_from_ce_task_when_organizationKey_is_not_set_in_report() { - reportReader.setMetadata( - newBatchReportBuilder() - .build()); - - underTest.execute(new TestComputationStepContext()); - - Organization organization = analysisMetadataHolder.getOrganization(); - OrganizationDto defaultOrganization = db.getDefaultOrganization(); - assertThat(organization.getUuid()).isEqualTo(defaultOrganization.getUuid()); - assertThat(organization.getKey()).isEqualTo(defaultOrganization.getKey()); - assertThat(organization.getName()).isEqualTo(defaultOrganization.getName()); - } - - @Test - @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()); - when(organizationFlags.isEnabled(any())).thenReturn(organizationEnabled); - - underTest.execute(new TestComputationStepContext()); - - Organization organization = analysisMetadataHolder.getOrganization(); - OrganizationDto defaultOrganization = db.getDefaultOrganization(); - assertThat(organization.getUuid()).isEqualTo(defaultOrganization.getUuid()); - assertThat(organization.getKey()).isEqualTo(defaultOrganization.getKey()); - assertThat(organization.getName()).isEqualTo(defaultOrganization.getName()); - assertThat(analysisMetadataHolder.isOrganizationsEnabled()).isEqualTo(organizationEnabled); - } - - @Test - @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( - newBatchReportBuilder() - .setOrganizationKey(nonDefaultOrganizationDto.getKey()) - .setProjectKey(project.getDbKey()) - .build()); - when(organizationFlags.isEnabled(any())).thenReturn(organizationEnabled); - - ComputationStep underTest = createStep(createCeTask(project.getDbKey(), nonDefaultOrganizationDto.getUuid())); - - underTest.execute(new TestComputationStepContext()); - - Organization organization = analysisMetadataHolder.getOrganization(); - assertThat(organization.getUuid()).isEqualTo(nonDefaultOrganizationDto.getUuid()); - assertThat(organization.getKey()).isEqualTo(nonDefaultOrganizationDto.getKey()); - assertThat(organization.getName()).isEqualTo(nonDefaultOrganizationDto.getName()); - assertThat(analysisMetadataHolder.isOrganizationsEnabled()).isEqualTo(organizationEnabled); - } - - @DataProvider - public static Object[][] organizationEnabledFlags() { - return new Object[][] { - {true}, - {false} - }; - } - @Test public void execute_does_not_fail_when_report_has_a_quality_profile_that_does_not_exist_anymore() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); ScannerReport.Metadata.Builder metadataBuilder = newBatchReportBuilder(); metadataBuilder - .setOrganizationKey(organization.getKey()) .setProjectKey(project.getDbKey()); metadataBuilder.putQprofilesPerLanguage("js", ScannerReport.Metadata.QProfile.newBuilder().setKey("p1").setName("Sonar way").setLanguage("js").build()); reportReader.setMetadata(metadataBuilder.build()); - ComputationStep underTest = createStep(createCeTask(project.getDbKey(), organization.getUuid())); + ComputationStep underTest = createStep(createCeTask(project.getDbKey())); underTest.execute(new TestComputationStepContext()); } @@ -402,7 +303,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { private LoadReportAnalysisMetadataHolderStep createStep(CeTask ceTask) { return new LoadReportAnalysisMetadataHolderStep(ceTask, reportReader, analysisMetadataHolder, - defaultOrganizationProvider, dbClient, new BranchLoader(analysisMetadataHolder), pluginRepository, organizationFlags); + dbClient, new BranchLoader(analysisMetadataHolder), pluginRepository); } private static ScannerReport.Metadata.Builder newBatchReportBuilder() { @@ -410,10 +311,9 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setProjectKey(PROJECT_KEY); } - private CeTask createCeTask(String projectKey, String organizationUuid) { + private CeTask createCeTask(String projectKey) { CeTask res = mock(CeTask.class); Optional component = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name")); - when(res.getOrganizationUuid()).thenReturn(organizationUuid); when(res.getComponent()).thenReturn(component); when(res.getMainComponent()).thenReturn(component); return res; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java index af5bdc76943..944319e7ab3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDao; +import org.sonar.server.organization.DefaultOrganizationProvider; import static java.util.Collections.emptyList; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; @@ -69,6 +70,7 @@ public class PersistComponentsStepTest { mock(MutableDisabledComponentsHolder.class), mock(AnalysisMetadataHolder.class), mock(BranchPersister.class), - mock(ProjectPersister.class)).execute(new TestComputationStepContext()); + mock(ProjectPersister.class), + mock(DefaultOrganizationProvider.class)).execute(new TestComputationStepContext()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java index 655e7f6d217..410e20948d2 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java @@ -175,13 +175,12 @@ public class PersistDuplicationDataStepTest extends BaseStepTest { private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() - .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); - db.getDbClient().componentDao().insert(db.getSession(), componentDto); + db.components().insertComponent(componentDto); return componentDto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java index fb6d7c5fcaa..e6f876ae6a5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java @@ -51,7 +51,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueMapper; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleTesting; import org.sonar.scanner.protocol.output.ScannerReport; @@ -114,8 +113,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void insert_copied_issue() { RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); when(system2.now()).thenReturn(NOW); @@ -174,8 +172,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void insert_copied_issue_with_minimal_info() { RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); when(system2.now()).thenReturn(NOW); @@ -218,8 +215,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void insert_merged_issue() { RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); when(system2.now()).thenReturn(NOW); @@ -275,8 +271,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void update_conflicting_issue() { RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN) @@ -310,8 +305,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void insert_new_issue() { RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); session.commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java index 1a4d2716938..b0ed74a1f1a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java @@ -277,13 +277,12 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() - .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); - dbClient.componentDao().insert(db.getSession(), componentDto); + db.components().insertComponent(componentDto); return componentDto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java index 9ffa01abcad..ba8af03b04b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java @@ -223,13 +223,12 @@ public class PersistMeasuresStepTest extends BaseStepTest { private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() - .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); - dbClient.componentDao().insert(db.getSession(), componentDto); + db.components().insertComponent(componentDto); return componentDto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java index bbf7cc39fdc..1ff2d794c11 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java @@ -41,7 +41,6 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotQuery; import org.sonar.db.component.SnapshotTesting; -import org.sonar.db.organization.OrganizationDto; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; @@ -94,15 +93,14 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_analysis() { String projectVersion = randomAlphabetic(10); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); - dbClient.componentDao().insert(dbTester.getSession(), projectDto); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + dbTester.components().insertComponent(projectDto); ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module"); - dbClient.componentDao().insert(dbTester.getSession(), moduleDto); + dbTester.components().insertComponent(moduleDto); ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir"); - dbClient.componentDao().insert(dbTester.getSession(), directoryDto); + dbTester.components().insertComponent(directoryDto); ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java"); - dbClient.componentDao().insert(dbTester.getSession(), fileDto); + dbTester.components().insertComponent(fileDto); dbTester.getSession().commit(); Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build(); @@ -136,9 +134,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_snapshots_with_new_code_period() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); - dbClient.componentDao().insert(dbTester.getSession(), projectDto); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + dbTester.components().insertComponent(projectDto); SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime()); dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); dbTester.getSession().commit(); @@ -159,20 +156,19 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { public void only_persist_snapshots_with_new_code_period_on_project_and_module() { periodsHolder.setPeriod(new Period("PREVIOUS_VERSION", null, analysisDate)); - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); - dbClient.componentDao().insert(dbTester.getSession(), projectDto); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + dbTester.components().insertComponent(projectDto); SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto); dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot); ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module"); - dbClient.componentDao().insert(dbTester.getSession(), moduleDto); + dbTester.components().insertComponent(moduleDto); ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir"); - dbClient.componentDao().insert(dbTester.getSession(), directoryDto); + dbTester.components().insertComponent(directoryDto); ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java"); - dbClient.componentDao().insert(dbTester.getSession(), fileDto); + dbTester.components().insertComponent(fileDto); dbTester.getSession().commit(); @@ -189,8 +185,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void set_no_period_on_snapshots_when_no_period() { - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY).setName("Project"); - dbClient.componentDao().insert(dbTester.getSession(), projectDto); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + dbTester.components().insertComponent(projectDto); SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto); dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); dbTester.getSession().commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java index da466c1f677..4714275e015 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java @@ -48,6 +48,8 @@ import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; +import org.sonar.server.organization.DefaultOrganizationProvider; +import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.project.Project; import static org.apache.commons.lang.StringUtils.isEmpty; @@ -69,21 +71,19 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); private static final String PROJECT_KEY = "PROJECT_KEY"; - private static final String ORGANIZATION_UUID = "org1"; - private static final String QUALITY_GATE_UUID = "gg1"; @Rule public DbTester db = DbTester.create(System2.INSTANCE); + public DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); @Rule - public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule() - .setOrganizationUuid(ORGANIZATION_UUID, QUALITY_GATE_UUID); + public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); - private System2 system2 = mock(System2.class); - private DbClient dbClient = db.getDbClient(); + private final System2 system2 = mock(System2.class); + private final DbClient dbClient = db.getDbClient(); private Date now; - private MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS); + private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS); private PersistComponentsStep underTest; @Before @@ -91,10 +91,10 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { now = DATE_FORMAT.parse("2015-06-02"); when(system2.now()).thenReturn(now.getTime()); - db.organizations().insertForUuid(ORGANIZATION_UUID); BranchPersister branchPersister = mock(BranchPersister.class); ProjectPersister projectPersister = mock(ProjectPersister.class); - underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister); + underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister, + defaultOrganizationProvider); } @Override @@ -125,7 +125,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(db.countRowsOfTable("components")).isEqualTo(3); ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); - assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(directoryDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(directoryDto.name()).isEqualTo("dir"); assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); assertThat(directoryDto.description()).isNull(); @@ -142,7 +142,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directoryDto.getCreatedAt()).isEqualTo(now); ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); - assertThat(fileDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(fileDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(fileDto.name()).isEqualTo("Foo.java"); assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); assertThat(fileDto.description()).isNull(); @@ -184,7 +184,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(db.countRowsOfTable("components")).isEqualTo(3); ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); - assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(directoryDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(directoryDto.name()).isEqualTo("dir"); assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); assertThat(directoryDto.description()).isNull(); @@ -201,7 +201,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directoryDto.getCreatedAt()).isEqualTo(now); ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); - assertThat(fileDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(fileDto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(fileDto.name()).isEqualTo("Foo.java"); assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); assertThat(fileDto.description()).isNull(); @@ -631,7 +631,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { } private ComponentDto prepareProject(Consumer populators) { - ComponentDto dto = db.components().insertPrivateProject(db.organizations().insert(), populators); + ComponentDto dto = db.components().insertPrivateProject(populators); analysisMetadataHolder.setProject(Project.from(dto)); analysisMetadataHolder.setBranch(new DefaultBranchImpl()); return dto; @@ -642,7 +642,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { } private ComponentDto prepareBranch(String branchName, Consumer populators) { - ComponentDto dto = db.components().insertPrivateProject(db.organizations().insert(), populators); + ComponentDto dto = db.components().insertPrivateProject(populators); analysisMetadataHolder.setProject(Project.from(dto)); analysisMetadataHolder.setBranch(new TestBranch(branchName)); return dto; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java index 49a094beb53..60b171b3d2e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -105,7 +105,6 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.ComponentTesting.newBranchComponent; import static org.sonar.db.issue.IssueTesting.newIssue; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.db.rule.RuleTesting.newRule; public class SendIssueNotificationsStepTest extends BaseStepTest { @@ -252,7 +251,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void send_global_new_issues_notification_on_branch() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto branch = setUpBranch(project, BRANCH); protoIssueCache.newAppender().append( createIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); @@ -273,7 +272,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void do_not_send_global_new_issues_notification_on_pull_request() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto branch = setUpBranch(project, PULL_REQUEST); protoIssueCache.newAppender().append( createIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); @@ -294,7 +293,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void do_not_send_global_new_issues_notification_on_branch_if_issue_has_been_backdated() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto branch = setUpBranch(project, BRANCH); protoIssueCache.newAppender().append( createIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close(); @@ -498,7 +497,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void do_not_send_new_issues_notifications_for_hotspot() { UserDto user = db.users().insertUser(); - ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); + ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); RuleDefinitionDto ruleDefinitionDto = newRule(); prepareIssue(ANALYSE_DATE, user, project, file, ruleDefinitionDto, RuleType.SECURITY_HOTSPOT); @@ -520,7 +519,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { private void sendIssueChangeNotification(long issueCreatedAt) { UserDto user = db.users().insertUser(); - ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); + ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); analysisMetadataHolder.setProject(Project.from(project)); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(project.getDbKey()).setPublicKey(project.getKey()).setName(project.longName()).setUuid(project.uuid()) @@ -566,7 +565,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { } private void sendIssueChangeNotificationOnBranch(long issueCreatedAt) { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto branch = newBranchComponent(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto file = newFileDto(branch); treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( @@ -600,7 +599,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void sends_one_issue_change_notification_every_1000_issues() { UserDto user = db.users().insertUser(); - ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); + ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); RuleDefinitionDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java index 0a35b16968e..24ae48eefe1 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java @@ -92,8 +92,8 @@ public class ValidateProjectStepTest { @Test public void not_fail_if_analysis_date_is_after_last_analysis() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY); - dbClient.componentDao().insert(db.getSession(), project); + ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY); + db.components().insertComponent(project); dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(PAST_ANALYSIS_TIME)); db.getSession().commit(); @@ -123,8 +123,8 @@ public class ValidateProjectStepTest { public void fail_if_analysis_date_is_before_last_analysis() { analysisMetadataHolder.setAnalysisDate(DateUtils.parseDate("2015-01-01")); - ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY); - dbClient.componentDao().insert(db.getSession(), project); + ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY); + db.components().insertComponent(project); dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1433131200000L)); // 2015-06-01 db.getSession().commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java deleted file mode 100644 index ece51e37b1a..00000000000 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.ce.task.projectanalysis.step; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.ArgumentCaptor; -import org.sonar.api.utils.MessageException; -import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule; -import org.sonar.ce.task.projectanalysis.analysis.Organization; -import org.sonar.ce.task.step.TestComputationStepContext; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.server.organization.BillingValidations; -import org.sonar.server.organization.BillingValidations.BillingValidationsException; -import org.sonar.server.organization.BillingValidationsProxy; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; - -public class VerifyBillingStepTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private OrganizationDto organization = newOrganizationDto(); - @Rule - public MutableAnalysisMetadataHolderRule analysisMetadata = new MutableAnalysisMetadataHolderRule() - .setOrganization(Organization.from(organization)); - - private BillingValidationsProxy validations = mock(BillingValidationsProxy.class); - - @Test - public void execute_fails_with_MessageException_when_organization_is_not_allowed_to_execute_analysis() { - doThrow(new BillingValidationsException("This organization cannot execute project analysis")) - .when(validations) - .checkBeforeProjectAnalysis(any(BillingValidations.Organization.class)); - - VerifyBillingStep underTest = new VerifyBillingStep(analysisMetadata, validations); - - expectedException.expect(MessageException.class); - expectedException.expectMessage("This organization cannot execute project analysis"); - - underTest.execute(new TestComputationStepContext()); - - } - - @Test - public void execute_does_no_fail_when_organization_is_allowed_to_execute_analysis() { - ArgumentCaptor orgCaptor = ArgumentCaptor.forClass(BillingValidations.Organization.class); - VerifyBillingStep underTest = new VerifyBillingStep(analysisMetadata, validations); - - underTest.execute(new TestComputationStepContext()); - - verify(validations).checkBeforeProjectAnalysis(orgCaptor.capture()); - BillingValidations.Organization calledOrg = orgCaptor.getValue(); - assertThat(calledOrg.getKey()).isEqualTo(organization.getKey()); - assertThat(calledOrg.getUuid()).isEqualTo(organization.getUuid()); - assertThat(calledOrg.getName()).isEqualTo(organization.getName()); - } - -} diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java index 99920946328..7273e307a16 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java @@ -38,7 +38,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotQuery; -import org.sonar.db.organization.OrganizationDto; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -92,10 +91,9 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_analysis() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setDbKey("KEY_VIEW")); + ComponentDto viewDto = save(newView("UUID_VIEW").setDbKey("KEY_VIEW")); save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); - save(newPrivateProjectDto(organizationDto, "proj")); + save(newPrivateProjectDto("proj")); dbTester.getSession().commit(); Component projectView = ViewsComponent.builder(PROJECT_VIEW, "KEY_PROJECT_COPY").setUuid("UUID_PROJECT_COPY").build(); @@ -119,8 +117,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_snapshots_with_new_code_period() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setDbKey("KEY_VIEW")); + ComponentDto viewDto = save(newView("UUID_VIEW").setDbKey("KEY_VIEW")); ComponentDto subViewDto = save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); dbTester.getSession().commit(); @@ -139,8 +136,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { } private ComponentDto save(ComponentDto componentDto) { - dbClient.componentDao().insert(dbTester.getSession(), componentDto); - return componentDto; + return dbTester.components().insertComponent(componentDto); } private SnapshotDto getUnprocessedSnapshot(String componentUuid) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java index 514531a2ccd..ed4377c5109 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java @@ -48,7 +48,8 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; +import org.sonar.server.organization.DefaultOrganizationProvider; +import org.sonar.server.organization.TestDefaultOrganizationProvider; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -76,22 +77,22 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { private static final String PROJECT_VIEW_1_KEY = "PV1_KEY"; private static final String PROJECT_VIEW_1_NAME = "PV1_NAME"; private static final String PROJECT_VIEW_1_UUID = "PV1_UUID"; - private static final String ORGANIZATION_UUID = "org1"; - private static final String QUALITY_GATE_UUID = "qg1"; @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); + + public DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester); + @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); @Rule - public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule() - .setOrganizationUuid(ORGANIZATION_UUID, QUALITY_GATE_UUID); + public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); - private System2 system2 = mock(System2.class); - private DbClient dbClient = dbTester.getDbClient(); + private final System2 system2 = mock(System2.class); + private final DbClient dbClient = dbTester.getDbClient(); private Date now; - private ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); - private MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS); + private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); + private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS); private PersistComponentsStep underTest; @Before @@ -102,7 +103,8 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { analysisMetadataHolder.setBranch(new DefaultBranchImpl()); BranchPersister branchPersister = mock(BranchPersister.class); ProjectPersister projectPersister = mock(ProjectPersister.class); - underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister); + underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister, + defaultOrganizationProvider); } @Override @@ -125,7 +127,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persist_existing_empty_view() { // most of the time view already exists since its supposed to be created when config is uploaded - persistComponents(newViewDto(dbTester.organizations().insert())); + persistComponents(newViewDto()); treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build()); @@ -138,7 +140,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persist_view_with_projectView() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); persistComponents(project); treeRootHolder.setRoot( @@ -159,7 +161,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persist_application_with_projectView() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); persistComponents(project); treeRootHolder.setRoot( @@ -215,7 +217,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persist_existing_empty_subview_under_existing_view() { - ComponentDto viewDto = newViewDto(dbTester.organizations().insert()); + ComponentDto viewDto = newViewDto(); persistComponents(viewDto); persistComponents(ComponentTesting.newSubView(viewDto, SUBVIEW_1_UUID, SUBVIEW_1_KEY).setName(SUBVIEW_1_NAME)); @@ -235,7 +237,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persist_empty_subview_under_existing_view() { - persistComponents(newViewDto(dbTester.organizations().insert())); + persistComponents(newViewDto()); treeRootHolder.setRoot( createViewBuilder(PORTFOLIO) @@ -253,7 +255,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persist_project_view_under_subview() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); persistComponents(project); treeRootHolder.setRoot( @@ -279,7 +281,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void update_view_name_and_longName() { - ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now); + ComponentDto viewDto = newViewDto().setLongName("another long name").setCreatedAt(now); persistComponents(viewDto); treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build()); @@ -297,12 +299,10 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void update_project_view() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto view = newViewDto(organizationDto); - ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto); + ComponentDto view = newViewDto(); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); persistComponents(view, project); ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view) - .setOrganizationUuid(ORGANIZATION_UUID) .setDbKey(PROJECT_VIEW_1_KEY) .setName("Old name") .setCreatedAt(now); @@ -326,10 +326,9 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void update_copy_component_uuid_of_project_view() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto view = newViewDto(organizationDto); - ComponentDto project1 = newPrivateProjectDto(organizationDto, "P1"); - ComponentDto project2 = newPrivateProjectDto(organizationDto, "P2"); + ComponentDto view = newViewDto(); + ComponentDto project1 = newPrivateProjectDto("P1"); + ComponentDto project2 = newPrivateProjectDto("P2"); persistComponents(view, project1, project2); // Project view in DB is associated to project1 @@ -357,8 +356,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void update_copy_component_uuid_of_sub_view() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - ComponentDto view = newViewDto(organizationDto); + ComponentDto view = newViewDto(); ComponentDto subView = newSubViewDto(view).setCopyComponentUuid("OLD_COPY"); persistComponents(view, subView); @@ -400,8 +398,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() { boolean isRootPrivate = new Random().nextBoolean(); ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); + ComponentDto view = newViewDto().setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); dbTester.components().insertComponent(view); treeRootHolder.setRoot( createViewBuilder(PORTFOLIO) @@ -424,8 +421,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() { boolean isRootPrivate = new Random().nextBoolean(); ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); + ComponentDto view = newViewDto().setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); dbTester.components().insertComponent(view); ComponentDto subView = newSubView(view).setUuid("BCDE").setDbKey("MODULE").setPrivate(!isRootPrivate); dbTester.components().insertComponent(subView); @@ -487,9 +483,9 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { assertThat(getComponentFromDb(componentKey).getCreatedAt()).isNotEqualTo(now); } - private ComponentDto newViewDto(OrganizationDto organizationDto) { - return ComponentTesting.newView(organizationDto, VIEW_UUID) - .setOrganizationUuid(ORGANIZATION_UUID) + private ComponentDto newViewDto() { + return ComponentTesting.newView(VIEW_UUID) + .setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) .setDbKey(VIEW_KEY) .setName(VIEW_NAME); } @@ -503,7 +499,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} */ private void assertDtoIsView(ComponentDto dto) { - assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(dto.name()).isEqualTo(VIEW_NAME); assertThat(dto.longName()).isEqualTo(VIEW_NAME); assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); @@ -523,7 +519,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()} */ private void assertDtoIsApplication(ComponentDto dto) { - assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(dto.name()).isEqualTo(VIEW_NAME); assertThat(dto.longName()).isEqualTo(VIEW_NAME); assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); @@ -543,7 +539,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { * Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)} */ private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) { - assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME); assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME); assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION); @@ -560,7 +556,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { } private void assertDtoIsProjectView1(ComponentDto pv1Dto, ComponentDto viewDto, ComponentDto parentViewDto, ComponentDto project) { - assertThat(pv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID); + assertThat(pv1Dto.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); assertThat(pv1Dto.name()).isEqualTo(PROJECT_VIEW_1_NAME); assertThat(pv1Dto.longName()).isEqualTo(PROJECT_VIEW_1_NAME); assertThat(pv1Dto.description()).isNull(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepTest.java index 91ed08e795a..48e06dbb19b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepTest.java @@ -41,7 +41,6 @@ public class IgnoreOrphanBranchStepTest { private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name"); private CeTask ceTask = new CeTask.Builder() - .setOrganizationUuid("organizationUuid") .setType("type") .setUuid("uuid") .setComponent(component) @@ -90,7 +89,6 @@ public class IgnoreOrphanBranchStepTest { @Test public void fail_if_missing_main_component_in_task() { CeTask ceTask = new CeTask.Builder() - .setOrganizationUuid("organizationUuid") .setType("type") .setUuid("uuid") .setComponent(null) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java index 8f004404c38..c98de3cea06 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java @@ -52,7 +52,6 @@ public class IndexIssuesStepTest { private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name"); private CeTask ceTask = new CeTask.Builder() - .setOrganizationUuid("organizationUuid") .setType("type") .setUuid("uuid") .setComponent(component) @@ -106,7 +105,6 @@ public class IndexIssuesStepTest { @Test public void fail_if_missing_component_in_task() { CeTask ceTask = new CeTask.Builder() - .setOrganizationUuid("organizationUuid") .setType("type") .setUuid("uuid") .setComponent(null) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IssueSyncTaskProcessorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IssueSyncTaskProcessorTest.java index 3dd49083c26..d0ec49c9907 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IssueSyncTaskProcessorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IssueSyncTaskProcessorTest.java @@ -47,7 +47,6 @@ public class IssueSyncTaskProcessorTest { @Test public void newContainerPopulator() { CeTask task = new CeTask.Builder() - .setOrganizationUuid("ORGANIZATION_UUID") .setUuid("TASK_UUID") .setType("Type") .build(); diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java index 24fe8bd4ca6..eac15900c01 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java @@ -27,19 +27,15 @@ import javax.annotation.Nullable; import org.junit.rules.ExternalResource; import org.sonar.ce.task.util.InitializedProperty; import org.sonar.db.component.BranchType; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.project.Project; import org.sonar.server.qualityprofile.QualityProfile; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; import static org.apache.commons.lang.StringUtils.defaultIfBlank; public class AnalysisMetadataHolderRule extends ExternalResource implements MutableAnalysisMetadataHolder { - private final InitializedProperty organizationsEnabled = new InitializedProperty<>(); - private final InitializedProperty organization = new InitializedProperty<>(); private final InitializedProperty uuid = new InitializedProperty<>(); private final InitializedProperty analysisDate = new InitializedProperty<>(); private final InitializedProperty forkDate = new InitializedProperty<>(); @@ -53,38 +49,6 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta private final InitializedProperty> pluginsByKey = new InitializedProperty<>(); private final InitializedProperty scmRevision = 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); - return this; - } - - 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))); - return this; - } - - @Override - public Organization getOrganization() { - checkState(organization.isInitialized(), "Organization has not been set"); - return this.organization.getProperty(); - } - @Override public AnalysisMetadataHolderRule setUuid(String s) { checkNotNull(s, "UUID must not be null"); @@ -110,7 +74,8 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta return this; } - @Override public MutableAnalysisMetadataHolder setForkDate(@Nullable Long date) { + @Override + public MutableAnalysisMetadataHolder setForkDate(@Nullable Long date) { forkDate.setProperty(date); return this; } diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java index e8f09ed99d9..5e9368edf59 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java @@ -32,7 +32,7 @@ import static org.mockito.Mockito.mock; public class MutableAnalysisMetadataHolderRule extends ExternalResource implements MutableAnalysisMetadataHolder { - private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); + private final PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); private AnalysisMetadataHolderImpl delegate = new AnalysisMetadataHolderImpl(editionProvider); @Override @@ -40,28 +40,6 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen delegate = new AnalysisMetadataHolderImpl(editionProvider); } - @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; - } - - @Override - public Organization getOrganization() { - return delegate.getOrganization(); - } - public MutableAnalysisMetadataHolderRule setUuid(String s) { delegate.setUuid(s); return this; @@ -77,7 +55,8 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen return this; } - @Override public MutableAnalysisMetadataHolder setForkDate(@Nullable Long date) { + @Override + public MutableAnalysisMetadataHolder setForkDate(@Nullable Long date) { return delegate.setForkDate(date); } diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java index ba05dc99382..a60cda39df7 100644 --- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java @@ -37,7 +37,6 @@ import static java.util.Objects.requireNonNull; @Immutable public class CeTask { - private final String organizationUuid; private final String type; private final String uuid; private final Component component; @@ -46,7 +45,6 @@ public class CeTask { private final Map characteristics; private CeTask(Builder builder) { - this.organizationUuid = requireNonNull(emptyToNull(builder.organizationUuid), "organizationUuid can't be null nor empty"); this.uuid = requireNonNull(emptyToNull(builder.uuid), "uuid can't be null nor empty"); this.type = requireNonNull(emptyToNull(builder.type), "type can't be null nor empty"); checkArgument((builder.component == null) == (builder.mainComponent == null), @@ -106,10 +104,6 @@ public class CeTask { } } - public String getOrganizationUuid() { - return organizationUuid; - } - public String getUuid() { return uuid; } @@ -138,7 +132,6 @@ public class CeTask { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("organizationUuid", organizationUuid) .add("type", type) .add("uuid", uuid) .add("component", component) @@ -165,7 +158,6 @@ public class CeTask { } public static final class Builder { - private String organizationUuid; private String uuid; private String type; private Component component; @@ -173,16 +165,6 @@ public class CeTask { private User submitter; private Map characteristics; - public Builder setOrganizationUuid(String organizationUuid) { - this.organizationUuid = organizationUuid; - return this; - } - - // FIXME remove this method when organization support is added to the Compute Engine queue - public boolean hasOrganizationUuid() { - return organizationUuid != null; - } - public Builder setUuid(String uuid) { this.uuid = uuid; return this; diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java index 16be9f7773e..e5bd88645ca 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java @@ -38,68 +38,9 @@ public class CeTaskTest { private CeTask.Builder underTest = new CeTask.Builder(); - @Test - public void build_fails_with_NPE_if_organizationUuid_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("organizationUuid can't be null nor empty"); - - underTest.build(); - } - - @Test - public void build_fails_with_NPE_if_organizationUuid_is_empty() { - underTest.setOrganizationUuid(""); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("organizationUuid can't be null nor empty"); - - underTest.build(); - } - - @Test - public void build_fails_with_NPE_if_uid_is_null() { - underTest.setOrganizationUuid("org1"); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("uuid can't be null nor empty"); - - underTest.build(); - } - - @Test - public void build_fails_with_NPE_if_uuid_is_empty() { - underTest.setOrganizationUuid("org1").setUuid(""); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("uuid can't be null nor empty"); - - underTest.build(); - } - - @Test - public void build_fails_with_NPE_if_type_is_null() { - underTest.setOrganizationUuid("org1").setUuid("uuid"); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("type can't be null nor empty"); - - underTest.build(); - } - - @Test - public void build_fails_with_NPE_if_type_is_empty() { - underTest.setOrganizationUuid("org1").setUuid("uuid").setType(""); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("type can't be null nor empty"); - - underTest.build(); - } - @Test @UseDataProvider("oneAndOnlyOneOfComponentAndMainComponent") public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component mainComponent) { - underTest.setOrganizationUuid("org1"); underTest.setType("TYPE_1"); underTest.setUuid("UUID_1"); underTest.setComponent(component); @@ -125,7 +66,6 @@ public class CeTaskTest { CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component"); CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component"); CeTask.User submitter = new CeTask.User("UUID_USER_1", "LOGIN_1"); - underTest.setOrganizationUuid("org1"); underTest.setType("TYPE_1"); underTest.setUuid("UUID_1"); underTest.setSubmitter(submitter); @@ -135,7 +75,6 @@ public class CeTaskTest { CeTask task = underTest.build(); - assertThat(task.getOrganizationUuid()).isEqualTo("org1"); assertThat(task.getUuid()).isEqualTo("UUID_1"); assertThat(task.getType()).isEqualTo("TYPE_1"); assertThat(task.getSubmitter()).isEqualTo(submitter); @@ -148,7 +87,6 @@ public class CeTaskTest { public void verify_toString() { CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component"); CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component"); - underTest.setOrganizationUuid("org1"); underTest.setType("TYPE_1"); underTest.setUuid("UUID_1"); underTest.setComponent(component); @@ -159,20 +97,18 @@ public class CeTaskTest { CeTask task = underTest.build(); System.out.println(task.toString()); - assertThat(task.toString()).isEqualTo("CeTask{" + - "organizationUuid=org1, " + - "type=TYPE_1, " + - "uuid=UUID_1, " + - "component=Component{uuid='COMPONENT_UUID_1', key='COMPONENT_KEY_1', name='The component'}, " + - "mainComponent=Component{uuid='MAIN_COMPONENT_UUID_1', key='MAIN_COMPONENT_KEY_1', name='The main component'}, " + - "submitter=User{uuid='UUID_USER_1', login='LOGIN_1'}" + - "}" - ); + assertThat(task).hasToString("CeTask{" + + "type=TYPE_1, " + + "uuid=UUID_1, " + + "component=Component{uuid='COMPONENT_UUID_1', key='COMPONENT_KEY_1', name='The component'}, " + + "mainComponent=Component{uuid='MAIN_COMPONENT_UUID_1', key='MAIN_COMPONENT_KEY_1', name='The main component'}, " + + "submitter=User{uuid='UUID_USER_1', login='LOGIN_1'}" + + "}"); } @Test public void empty_in_submitterLogin_is_considered_as_null() { - CeTask ceTask = underTest.setOrganizationUuid("org1").setUuid("uuid").setType("type") + CeTask ceTask = underTest.setUuid("uuid").setType("type") .setSubmitter(new CeTask.User("USER_ID", "")) .build(); @@ -181,10 +117,10 @@ public class CeTaskTest { @Test public void equals_and_hashCode_on_uuid() { - underTest.setOrganizationUuid("org1").setType("TYPE_1").setUuid("UUID_1"); + underTest.setType("TYPE_1").setUuid("UUID_1"); CeTask task1 = underTest.build(); CeTask task1bis = underTest.build(); - CeTask task2 = new CeTask.Builder().setOrganizationUuid("org1").setType("TYPE_1").setUuid("UUID_2").build(); + CeTask task2 = new CeTask.Builder().setType("TYPE_1").setUuid("UUID_2").build(); assertThat(task1.equals(task1)).isTrue(); assertThat(task1.equals(task1bis)).isTrue(); @@ -195,7 +131,7 @@ public class CeTaskTest { @Test public void setCharacteristics_null_is_considered_as_empty() { - CeTask task = underTest.setOrganizationUuid("org1").setType("TYPE_1").setUuid("UUID_1") + CeTask task = underTest.setType("TYPE_1").setUuid("UUID_1") .setCharacteristics(null) .build(); assertThat(task.getCharacteristics()).isEmpty(); diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesImplTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesImplTest.java index c8a96879a64..df741f7c756 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesImplTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesImplTest.java @@ -58,7 +58,6 @@ public class CeTaskMessagesImplTest { private CeTask ceTask = new CeTask.Builder() .setUuid(taskUuid) - .setOrganizationUuid(randomAlphabetic(10)) .setType(randomAlphabetic(5)) .build(); diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index 73d6ff344fa..9bab389ae54 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -76,8 +76,8 @@ import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.EditionProvider; import org.sonar.core.platform.Module; import org.sonar.core.platform.PlatformEditionProvider; -import org.sonar.core.platform.PluginClassloaderFactory; import org.sonar.core.platform.PluginClassLoader; +import org.sonar.core.platform.PluginClassloaderFactory; import org.sonar.core.util.UuidFactoryImpl; import org.sonar.db.DBSessionsImpl; import org.sonar.db.DaoModule; @@ -115,9 +115,7 @@ import org.sonar.server.metric.UnanalyzedLanguageMetrics; import org.sonar.server.notification.DefaultNotificationManager; import org.sonar.server.notification.NotificationService; import org.sonar.server.notification.email.EmailNotificationChannel; -import org.sonar.server.organization.BillingValidationsProxyImpl; import org.sonar.server.organization.DefaultOrganizationProviderImpl; -import org.sonar.server.organization.OrganizationFlagsImpl; import org.sonar.server.platform.OfficialDistribution; import org.sonar.server.platform.ServerFileSystemImpl; import org.sonar.server.platform.ServerImpl; @@ -355,15 +353,13 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { UriReader.class, ServerImpl.class, DefaultOrganizationProviderImpl.class, - SynchronousAsyncExecution.class, - OrganizationFlagsImpl.class); + SynchronousAsyncExecution.class); } private static void populateLevel4(ComponentContainer container, Props props) { container.add( ResourceTypes.class, DefaultResourceTypes.get(), - BillingValidationsProxyImpl.class, // quality profile ActiveRuleIndexer.class, diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java index 279b2f60021..d70f5e887a9 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java @@ -47,7 +47,6 @@ import org.sonar.db.ce.CeQueueDao; import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskCharacteristicDto; import org.sonar.db.component.ComponentDto; -import org.sonar.server.organization.DefaultOrganizationProvider; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; @@ -65,8 +64,8 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue private final ComputeEngineStatus computeEngineStatus; public InternalCeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory, CEQueueStatus queueStatus, - DefaultOrganizationProvider defaultOrganizationProvider, ComputeEngineStatus computeEngineStatus) { - super(system2, dbClient, uuidFactory, defaultOrganizationProvider); + ComputeEngineStatus computeEngineStatus) { + super(system2, dbClient, uuidFactory); this.dbClient = dbClient; this.queueStatus = queueStatus; this.computeEngineStatus = computeEngineStatus; diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java index 8e02119265d..4aa86af1ea2 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java @@ -45,8 +45,6 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.server.notification.NotificationService; import static java.util.Collections.singleton; @@ -151,15 +149,14 @@ public class ReportAnalysisFailureNotificationExecutionListenerTest { @Test public void onEnd_fails_with_IAE_if_component_is_not_a_project() { when(ceTaskMock.getType()).thenReturn(CeTaskTypes.REPORT); - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto directory = dbTester.components().insertComponent(newDirectory(module, randomAlphanumeric(12))); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); - ComponentDto view = dbTester.components().insertComponent(ComponentTesting.newView(organization)); + ComponentDto view = dbTester.components().insertComponent(ComponentTesting.newView()); ComponentDto subView = dbTester.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto projectCopy = dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project, subView)); - ComponentDto application = dbTester.components().insertComponent(ComponentTesting.newApplication(organization)); + ComponentDto application = dbTester.components().insertComponent(ComponentTesting.newApplication()); Arrays.asList(module, directory, file, view, subView, projectCopy, application) .forEach(component -> { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index 2d37e9480e5..a9b82a87f75 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -47,10 +47,7 @@ import org.sonar.db.ce.CeQueueTesting; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.UserDto; -import org.sonar.server.organization.DefaultOrganization; -import org.sonar.server.organization.DefaultOrganizationProvider; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; @@ -81,20 +78,11 @@ public class InternalCeQueueImplTest { private UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE; private CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class)); - private DefaultOrganizationProvider defaultOrganizationProvider = mock(DefaultOrganizationProvider.class); private ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class); - private InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus, defaultOrganizationProvider, computeEngineStatus); + private InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus, computeEngineStatus); @Before public void setUp() { - OrganizationDto defaultOrganization = db.getDefaultOrganization(); - when(defaultOrganizationProvider.get()).thenReturn(DefaultOrganization.newBuilder() - .setUuid(defaultOrganization.getUuid()) - .setKey(defaultOrganization.getKey()) - .setName(defaultOrganization.getName()) - .setCreatedAt(defaultOrganization.getCreatedAt()) - .setUpdatedAt(defaultOrganization.getUpdatedAt()) - .build()); when(computeEngineStatus.getStatus()).thenReturn(STARTED); } @@ -259,7 +247,7 @@ public class InternalCeQueueImplTest { db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid()); db.commit(); - InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatus, null, null); + InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatus, null); try { underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null); @@ -276,7 +264,7 @@ public class InternalCeQueueImplTest { CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1")); db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid()); db.commit(); - InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null); + InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null); try { underTest.remove(task, CeActivityDto.Status.FAILED, null, null); @@ -293,7 +281,7 @@ public class InternalCeQueueImplTest { CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1")); db.executeUpdateSql("update ce_queue set status = 'PENDING', started_at = 123 where uuid = '" + task.getUuid() + "'"); db.commit(); - InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null); + InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null); underTest.cancelWornOuts(); @@ -325,7 +313,6 @@ public class InternalCeQueueImplTest { db.commit(); underTest.remove(new CeTask.Builder() - .setOrganizationUuid("foo") .setUuid("uuid") .setType("bar") .build(), CeActivityDto.Status.SUCCESS, null, null); @@ -623,11 +610,6 @@ public class InternalCeQueueImplTest { } private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable UserDto userDto) { - if (componentDto == null) { - assertThat(task.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); - } else { - assertThat(task.getOrganizationUuid()).isEqualTo(componentDto.getOrganizationUuid()); - } assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid()); assertThat(task.getType()).isEqualTo(taskSubmit.getType()); if (componentDto != null) { @@ -669,7 +651,7 @@ public class InternalCeQueueImplTest { } private ComponentDto newProjectDto(String uuid) { - return ComponentTesting.newPublicProjectDto(db.getDefaultOrganization(), uuid).setName("name_" + uuid).setDbKey("key_" + uuid); + return ComponentTesting.newPublicProjectDto(uuid).setName("name_" + uuid).setDbKey("key_" + uuid); } private CeTask submit(String reportType, ComponentDto componentDto) { @@ -698,9 +680,7 @@ public class InternalCeQueueImplTest { } private ComponentDto insertComponent(ComponentDto componentDto) { - db.getDbClient().componentDao().insert(session, componentDto); - session.commit(); - return componentDto; + return db.components().insertComponent(componentDto); } private CeQueueDto makeInProgress(CeQueueDto ceQueueDto, String workerUuid) { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java index 9929bf0e13b..be598e318a3 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java @@ -109,7 +109,6 @@ public class CeTaskProcessorRepositoryImplTest { private static CeTask createCeTask(String ceTaskType, String key) { CeTask.Component component = new CeTask.Component("uuid_" + key, key, "name_" + key); return new CeTask.Builder() - .setOrganizationUuid("org1") .setType(ceTaskType) .setUuid("task_uuid_" + key) .setComponent(component) diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerImplTest.java index ddb5027720d..821e1dddcdc 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeWorkerImplTest.java @@ -19,7 +19,6 @@ */ package org.sonar.ce.taskprocessor; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -55,7 +54,6 @@ import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserTesting; -import org.sonar.server.organization.BillingValidations; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; @@ -64,10 +62,12 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; @@ -490,22 +490,6 @@ public class CeWorkerImplTest { assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); } - @Test - public void do_no_log_error_when_task_fails_with_BillingValidationsException() throws Exception { - CeTask ceTask = createCeTask(submitter); - when(queue.peek(anyString(), anyBoolean(), anyBoolean())).thenReturn(Optional.of(ceTask)); - taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor); - makeTaskProcessorFail(ceTask, new BillingValidations.BillingValidationsException("simulate MessageException thrown by TaskProcessor#process")); - - underTest.call(); - - List logs = logTester.logs(LoggerLevel.INFO); - assertThat(logs).hasSize(2); - assertThat(logs.get(1)).contains(" | submitter=" + submitter.getLogin()); - assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin())); - assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); - } - @Test public void log_error_when_task_was_successful_but_ending_state_can_not_be_persisted_to_db() throws Exception { CeTask ceTask = createCeTask(submitter); @@ -772,7 +756,6 @@ public class CeWorkerImplTest { } CeTask.Component component = new CeTask.Component("PROJECT_1", null, null); return new CeTask.Builder() - .setOrganizationUuid("org1") .setUuid("TASK_1").setType(CeTaskTypes.REPORT) .setComponent(component) .setMainComponent(component) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java index d25c36220af..3685dd15774 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java @@ -279,6 +279,7 @@ public class ComponentTesting { public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { return newChildComponent(uuid, view, view) .setDbKey(view.getDbKey() + project.getDbKey()) + .setOrganizationUuid(project.getOrganizationUuid()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java index d8688b980c5..8d150fd95c9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java @@ -23,8 +23,8 @@ import javax.annotation.Nullable; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; import org.sonar.api.impl.utils.TestSystem2; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.ce.queue.CeQueue; import org.sonar.ce.queue.CeQueueImpl; @@ -37,8 +37,6 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.organization.DefaultOrganizationProvider; -import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; @@ -54,9 +52,8 @@ public class CancelActionTest { @Rule public DbTester db = DbTester.create(); - private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); private System2 system2 = new TestSystem2(); - private CeQueue queue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), defaultOrganizationProvider); + private CeQueue queue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance()); private CancelAction underTest = new CancelAction(userSession, db.getDbClient(), queue); private WsActionTester tester = new WsActionTester(underTest); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java index d98b6a7f6da..dc0124fc1fe 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java @@ -48,7 +48,6 @@ public class SubmitActionTest { private static final String PROJECT_UUID = "PROJECT_1"; private static final CeTask.Component COMPONENT = new CeTask.Component(PROJECT_UUID, "KEY_1", "NAME_1"); private static final CeTask A_CE_TASK = new CeTask.Builder() - .setOrganizationUuid("org1") .setUuid("TASK_1") .setType(CeTaskTypes.REPORT) .setComponent(COMPONENT) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java index 67e6ea79269..f1513799d45 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java @@ -91,8 +91,6 @@ public class MetadataPublisher implements ReportPublisherStep { projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion); projectInfo.getBuildString().ifPresent(builder::setBuildString); - properties.organizationKey().ifPresent(builder::setOrganizationKey); - if (branchConfiguration.branchName() != null) { addBranchInformation(builder); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java index f6f176d8cff..01a995dda20 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java @@ -172,20 +172,6 @@ public class MetadataPublisherTest { assertThat(metadata.getNotAnalyzedFilesByLanguageMap()).contains(entry("c", 10), entry("cpp", 20)); } - @Test - public void write_project_organization() throws Exception { - when(properties.organizationKey()).thenReturn(Optional.of("SonarSource")); - - File outputDir = temp.newFolder(); - ScannerReportWriter writer = new ScannerReportWriter(outputDir); - - underTest.publish(writer); - - ScannerReportReader reader = new ScannerReportReader(outputDir); - ScannerReport.Metadata metadata = reader.readMetadata(); - assertThat(metadata.getOrganizationKey()).isEqualTo("SonarSource"); - } - @Test @UseDataProvider("projectVersions") public void write_project_version(@Nullable String projectVersion, String expected) throws Exception { diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto index 3e3a1f80351..b2deb7be2f5 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto @@ -30,7 +30,7 @@ option optimize_for = SPEED; message Metadata { int64 analysis_date = 1; - string organization_key = 2; + reserved 2; // organization drop // TODO should we keep this project_key here or not ? Because it's a duplication of Component.key string project_key = 3; -- 2.39.5