Search in sources :

Example 1 with TreeRootHolder

use of org.sonar.ce.task.projectanalysis.component.TreeRootHolder 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 2 with TreeRootHolder

use of org.sonar.ce.task.projectanalysis.component.TreeRootHolder in project sonarqube by SonarSource.

the class PersistComponentsStepTest method should_fail_if_project_is_not_stored_in_database_yet.

@Test
public void should_fail_if_project_is_not_stored_in_database_yet() {
    TreeRootHolder treeRootHolder = mock(TreeRootHolder.class);
    Component component = mock(Component.class);
    DbClient dbClient = mock(DbClient.class);
    ComponentDao componentDao = mock(ComponentDao.class);
    String projectKey = randomAlphabetic(20);
    doReturn(component).when(treeRootHolder).getRoot();
    doReturn(projectKey).when(component).getDbKey();
    doReturn(componentDao).when(dbClient).componentDao();
    doReturn(emptyList()).when(componentDao).selectAllComponentsFromProjectKey(any(DbSession.class), eq(projectKey));
    assertThatThrownBy(() -> {
        new PersistComponentsStep(dbClient, treeRootHolder, System2.INSTANCE, mock(MutableDisabledComponentsHolder.class), mock(AnalysisMetadataHolder.class), mock(BranchPersister.class), mock(ProjectPersister.class)).execute(new TestComputationStepContext());
    }).isInstanceOf(IllegalStateException.class).hasMessageContaining("The project '" + projectKey + "' is not stored in the database, during a project analysis");
}
Also used : DbSession(org.sonar.db.DbSession) DbClient(org.sonar.db.DbClient) Component(org.sonar.ce.task.projectanalysis.component.Component) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) ComponentDao(org.sonar.db.component.ComponentDao) Test(org.junit.Test)

Example 3 with TreeRootHolder

use of org.sonar.ce.task.projectanalysis.component.TreeRootHolder in project sonarqube by SonarSource.

the class QualityGateEventsStepTest method no_alert_on_pull_request_branches.

@Test
public void no_alert_on_pull_request_branches() {
    Branch pr = mock(Branch.class);
    when(pr.getType()).thenReturn(BranchType.PULL_REQUEST);
    analysisMetadataHolder.setBranch(pr);
    TreeRootHolder treeRootHolder = mock(TreeRootHolder.class);
    MetricRepository metricRepository = mock(MetricRepository.class);
    MeasureRepository measureRepository = mock(MeasureRepository.class);
    EventRepository eventRepository = mock(EventRepository.class);
    NotificationService notificationService = mock(NotificationService.class);
    QualityGateEventsStep underTest = new QualityGateEventsStep(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService, analysisMetadataHolder);
    underTest.execute(new TestComputationStepContext());
    verifyZeroInteractions(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService);
}
Also used : MeasureRepository(org.sonar.ce.task.projectanalysis.measure.MeasureRepository) MetricRepository(org.sonar.ce.task.projectanalysis.metric.MetricRepository) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) EventRepository(org.sonar.ce.task.projectanalysis.event.EventRepository) NotificationService(org.sonar.server.notification.NotificationService) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 TreeRootHolder (org.sonar.ce.task.projectanalysis.component.TreeRootHolder)3 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 DbClient (org.sonar.db.DbClient)2 Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)1 BatchReportReader (org.sonar.ce.task.projectanalysis.batch.BatchReportReader)1 Component (org.sonar.ce.task.projectanalysis.component.Component)1 EventRepository (org.sonar.ce.task.projectanalysis.event.EventRepository)1 MeasureRepository (org.sonar.ce.task.projectanalysis.measure.MeasureRepository)1 MetricRepository (org.sonar.ce.task.projectanalysis.metric.MetricRepository)1 UuidFactory (org.sonar.core.util.UuidFactory)1 DbSession (org.sonar.db.DbSession)1 ComponentDao (org.sonar.db.component.ComponentDao)1 NotificationService (org.sonar.server.notification.NotificationService)1