Search in sources :

Example 66 with TestComputationStepContext

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

the class PersistProjectLinksStepTest method no_effect_if_branch_is_not_main.

@Test
public void no_effect_if_branch_is_not_main() {
    DbClient dbClient = mock(DbClient.class);
    TreeRootHolder treeRootHolder = mock(TreeRootHolder.class);
    BatchReportReader reportReader = mock(BatchReportReader.class);
    UuidFactory uuidFactory = mock(UuidFactory.class);
    mockBranch(false);
    PersistProjectLinksStep underTest = new PersistProjectLinksStep(analysisMetadataHolder, dbClient, treeRootHolder, reportReader, uuidFactory);
    underTest.execute(new TestComputationStepContext());
    verifyZeroInteractions(uuidFactory, reportReader, treeRootHolder, dbClient);
}
Also used : DbClient(org.sonar.db.DbClient) UuidFactory(org.sonar.core.util.UuidFactory) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) BatchReportReader(org.sonar.ce.task.projectanalysis.batch.BatchReportReader) Test(org.junit.Test)

Example 67 with TestComputationStepContext

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

the class PersistProjectLinksStepTest method nothing_to_do_when_link_already_exists.

@Test
public void nothing_to_do_when_link_already_exists() {
    mockBranch(true);
    ComponentDto project = db.components().insertPrivateProject(p -> p.setUuid("ABCD"));
    db.componentLinks().insertProvidedLink(project, l -> l.setType("homepage").setName("Home").setHref("http://www.sonarqube.org"));
    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(1).setType(ComponentType.PROJECT).addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()).build());
    underTest.execute(new TestComputationStepContext());
    assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")).extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref).containsExactlyInAnyOrder(tuple("homepage", "http://www.sonarqube.org"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 68 with TestComputationStepContext

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

the class QualityGateMeasuresStepTest method new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst.

@Test
public void new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst() {
    int rawValue = 3;
    Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition periodCondition = createLessThanCondition(INT_METRIC_1, "2");
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
    Measure measure = newMeasureBuilder().create(rawValue, null);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure);
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
    assertThat(rawMeasure1.get()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(fixedCondition, ERROR, rawValue));
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) Test(org.junit.Test)

Example 69 with TestComputationStepContext

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

the class QualityGateMeasuresStepTest method no_measure_if_there_is_no_qualitygate.

@Test
public void no_measure_if_there_is_no_qualitygate() {
    qualityGateHolder.setQualityGate(null);
    underTest.execute(new TestComputationStepContext());
    measureRepository.getAddedRawMeasures(PROJECT_COMPONENT).isEmpty();
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 70 with TestComputationStepContext

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

the class QualityGateMeasuresStepTest method new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level.

@Test
public void new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level() {
    int rawValue = 3;
    Condition equalsOneErrorCondition = createLessThanCondition(INT_METRIC_1, "4");
    Condition equalsOneOkCondition = createLessThanCondition(INT_METRIC_2, "2");
    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition)));
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
    underTest.execute(new TestComputationStepContext());
    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
    Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY);
    assertThat(rawMeasure1.get()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue));
    assertThat(rawMeasure2.get()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getAlertStatusMeasure()).hasQualityGateLevel(ERROR).hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue) + ", " + dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
    assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(ERROR, of(new EvaluatedCondition(equalsOneErrorCondition, ERROR, rawValue), new EvaluatedCondition(equalsOneOkCondition, OK, rawValue)), false).toJson());
    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.ERROR).hasConditionCount(2).hasCondition(equalsOneErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue)).hasCondition(equalsOneOkCondition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
}
Also used : EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.ce.task.projectanalysis.qualitygate.Condition) QualityGateDetailsData(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) EvaluatedCondition(org.sonar.ce.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) QualityGate(org.sonar.ce.task.projectanalysis.qualitygate.QualityGate) 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