Search in sources :

Example 31 with ReportComponent

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

the class NotificationFactoryTest method newIssuesChangesNotification_creates_assignee_from_UserDto.

@Test
public void newIssuesChangesNotification_creates_assignee_from_UserDto() {
    RuleKey ruleKey = RuleKey.of("foo", "bar");
    String assigneeUuid = randomAlphabetic(40);
    DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN).setAssigneeUuid(assigneeUuid);
    UserDto userDto = UserTesting.newUserDto();
    Map<String, UserDto> assigneesByUuid = ImmutableMap.of(assigneeUuid, userDto);
    ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
    ruleRepository.add(ruleKey);
    treeRootHolder.setRoot(project);
    analysisMetadata.setAnalysisDate(new Random().nextLong());
    analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, randomAlphabetic(12)));
    IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
    when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
    IssuesChangesNotification notification = underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid);
    assertThat(notification).isSameAs(expected);
    IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
    assertThat(builder.getIssues()).hasSize(1);
    ChangedIssue changeIssue = builder.getIssues().iterator().next();
    assertThat(changeIssue.getAssignee()).isPresent();
    IssuesChangesNotificationBuilder.User assignee = changeIssue.getAssignee().get();
    assertThat(assignee.getUuid()).isEqualTo(userDto.getUuid());
    assertThat(assignee.getName()).contains(userDto.getName());
    assertThat(assignee.getLogin()).isEqualTo(userDto.getLogin());
}
Also used : Random(java.util.Random) RuleKey(org.sonar.api.rule.RuleKey) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) UserDto(org.sonar.db.user.UserDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Test(org.junit.Test)

Example 32 with ReportComponent

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

the class SourceLinesHashCacheTest method get_throws_ISE_if_not_cached.

@Test
public void get_throws_ISE_if_not_cached() {
    Component component = createComponent(1);
    assertThatThrownBy(() -> underTest.get(component)).isInstanceOf(IllegalStateException.class).hasMessage("Source line hashes for component ReportComponent{ref=1, key='FILE_KEY', type=FILE} not cached");
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 33 with ReportComponent

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

the class PersistFileSourcesStepTest method initBasicReport.

private void initBasicReport(int numberOfLines) {
    ReportComponent root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(fileComponent().setFileAttributes(new FileAttributes(false, null, numberOfLines)).build()).build();
    treeRootHolder.setRoots(root, root);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes)

Example 34 with ReportComponent

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

the class NotificationFactoryTest method newIssuesChangesNotification_creates_project_from_TreeRootHolder_and_branch_name_from_branch.

@Test
public void newIssuesChangesNotification_creates_project_from_TreeRootHolder_and_branch_name_from_branch() {
    RuleKey ruleKey = RuleKey.of("foo", "bar");
    DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN);
    Map<String, UserDto> assigneesByUuid = nonEmptyAssigneesByUuid();
    ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
    String branchName = randomAlphabetic(12);
    ruleRepository.add(ruleKey);
    treeRootHolder.setRoot(project);
    analysisMetadata.setAnalysisDate(new Random().nextLong());
    analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, branchName));
    IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
    when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
    IssuesChangesNotification notification = underTest.newIssuesChangesNotification(ImmutableSet.of(issue), assigneesByUuid);
    assertThat(notification).isSameAs(expected);
    IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
    assertThat(builder.getIssues()).hasSize(1);
    ChangedIssue changeIssue = builder.getIssues().iterator().next();
    assertThat(changeIssue.getProject().getUuid()).isEqualTo(project.getUuid());
    assertThat(changeIssue.getProject().getKey()).isEqualTo(project.getKey());
    assertThat(changeIssue.getProject().getProjectName()).isEqualTo(project.getName());
    assertThat(changeIssue.getProject().getBranchName()).contains(branchName);
}
Also used : Random(java.util.Random) RuleKey(org.sonar.api.rule.RuleKey) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) UserDto(org.sonar.db.user.UserDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Test(org.junit.Test)

Example 35 with ReportComponent

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

the class FileSourceDataWarningsTest method create_highlighting_warning_when_any_number_of_read_error_for_one_file.

@Test
public void create_highlighting_warning_when_any_number_of_read_error_for_one_file() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setUuid("uuid").setName(path).build();
    LineReader.ReadError[] readErrors = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> new LineReader.ReadError(HIGHLIGHTING, line + i)).toArray(LineReader.ReadError[]::new);
    when(system2.now()).thenReturn(timeStamp);
    Arrays.stream(readErrors).forEach(readError -> underTest.addWarning(file, readError));
    verifyZeroInteractions(taskMessages);
    underTest.commitWarnings();
    verify(taskMessages, times(1)).add(new CeTaskMessages.Message("Inconsistent highlighting data detected on file '" + path + "'. " + "File source may have been modified while analysis was running.", timeStamp));
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.task.projectanalysis.component.Component) Arrays(java.util.Arrays) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) SYMBOLS(org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.SYMBOLS) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) HIGHLIGHTING(org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.HIGHLIGHTING) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Mockito.mock(org.mockito.Mockito.mock) CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)48 Test (org.junit.Test)46 DefaultIssue (org.sonar.core.issue.DefaultIssue)16 Random (java.util.Random)10 RuleKey (org.sonar.api.rule.RuleKey)7 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)7 UserDto (org.sonar.db.user.UserDto)7 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)6 IssuesChangesNotificationBuilder (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 LineReader (org.sonar.ce.task.projectanalysis.source.linereader.LineReader)5 ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)5 IntStream (java.util.stream.IntStream)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.verify (org.mockito.Mockito.verify)4 Mockito.when (org.mockito.Mockito.when)4 CeTaskMessages (org.sonar.ce.task.log.CeTaskMessages)4 Component (org.sonar.ce.task.projectanalysis.component.Component)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)3