Search in sources :

Example 6 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class EnableAnalysisStepTest method switch_islast_flag_and_mark_analysis_as_processed.

@Test
public void switch_islast_flag_and_mark_analysis_as_processed() {
    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();
    treeRootHolder.setRoot(REPORT_PROJECT);
    analysisMetadataHolder.setUuid(CURRENT_ANALYSIS_UUID);
    underTest.execute(new TestComputationStepContext());
    verifyAnalysis(PREVIOUS_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, false);
    verifyAnalysis(CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, true);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 7 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class BuildComponentTreeStepTest method verify_tree_is_correctly_built.

@Test
public void verify_tree_is_correctly_built() {
    setAnalysisMetadataHolder();
    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF, FILE_2_REF, FILE_3_REF));
    reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
    reportReader.putComponent(componentWithPath(FILE_2_REF, FILE, REPORT_FILE_PATH_2));
    reportReader.putComponent(componentWithPath(FILE_3_REF, FILE, REPORT_FILE_PATH_3));
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    Component root = treeRootHolder.getRoot();
    assertThat(root).isNotNull();
    verifyComponent(root, Component.Type.PROJECT, ROOT_REF, 1);
    Component dir = root.getChildren().iterator().next();
    verifyComponent(dir, Component.Type.DIRECTORY, null, 2);
    Component dir1 = dir.getChildren().get(0);
    verifyComponent(dir1, Component.Type.DIRECTORY, null, 1);
    verifyComponent(dir1.getChildren().get(0), Component.Type.FILE, FILE_1_REF, 0);
    Component dir2 = dir.getChildren().get(1);
    verifyComponent(dir2, Component.Type.DIRECTORY, null, 2);
    verifyComponent(dir2.getChildren().get(0), Component.Type.FILE, FILE_2_REF, 0);
    verifyComponent(dir2.getChildren().get(1), Component.Type.FILE, FILE_3_REF, 0);
    context.getStatistics().assertValue("components", 7);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 8 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class BuildComponentTreeStepTest method generate_keys_when_using_new_branch.

@Test
public void generate_keys_when_using_new_branch() {
    Branch branch = mock(Branch.class);
    when(branch.getName()).thenReturn("origin/feature");
    when(branch.isMain()).thenReturn(false);
    when(branch.generateKey(any(), any())).thenReturn("generated");
    analysisMetadataHolder.setRootComponentRef(ROOT_REF).setAnalysisDate(ANALYSIS_DATE).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));
    reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
    underTest.execute(new TestComputationStepContext());
    verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null);
    verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated", REPORT_DIR_PATH_1);
    verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 9 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class BuildComponentTreeStepTest method fails_if_root_component_does_not_exist_in_reportReader.

@Test
public void fails_if_root_component_does_not_exist_in_reportReader() {
    setAnalysisMetadataHolder();
    assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())).isInstanceOf(NullPointerException.class);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 10 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class BuildComponentTreeStepTest method set_buildString.

@Test
@UseDataProvider("oneParameterNullNonNullCombinations")
public void set_buildString(@Nullable String buildString) {
    String projectVersion = randomAlphabetic(7);
    setAnalysisMetadataHolder();
    reportReader.setMetadata(createReportMetadata(projectVersion, buildString));
    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
    underTest.execute(new TestComputationStepContext());
    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getBuildString()).isEqualTo(Optional.ofNullable(buildString));
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)458 Test (org.junit.Test)431 ComponentDto (org.sonar.db.component.ComponentDto)91 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)38 Component (org.sonar.ce.task.projectanalysis.component.Component)38 SnapshotDto (org.sonar.db.component.SnapshotDto)31 Date (java.util.Date)30 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)28 ComputationStep (org.sonar.ce.task.step.ComputationStep)24 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)17 FileSourceDto (org.sonar.db.source.FileSourceDto)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Project (org.sonar.server.project.Project)14 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)13 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)13 Notification (org.sonar.api.notifications.Notification)12 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)11 IssueDto (org.sonar.db.issue.IssueDto)11 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)11