Search in sources :

Example 51 with TestComputationStepContext

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

the class SendIssueNotificationsStepTest method do_not_send_notifications_if_no_subscribers.

@Test
public void do_not_send_notifications_if_no_subscribers() {
    analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList()));
    when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(false);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    verify(notificationService, never()).deliver(any(Notification.class));
    verify(notificationService, never()).deliverEmails(anyCollection());
    verifyStatistics(context, 0, 0, 0);
}
Also used : Project(org.sonar.server.project.Project) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) Notification(org.sonar.api.notifications.Notification) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Test(org.junit.Test)

Example 52 with TestComputationStepContext

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

the class LoadReportAnalysisMetadataHolderStepTest method set_cross_project_duplication_to_true.

@Test
public void set_cross_project_duplication_to_true() {
    reportReader.setMetadata(newBatchReportBuilder().setCrossProjectDuplicationActivated(true).build());
    underTest.execute(new TestComputationStepContext());
    assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isTrue();
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 53 with TestComputationStepContext

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

the class LoadReportAnalysisMetadataHolderStepTest method set_analysis_date.

@Test
public void set_analysis_date() {
    reportReader.setMetadata(newBatchReportBuilder().setAnalysisDate(ANALYSIS_DATE).build());
    underTest.execute(new TestComputationStepContext());
    assertThat(analysisMetadataHolder.getAnalysisDate()).isEqualTo(ANALYSIS_DATE);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 54 with TestComputationStepContext

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

the class LoadReportAnalysisMetadataHolderStepTest method execute_fails_with_MessageException_if_main_projectKey_is_null_in_CE_task.

@Test
public void execute_fails_with_MessageException_if_main_projectKey_is_null_in_CE_task() {
    CeTask res = mock(CeTask.class);
    Optional<CeTask.Component> component = Optional.of(new CeTask.Component("main_prj_uuid", null, null));
    when(res.getComponent()).thenReturn(component);
    when(res.getMainComponent()).thenReturn(component);
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
    ComputationStep underTest = createStep(res);
    assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())).isInstanceOf(MessageException.class).hasMessage("Compute Engine task main component key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
}
Also used : MessageException(org.sonar.api.utils.MessageException) ComputationStep(org.sonar.ce.task.step.ComputationStep) CeTask(org.sonar.ce.task.CeTask) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 55 with TestComputationStepContext

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

the class LoadReportAnalysisMetadataHolderStepTest method execute_sets_branch_even_if_MessageException_is_thrown_because_projectKey_in_report_is_different_from_componentKey_in_CE_task.

@Test
public void execute_sets_branch_even_if_MessageException_is_thrown_because_projectKey_in_report_is_different_from_componentKey_in_CE_task() {
    ComponentDto otherProject = db.components().insertPublicProject();
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().setProjectKey(otherProject.getDbKey()).build());
    try {
        underTest.execute(new TestComputationStepContext());
    } catch (MessageException e) {
        assertThat(analysisMetadataHolder.getBranch()).isNotNull();
    }
}
Also used : MessageException(org.sonar.api.utils.MessageException) ComponentDto(org.sonar.db.component.ComponentDto) 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