Search in sources :

Example 11 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method do_not_send_global_new_issues_notification_if_issue_has_been_backdated.

@Test
public void do_not_send_global_new_issues_notification_if_issue_has_been_backdated() {
    analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList()));
    protoIssueCache.newAppender().append(createIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close();
    when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true);
    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) Date(java.util.Date) 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 12 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method send_new_issues_notification_to_user.

@Test
public void send_new_issues_notification_to_user() {
    UserDto user = db.users().insertUser();
    analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList()));
    protoIssueCache.newAppender().append(createIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setAssigneeUuid(user.getUuid()).setCreationDate(new Date(ANALYSE_DATE))).close();
    when(notificationService.hasProjectSubscribersForTypes(eq(PROJECT.getUuid()), any())).thenReturn(true);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    verify(notificationService).deliverEmails(ImmutableSet.of(newIssuesNotificationMock));
    verify(notificationService).deliverEmails(ImmutableSet.of(myNewIssuesNotificationMock));
    // old API compatibility call
    verify(notificationService).deliver(newIssuesNotificationMock);
    verify(notificationService).deliver(myNewIssuesNotificationMock);
    verify(myNewIssuesNotificationMock).setAssignee(any(UserDto.class));
    verify(myNewIssuesNotificationMock).setProject(PROJECT.getKey(), PROJECT.getName(), null, null);
    verify(myNewIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
    verify(myNewIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any(NewIssuesStatistics.Stats.class));
    verify(myNewIssuesNotificationMock).setDebt(ISSUE_DURATION);
    verifyStatistics(context, 1, 1, 0);
}
Also used : Project(org.sonar.server.project.Project) UserDto(org.sonar.db.user.UserDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Test(org.junit.Test)

Example 13 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class TriggerViewRefreshStepTest method execute_calls_delegate_with_project_from_holder_if_passed_to_constructor.

@Test
public void execute_calls_delegate_with_project_from_holder_if_passed_to_constructor() {
    TriggerViewRefreshDelegate delegate = mock(TriggerViewRefreshDelegate.class);
    Project project = mock(Project.class);
    when(analysisMetadataHolder.getProject()).thenReturn(project);
    TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder, new TriggerViewRefreshDelegate[] { delegate });
    underTest.execute(new TestComputationStepContext());
    verify(analysisMetadataHolder).getProject();
    verify(delegate).triggerFrom(project);
}
Also used : Project(org.sonar.server.project.Project) TriggerViewRefreshDelegate(org.sonar.ce.task.projectanalysis.view.TriggerViewRefreshDelegate) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 14 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class LoadPeriodsStepTest method setupRoot.

private void setupRoot(ComponentDto projectDto, String version) {
    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(projectDto.uuid()).setKey(projectDto.getKey()).setProjectVersion(version).build());
    Project project = mock(Project.class);
    when(project.getUuid()).thenReturn(projectDto.getMainBranchProjectUuid() != null ? projectDto.getMainBranchProjectUuid() : projectDto.uuid());
    when(analysisMetadataHolder.getProject()).thenReturn(project);
}
Also used : Project(org.sonar.server.project.Project)

Example 15 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class QualityGateEventsStepTest method setUp.

@Before
public void setUp() {
    when(metricRepository.getByKey(ALERT_STATUS_KEY)).thenReturn(alertStatusMetric);
    analysisMetadataHolder.setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getDbKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList()));
    analysisMetadataHolder.setBranch(mock(Branch.class));
    treeRootHolder.setRoot(PROJECT_COMPONENT);
}
Also used : Project(org.sonar.server.project.Project) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Before(org.junit.Before)

Aggregations

Project (org.sonar.server.project.Project)26 Test (org.junit.Test)21 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)14 ComponentDto (org.sonar.db.component.ComponentDto)14 Before (org.junit.Before)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 Rule (org.junit.Rule)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 DbTester (org.sonar.db.DbTester)11 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)10 Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)10 BranchType (org.sonar.db.component.BranchType)10 Date (java.util.Date)9 Notification (org.sonar.api.notifications.Notification)8 UserDto (org.sonar.db.user.UserDto)8 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)8 MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)8 NewIssuesNotification (org.sonar.server.issue.notification.NewIssuesNotification)8 System2 (org.sonar.api.utils.System2)6