Search in sources :

Example 36 with TestComputationStepContext

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

the class LoadCrossProjectDuplicationsRepositoryStepTest method nothing_to_do_when_no_cpd_text_blocks_found.

@Test
public void nothing_to_do_when_no_cpd_text_blocks_found() {
    when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
    analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
    batchReportReader.putDuplicationBlocks(FILE_REF, Collections.emptyList());
    underTest.execute(new TestComputationStepContext());
    verifyNoInteractions(integrateCrossProjectDuplications);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 37 with TestComputationStepContext

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

the class LoadMeasureComputersStepTest method return_empty_list_when_no_metrics_neither_measure_computers.

@Test
public void return_empty_list_when_no_metrics_neither_measure_computers() {
    ComputationStep underTest = new LoadMeasureComputersStep(holder);
    underTest.execute(new TestComputationStepContext());
    assertThat(holder.getMeasureComputers()).isEmpty();
}
Also used : ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 38 with TestComputationStepContext

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

the class LoadMeasureComputersStepTest method fail_with_IAE_when_creating_measure_computer_definition_without_using_the_builder_and_with_invalid_output_metrics.

@Test
public void fail_with_IAE_when_creating_measure_computer_definition_without_using_the_builder_and_with_invalid_output_metrics() {
    assertThatThrownBy(() -> {
        MeasureComputer measureComputer = new MeasureComputer() {

            @Override
            public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
                // Create a instance of MeasureComputerDefinition without using the builder
                return new MeasureComputer.MeasureComputerDefinition() {

                    @Override
                    public Set<String> getInputMetrics() {
                        return ImmutableSet.of(NCLOC_KEY);
                    }

                    @Override
                    public Set<String> getOutputMetrics() {
                        // Empty output metric is not allowed !
                        return Collections.emptySet();
                    }
                };
            }

            @Override
            public void compute(MeasureComputerContext context) {
            // Nothing needs to be done as we're only testing metada
            }
        };
        MeasureComputer[] computers = new MeasureComputer[] { measureComputer };
        ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
        underTest.execute(new TestComputationStepContext());
    }).isInstanceOf(IllegalArgumentException.class).hasMessage("At least one output metric must be defined");
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 39 with TestComputationStepContext

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

the class LoadMeasureComputersStepTest method fail_with_ISE_when_input_metric_is_unknown.

@Test
public void fail_with_ISE_when_input_metric_is_unknown() {
    assertThatThrownBy(() -> {
        MeasureComputer[] computers = new MeasureComputer[] { newMeasureComputer(array("unknown"), array(NEW_METRIC_4)) };
        ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
        underTest.execute(new TestComputationStepContext());
    }).isInstanceOf(IllegalStateException.class).hasMessage("Metric 'unknown' cannot be used as an input metric as it's not a core metric and no plugin declare this metric");
}
Also used : MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 40 with TestComputationStepContext

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

the class LoadMeasureComputersStepTest method sort_computers_when_one_computer_has_no_input_metric.

@Test
public void sort_computers_when_one_computer_has_no_input_metric() {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(new String[] {}, array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers = new MeasureComputer[] { measureComputer1, measureComputer2, measureComputer3 };
    ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
    underTest.execute(new TestComputationStepContext());
    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
}
Also used : MeasureComputerWrapper(org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper) MeasureComputer(org.sonar.api.ce.measure.MeasureComputer) ComputationStep(org.sonar.ce.task.step.ComputationStep) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

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