ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)
.setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch(BRANCH_KEY).build())
- .setMergeBranchUuid(projectDto.getMainBranchProjectUuid()));
+ .setMergeBranchUuid(projectDto.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
db.components().insertComponents(branch1File, pr1File);
ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)
.setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build())
- .setMergeBranchUuid(projectDto.getMainBranchProjectUuid()));
+ .setMergeBranchUuid(projectDto.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
db.components().insertComponents(branch1File, pr1File);
import org.sonar.server.project.Project;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
public void throw_ISE_when_specific_analysis_is_set_but_does_not_exist_in_DB() {
ComponentDto project = dbTester.components().insertPublicProject();
setProjectPeriod(project.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, "nonexistent");
- setupRoot(project);
+ setupRoot(project, project.uuid(), "any-string");
assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
.isInstanceOf(IllegalStateException.class)
.containsOnly(Stream.concat(Stream.of(log), Arrays.stream(otherLogs)).toArray(String[]::new));
}
- private void setupRoot(ComponentDto project) {
- setupRoot(project, randomAlphanumeric(3));
+ private void setupRoot(ComponentDto branchComponent) {
+ setupRoot(branchComponent, "any-string");
}
- private void setupRoot(ComponentDto projectDto, String version) {
+ private void setupRoot(ComponentDto branchComponent, String projectUuid, String version) {
treeRootHolder.setRoot(ReportComponent
.builder(Component.Type.PROJECT, 1)
- .setUuid(projectDto.uuid())
- .setKey(projectDto.getKey())
+ .setUuid(branchComponent.uuid())
+ .setKey(branchComponent.getKey())
.setProjectVersion(version)
.build());
Project project = mock(Project.class);
- when(project.getUuid()).thenReturn(projectDto.getMainBranchProjectUuid() != null ? projectDto.getMainBranchProjectUuid() : projectDto.uuid());
+ when(project.getUuid()).thenReturn(projectUuid);
when(analysisMetadataHolder.getProject()).thenReturn(project);
}
+ private void setupRoot(ComponentDto branchComponent, String version) {
+ setupRoot(branchComponent, project.uuid(), version);
+ }
+
private static void verifyInvalidValueMessage(MessageException e, String propertyValue) {
assertThat(e).hasMessage("Invalid new code period. '" + propertyValue
+ "' is not one of: integer > 0, date before current analysis j, \"previous_version\", or version string that exists in the project' \n" +
assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.uuid()).isEqualTo("CDEF");
assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + projectDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(directoryDto.getMainBranchProjectUuid()).isNull();
assertThat(directoryDto.branchUuid()).isEqualTo(projectDto.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(directoryDto.scope()).isEqualTo("DIR");
assertThat(fileDto.language()).isEqualTo("java");
assertThat(fileDto.uuid()).isEqualTo("DEFG");
assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(fileDto.getMainBranchProjectUuid()).isNull();
assertThat(fileDto.branchUuid()).isEqualTo(projectDto.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(fileDto.scope()).isEqualTo("FIL");
assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.uuid()).isEqualTo("CDEF");
assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + branch.uuid() + UUID_PATH_SEPARATOR);
- assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(analysisMetadataHolder.getProject().getUuid());
assertThat(directoryDto.branchUuid()).isEqualTo(branch.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(directoryDto.scope()).isEqualTo("DIR");
assertThat(fileDto.language()).isEqualTo("java");
assertThat(fileDto.uuid()).isEqualTo("DEFG");
assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(analysisMetadataHolder.getProject().getUuid());
assertThat(fileDto.branchUuid()).isEqualTo(branch.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(fileDto.scope()).isEqualTo("FIL");
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get();
assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
assertThat(projectReloaded.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT);
- assertThat(projectReloaded.getMainBranchProjectUuid()).isNull();
ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directory.getUuidPath()).isEqualTo(directory.getUuidPath());
assertThat(directory.branchUuid()).isEqualTo(project.uuid());
- assertThat(directory.getMainBranchProjectUuid()).isNull();
ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(file.getUuidPath()).isEqualTo(file.getUuidPath());
assertThat(file.branchUuid()).isEqualTo(project.uuid());
- assertThat(file.getMainBranchProjectUuid()).isNull();
}
@Test
assertThat(underTest.selectProjectsFromView(dbSession, subView2.uuid(), view.uuid())).containsExactlyInAnyOrder(project3.uuid());
}
- @Test
- public void select_projects() {
- ComponentDto provisionedProject = db.components().insertPrivateProject();
- ComponentDto provisionedView = db.components().insertPrivatePortfolio();
- String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto()).getComponentUuid();
- String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto().setEnabled(false)).getComponentUuid();
- String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newPortfolio()).getComponentUuid();
-
- assertThat(underTest.selectProjects(dbSession))
- .extracting(ComponentDto::uuid)
- .containsOnly(provisionedProject.uuid(), projectUuid);
- }
-
- @Test
- public void select_projects_does_not_return_branches() {
- ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
-
- assertThat(underTest.selectProjects(dbSession))
- .extracting(ComponentDto::uuid)
- .containsOnly(project.uuid());
- }
-
@Test
public void selectByQuery_provisioned() {
ComponentDto provisionedProject = db.components()
import org.sonar.db.webhook.WebhookDeliveryLiteDto;
import org.sonar.db.webhook.WebhookDto;
-import static com.google.common.base.MoreObjects.firstNonNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.time.ZoneOffset.UTC;
import static java.util.Arrays.asList;
insertPropertyFor(branch3, branch1);
// analysing branch1
- underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, branch1.uuid(), branch1.getMainBranchProjectUuid()), PurgeListener.EMPTY, new PurgeProfiler());
+ underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, branch1.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
// branch1 wasn't deleted since it was being analyzed!
ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto();
insertComponents(List.of(anotherLivingProject), List.of(projectToBeDeleted));
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
- CeActivityDto toBeDeletedActivity = insertCeActivity(projectToBeDeleted);
- CeActivityDto notDeletedActivity = insertCeActivity(anotherLivingProject);
+ CeActivityDto toBeDeletedActivity = insertCeActivity(projectToBeDeleted, projectToBeDeleted.uuid());
+ CeActivityDto notDeletedActivity = insertCeActivity(anotherLivingProject, anotherLivingProject.uuid());
dbSession.commit();
underTest.deleteProject(dbSession, projectToBeDeleted.uuid(), projectToBeDeleted.qualifier(), projectToBeDeleted.name(), projectToBeDeleted.getKey());
insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
- CeActivityDto projectTask = insertCeActivity(project);
+ CeActivityDto projectTask = insertCeActivity(project, project.uuid());
insertCeTaskInput(projectTask.getUuid());
- CeActivityDto branchTask = insertCeActivity(branch);
+ CeActivityDto branchTask = insertCeActivity(branch, project.uuid());
insertCeTaskInput(branchTask.getUuid());
- CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch);
+ CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid());
insertCeTaskInput(anotherBranchTask.getUuid());
- CeActivityDto anotherProjectTask = insertCeActivity(anotherProject);
+ CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid());
insertCeTaskInput(anotherProjectTask.getUuid());
insertCeTaskInput("non existing task");
dbSession.commit();
insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
- CeActivityDto projectTask = insertCeActivity(project);
+ CeActivityDto projectTask = insertCeActivity(project, project.uuid());
insertCeScannerContext(projectTask.getUuid());
- CeActivityDto branchTask = insertCeActivity(branch);
+ CeActivityDto branchTask = insertCeActivity(branch, project.uuid());
insertCeScannerContext(branchTask.getUuid());
- CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch);
+ CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid());
insertCeScannerContext(anotherBranchTask.getUuid());
- CeActivityDto anotherProjectTask = insertCeActivity(anotherProject);
+ CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid());
insertCeScannerContext(anotherProjectTask.getUuid());
insertCeScannerContext("non existing task");
dbSession.commit();
insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
- CeActivityDto projectTask = insertCeActivity(project);
+ CeActivityDto projectTask = insertCeActivity(project, project.uuid());
insertCeTaskCharacteristics(projectTask.getUuid(), 3);
- CeActivityDto branchTask = insertCeActivity(branch);
+ CeActivityDto branchTask = insertCeActivity(branch, project.uuid());
insertCeTaskCharacteristics(branchTask.getUuid(), 2);
- CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch);
+ CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid());
insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 6);
- CeActivityDto anotherProjectTask = insertCeActivity(anotherProject);
+ CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid());
insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2);
insertCeTaskCharacteristics("non existing task", 5);
dbSession.commit();
insertComponents(List.of(project, anotherProject), List.of(branch, anotherBranch));
- CeActivityDto projectTask = insertCeActivity(project);
+ CeActivityDto projectTask = insertCeActivity(project, project.uuid());
insertCeTaskMessages(projectTask.getUuid(), 3);
- CeActivityDto branchTask = insertCeActivity(branch);
+ CeActivityDto branchTask = insertCeActivity(branch, project.uuid());
insertCeTaskMessages(branchTask.getUuid(), 2);
- CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch);
+ CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch, project.uuid());
insertCeTaskMessages(anotherBranchTask.getUuid(), 6);
- CeActivityDto anotherProjectTask = insertCeActivity(anotherProject);
+ CeActivityDto anotherProjectTask = insertCeActivity(anotherProject, anotherProject.uuid());
insertCeTaskMessages(anotherProjectTask.getUuid(), 2);
insertCeTaskMessages("non existing task", 5);
dbSession.commit();
// Insert 3 rows in CE_QUEUE: two for the project that will be deleted (in order to check that status
// is not involved in deletion), and one on another project
- dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.PENDING));
- dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.IN_PROGRESS));
- dbClient.ceQueueDao().insert(dbSession, createCeQueue(anotherLivingProject, Status.PENDING));
+ dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, projectToBeDeleted.uuid(), Status.PENDING));
+ dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, projectToBeDeleted.uuid(), Status.IN_PROGRESS));
+ dbClient.ceQueueDao().insert(dbSession, createCeQueue(anotherLivingProject, anotherLivingProject.uuid(), Status.PENDING));
dbSession.commit();
underTest.deleteProject(dbSession, projectToBeDeleted.uuid(), projectToBeDeleted.qualifier(), projectToBeDeleted.name(), projectToBeDeleted.getKey());
CeQueueDto projectTask = insertCeQueue(project);
insertCeTaskInput(projectTask.getUuid());
- CeQueueDto branchTask = insertCeQueue(branch);
+ CeQueueDto branchTask = insertCeQueue(branch, project.uuid());
insertCeTaskInput(branchTask.getUuid());
- CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch);
+ CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid());
insertCeTaskInput(anotherBranchTask.getUuid());
CeQueueDto anotherProjectTask = insertCeQueue(anotherProject);
insertCeTaskInput(anotherProjectTask.getUuid());
CeQueueDto projectTask = insertCeQueue(project);
insertCeScannerContext(projectTask.getUuid());
- CeQueueDto branchTask = insertCeQueue(branch);
+ CeQueueDto branchTask = insertCeQueue(branch, project.uuid());
insertCeScannerContext(branchTask.getUuid());
- CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch);
+ CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid());
insertCeScannerContext(anotherBranchTask.getUuid());
CeQueueDto anotherProjectTask = insertCeQueue(anotherProject);
insertCeScannerContext(anotherProjectTask.getUuid());
CeQueueDto projectTask = insertCeQueue(project);
insertCeTaskCharacteristics(projectTask.getUuid(), 3);
- CeQueueDto branchTask = insertCeQueue(branch);
+ CeQueueDto branchTask = insertCeQueue(branch, project.uuid());
insertCeTaskCharacteristics(branchTask.getUuid(), 1);
- CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch);
+ CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid());
insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 5);
CeQueueDto anotherProjectTask = insertCeQueue(anotherProject);
insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2);
CeQueueDto projectTask = insertCeQueue(project);
insertCeTaskMessages(projectTask.getUuid(), 3);
- CeQueueDto branchTask = insertCeQueue(branch);
+ CeQueueDto branchTask = insertCeQueue(branch, project.uuid());
insertCeTaskMessages(branchTask.getUuid(), 1);
- CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch);
+ CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch, project.uuid());
insertCeTaskMessages(anotherBranchTask.getUuid(), 5);
CeQueueDto anotherProjectTask = insertCeQueue(anotherProject);
insertCeTaskMessages(anotherProjectTask.getUuid(), 2);
dbSession.commit();
}
- private CeQueueDto createCeQueue(ComponentDto component, Status status) {
+ private CeQueueDto createCeQueue(ComponentDto component, String mainBranch, Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setUuid(Uuids.create());
queueDto.setTaskType(REPORT);
queueDto.setComponentUuid(component.uuid());
- queueDto.setMainComponentUuid(firstNonNull(component.getMainBranchProjectUuid(), component.uuid()));
+ queueDto.setMainComponentUuid(mainBranch);
queueDto.setSubmitterUuid("submitter uuid");
queueDto.setCreatedAt(1_300_000_000_000L);
queueDto.setStatus(status);
return queueDto;
}
- private CeActivityDto insertCeActivity(ComponentDto component) {
+ private CeActivityDto insertCeActivity(ComponentDto component, String mainBranch) {
Status unusedStatus = Status.values()[RandomUtils.nextInt(Status.values().length)];
- CeQueueDto queueDto = createCeQueue(component, unusedStatus);
+ CeQueueDto queueDto = createCeQueue(component, mainBranch, unusedStatus);
CeActivityDto dto = new CeActivityDto(queueDto);
dto.setStatus(CeActivityDto.Status.SUCCESS);
return dto;
}
- private CeQueueDto insertCeQueue(ComponentDto component) {
+ private CeQueueDto insertCeQueue(ComponentDto component, String mainBranch) {
CeQueueDto res = new CeQueueDto()
.setUuid(UuidFactoryFast.getInstance().create())
.setTaskType("foo")
.setComponentUuid(component.uuid())
- .setMainComponentUuid(firstNonNull(component.getMainBranchProjectUuid(), component.uuid()))
+ .setMainComponentUuid(mainBranch)
.setStatus(Status.PENDING)
.setCreatedAt(1_2323_222L)
.setUpdatedAt(1_2323_222L);
return res;
}
+ private CeQueueDto insertCeQueue(ComponentDto component) {
+ return insertCeQueue(component, component.uuid());
+ }
+
private void insertCeScannerContext(String uuid) {
dbClient.ceScannerContextDao().insert(dbSession, uuid, CloseableIterator.from(Arrays.asList("a", "b", "c").iterator()));
dbSession.commit();
return mapper(session).selectUuidsForQualifiers(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW);
}
- /**
- * Returns all projects (Scope {@link Scopes#PROJECT} and qualifier
- * {@link Qualifiers#PROJECT}) which are enabled.
- * <p>
- * Branches are not returned.
- * <p>
- * Used by Views.
- */
- public List<ComponentDto> selectProjects(DbSession session) {
- return mapper(session).selectProjects();
- }
-
/**
* Used by Governance
*/
List<ComponentDto> selectChildren(@Param("branchUuid") String branchUuid, @Param("uuidPaths") Set<String> uuidPaths);
- /**
- * Returns all enabled projects (Scope {@link org.sonar.api.resources.Scopes#PROJECT} and qualifier
- * {@link org.sonar.api.resources.Qualifiers#PROJECT}) no matter if they are ghost project, provisioned projects or
- * regular ones.
- */
- List<ComponentDto> selectProjects();
-
/**
* Return all descendant views (including itself) from a given root view
*/
root.uuid=#{projectUuid,jdbcType=VARCHAR}
</select>
- <select id="selectProjects" resultType="Component">
- select
- <include refid="componentColumns"/>
- from components p
- where
- p.enabled=${_true}
- AND p.scope='PRJ'
- AND p.qualifier='TRK'
- AND p.main_branch_project_uuid IS NULL
- </select>
-
<select id="selectComponentsByQualifiers" resultType="Component">
SELECT
<include refid="componentColumns"/>
db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
insertIssue(project, projectAnalysis);
insertIssue(project, projectAnalysis);
- SnapshotDto branchAnalysis = insertAnalysis(branch, 1_501_000_000_000L);
+ SnapshotDto branchAnalysis = insertAnalysis(branch, project.uuid(), 1_501_000_000_000L);
db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
insertIssue(branch, branchAnalysis);
issueIndexer.indexAllIssues();
return newEvent(analysis).setCategory(EventCategory.QUALITY_GATE.getLabel());
}
- private CeActivityDto insertActivity(ComponentDto project, SnapshotDto analysis, CeActivityDto.Status status) {
+ private CeActivityDto insertActivity(String mainBranchUuid, SnapshotDto analysis, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
- String mainBranchProjectUuid = project.getMainBranchProjectUuid();
- queueDto.setComponentUuid(mainBranchProjectUuid == null ? project.uuid() : mainBranchProjectUuid);
+ queueDto.setComponentUuid(mainBranchUuid);
queueDto.setUuid(randomAlphanumeric(40));
queueDto.setCreatedAt(nextLong());
CeActivityDto activityDto = new CeActivityDto(queueDto);
.setType(randomRuleTypeExceptHotspot()));
}
+ private SnapshotDto insertAnalysis(ComponentDto branch, String mainBranchUuid, long analysisDate) {
+ SnapshotDto analysis = db.components().insertSnapshot(branch, s -> s.setCreatedAt(analysisDate));
+ insertActivity(mainBranchUuid, analysis, CeActivityDto.Status.SUCCESS);
+ return analysis;
+ }
+
private SnapshotDto insertAnalysis(ComponentDto project, long analysisDate) {
SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setCreatedAt(analysisDate));
- insertActivity(project, analysis, CeActivityDto.Status.SUCCESS);
+ insertActivity(project.uuid(), analysis, CeActivityDto.Status.SUCCESS);
return analysis;
}
userSession.addProjectPermission(USER, project);
String branchName1 = "branch1";
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName1));
- SnapshotDto branch1Analysis = insertAnalysis(branch1, 1_500_000_000_000L);
+ SnapshotDto branch1Analysis = insertAnalysis(branch1, project.uuid(), 1_500_000_000_000L);
insertIssue(branch1, branch1Analysis);
insertIssue(branch1, branch1Analysis);
String branchName2 = "branch2";
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey(branchName2));
- SnapshotDto branch2Analysis = insertAnalysis(branch2, 1_300_000_000_000L);
+ SnapshotDto branch2Analysis = insertAnalysis(branch2, project.uuid(), 1_300_000_000_000L);
insertIssue(branch2, branch2Analysis);
issueIndexer.indexAllIssues();
userSession.addProjectPermission(USER, project);
String nonMainBranchName = "nonMain";
ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(nonMainBranchName));
- SnapshotDto nonMainBranchAnalysis = insertAnalysis(nonMainBranch, 1_500_000_000_000L);
+ SnapshotDto nonMainBranchAnalysis = insertAnalysis(nonMainBranch, project.uuid(), 1_500_000_000_000L);
insertIssue(nonMainBranch, nonMainBranchAnalysis);
insertIssue(nonMainBranch, nonMainBranchAnalysis);
String pullRequestKey = "42";
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey));
- SnapshotDto pullRequestAnalysis = insertAnalysis(pullRequest, 1_300_000_000_000L);
+ SnapshotDto pullRequestAnalysis = insertAnalysis(pullRequest, project.uuid(), 1_300_000_000_000L);
insertIssue(pullRequest, pullRequestAnalysis);
issueIndexer.indexAllIssues();
.setType(RuleType.SECURITY_HOTSPOT));
}
+
private SnapshotDto insertAnalysis(ComponentDto project, long analysisDate) {
SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setCreatedAt(analysisDate));
- insertActivity(project, analysis, CeActivityDto.Status.SUCCESS);
+ insertActivity(project.uuid(), analysis, CeActivityDto.Status.SUCCESS);
+ return analysis;
+ }
+
+ private SnapshotDto insertAnalysis(ComponentDto branch, String mainBranchUuid, long analysisDate) {
+ SnapshotDto analysis = db.components().insertSnapshot(branch, s -> s.setCreatedAt(analysisDate));
+ insertActivity(mainBranchUuid, analysis, CeActivityDto.Status.SUCCESS);
return analysis;
}
- private CeActivityDto insertActivity(ComponentDto project, SnapshotDto analysis, CeActivityDto.Status status) {
+ private CeActivityDto insertActivity(String mainBranchUuid, SnapshotDto analysis, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
- String mainBranchProjectUuid = project.getMainBranchProjectUuid();
- queueDto.setComponentUuid(mainBranchProjectUuid == null ? project.uuid() : mainBranchProjectUuid);
+ queueDto.setComponentUuid(mainBranchUuid);
queueDto.setUuid(randomAlphanumeric(40));
queueDto.setCreatedAt(nextLong());
CeActivityDto activityDto = new CeActivityDto(queueDto);
import static java.lang.String.format;
import static java.lang.String.join;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn();
+ private static final long ANY_TIMESTAMP = 1666666666L;
+
private Server server = mock(Server.class);
private IssueIndex issueIndex = new IssueIndex(es.client(), null, userSession, null);
private IssueIndexSyncProgressChecker issueIndexSyncProgressChecker = mock(IssueIndexSyncProgressChecker.class);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
insertSuccessfulActivity(project, 1_500_000_000_000L);
SnapshotDto branchAnalysis = insertSuccessfulActivity(branch, 1_500_000_000_000L);
- insertActivity(branch, branchAnalysis, CeActivityDto.Status.SUCCESS);
+ insertActivity(project.uuid(), branchAnalysis, CeActivityDto.Status.SUCCESS);
db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
SearchEventsWsResponse result = ws.newRequest()
ComponentDto project = db.components().insertPrivateProject();
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
SnapshotDto prAnalysis = insertSuccessfulActivity(pr, 1_500_000_000_000L);
- insertActivity(pr, prAnalysis, CeActivityDto.Status.SUCCESS);
+ insertActivity(project.uuid(), prAnalysis, CeActivityDto.Status.SUCCESS);
db.events().insertEvent(newQualityGateEvent(prAnalysis).setDate(prAnalysis.getCreatedAt()).setName("Failed"));
SearchEventsWsResponse result = ws.newRequest()
private SnapshotDto insertSuccessfulActivity(ComponentDto project, long analysisDate) {
SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setCreatedAt(analysisDate));
- insertActivity(project, analysis, CeActivityDto.Status.SUCCESS);
+ insertActivity(project.uuid(), analysis, CeActivityDto.Status.SUCCESS);
return analysis;
}
- private CeActivityDto insertActivity(ComponentDto project, SnapshotDto analysis, CeActivityDto.Status status) {
+ private CeActivityDto insertActivity(String mainBranchUuid, SnapshotDto analysis, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
- String mainBranchProjectUuid = project.getMainBranchProjectUuid();
- queueDto.setComponentUuid(mainBranchProjectUuid == null ? project.uuid() : mainBranchProjectUuid);
+ queueDto.setComponentUuid(mainBranchUuid);
queueDto.setUuid(randomAlphanumeric(40));
- queueDto.setCreatedAt(nextLong());
+ queueDto.setCreatedAt(ANY_TIMESTAMP);
CeActivityDto activityDto = new CeActivityDto(queueDto);
activityDto.setStatus(status);
- activityDto.setExecutionTimeMs(nextLong());
- activityDto.setExecutedAt(nextLong());
+ activityDto.setExecutionTimeMs(1000L);
+ activityDto.setExecutedAt(ANY_TIMESTAMP);
activityDto.setAnalysisUuid(analysis.getUuid());
db.getDbClient().ceActivityDao().insert(db.getSession(), activityDto);
db.commit();
.containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "public");
ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
assertThat(component)
- .extracting(ComponentDto::getKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate, ComponentDto::getMainBranchProjectUuid)
- .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "PRJ", false, null);
+ .extracting(ComponentDto::getKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate)
+ .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "PRJ", false);
assertThat(db.getDbClient().branchDao().selectByUuid(db.getSession(), component.branchUuid()).get())
.extracting(BranchDto::getKey)