Search in sources :

Example 11 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method sendIssueChangeNotification.

private void sendIssueChangeNotification(long issueCreatedAt) {
    UserDto user = db.users().insertUser();
    ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName());
    analysisMetadataHolder.setProject(Project.from(project));
    ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName());
    treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(project.getDbKey()).setPublicKey(project.getKey()).setName(project.longName()).setUuid(project.uuid()).addChildren(builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build());
    RuleDefinitionDto ruleDefinitionDto = newRule();
    RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)];
    DefaultIssue issue = prepareIssue(issueCreatedAt, user, project, file, ruleDefinitionDto, randomTypeExceptHotspot);
    IssuesChangesNotification issuesChangesNotification = mock(IssuesChangesNotification.class);
    when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true);
    when(notificationFactory.newIssuesChangesNotification(anySet(), anyMap())).thenReturn(issuesChangesNotification);
    underTest.execute(new TestComputationStepContext());
    verify(notificationFactory).newIssuesChangesNotification(issuesSetCaptor.capture(), assigneeByUuidCaptor.capture());
    assertThat(issuesSetCaptor.getValue()).hasSize(1);
    assertThat(issuesSetCaptor.getValue().iterator().next()).isEqualTo(issue);
    assertThat(assigneeByUuidCaptor.getValue()).hasSize(1);
    assertThat(assigneeByUuidCaptor.getValue().get(user.getUuid())).isNotNull();
    verify(notificationService).hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES);
    verify(notificationService).deliverEmails(singleton(issuesChangesNotification));
    verify(notificationService).deliver(issuesChangesNotification);
    verifyNoMoreInteractions(notificationService);
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) RuleType(org.sonar.api.rules.RuleType) DefaultIssue(org.sonar.core.issue.DefaultIssue) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification)

Example 12 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class ComponentDaoTest method selectComponentsFromBranchesThatHaveOpenIssues_returns_nothing_if_no_open_issues_in_sibling_branches.

@Test
public void selectComponentsFromBranchesThatHaveOpenIssues_returns_nothing_if_no_open_issues_in_sibling_branches() {
    final ProjectDto project = db.components().insertPrivateProjectDto(b -> b.setName("foo"));
    ComponentDto branch1 = db.components().insertProjectBranch(project, ComponentTesting.newBranchDto(project.getUuid(), BRANCH).setKey("branch1"));
    ComponentDto fileBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1));
    RuleDefinitionDto rule = db.rules().insert();
    db.issues().insert(new IssueDto().setKee("i").setComponent(fileBranch1).setProject(branch1).setRule(rule).setStatus(STATUS_CLOSED));
    List<KeyWithUuidDto> result = underTest.selectComponentsFromBranchesThatHaveOpenIssues(db.getSession(), singleton(branch1.uuid()));
    assertThat(result).isEmpty();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 13 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class PurgeCommandsTest method deleteIssues_deletes_issue_changes.

@Test
@UseDataProvider("projectsAndViews")
public void deleteIssues_deletes_issue_changes(ComponentDto projectOrView) {
    RuleDefinitionDto rule = dbTester.rules().insert();
    dbTester.components().insertComponent(projectOrView);
    ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
    int count = 5;
    IntStream.range(0, count).forEach(i -> {
        IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
        dbTester.issues().insertChange(issue);
        issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
        dbTester.issues().insertChange(issue);
    });
    underTest.deleteIssues(projectOrView.uuid());
    assertThat(dbTester.countRowsOfTable("ISSUE_CHANGES")).isZero();
}
Also used : IntStream(java.util.stream.IntStream) BranchDto(org.sonar.db.component.BranchDto) Arrays(java.util.Arrays) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) STATUS_PROCESSED(org.sonar.db.component.SnapshotDto.STATUS_PROCESSED) IssueDto(org.sonar.db.issue.IssueDto) PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) GlobalPermission(org.sonar.db.permission.GlobalPermission) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) GroupDto(org.sonar.db.user.GroupDto) DbTester(org.sonar.db.DbTester) CeTaskMessageType(org.sonar.db.ce.CeTaskMessageType) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) AlwaysIncreasingSystem2(org.sonar.api.impl.utils.AlwaysIncreasingSystem2) Test(org.junit.Test) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) Consumer(java.util.function.Consumer) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DuplicationUnitDto(org.sonar.db.duplication.DuplicationUnitDto) ProjectDto(org.sonar.db.project.ProjectDto) IssueTesting.newCodeReferenceIssue(org.sonar.db.issue.IssueTesting.newCodeReferenceIssue) SnapshotDto(org.sonar.db.component.SnapshotDto) Dialect(org.sonar.db.dialect.Dialect) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 14 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class PurgeCommandsTest method deleteIssues_deletes_new_code_reference_issues.

@Test
@UseDataProvider("projectsAndViews")
public void deleteIssues_deletes_new_code_reference_issues(ComponentDto projectOrView) {
    RuleDefinitionDto rule = dbTester.rules().insert();
    dbTester.components().insertComponent(projectOrView);
    ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
    List<String> issueKeys = new ArrayList<>();
    int count = 5;
    IntStream.range(0, count).forEach(i -> {
        IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
        dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
        issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
        dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
        issueKeys.add("'" + issue.getKey() + "'");
    });
    underTest.deleteIssues(projectOrView.uuid());
    assertThat(dbTester.countSql("select count(uuid) from new_code_reference_issues where issue_key in (" + String.join(", ", issueKeys) + ")")).isZero();
}
Also used : IntStream(java.util.stream.IntStream) BranchDto(org.sonar.db.component.BranchDto) Arrays(java.util.Arrays) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) STATUS_PROCESSED(org.sonar.db.component.SnapshotDto.STATUS_PROCESSED) IssueDto(org.sonar.db.issue.IssueDto) PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) GlobalPermission(org.sonar.db.permission.GlobalPermission) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) GroupDto(org.sonar.db.user.GroupDto) DbTester(org.sonar.db.DbTester) CeTaskMessageType(org.sonar.db.ce.CeTaskMessageType) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) AlwaysIncreasingSystem2(org.sonar.api.impl.utils.AlwaysIncreasingSystem2) Test(org.junit.Test) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) Consumer(java.util.function.Consumer) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DuplicationUnitDto(org.sonar.db.duplication.DuplicationUnitDto) ProjectDto(org.sonar.db.project.ProjectDto) IssueTesting.newCodeReferenceIssue(org.sonar.db.issue.IssueTesting.newCodeReferenceIssue) SnapshotDto(org.sonar.db.component.SnapshotDto) Dialect(org.sonar.db.dialect.Dialect) ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class IssueDbTester method insertHotspot.

/**
 * Inserts a Security Hotspot.
 */
@SafeVarargs
public final IssueDto insertHotspot(ComponentDto project, ComponentDto file, Consumer<IssueDto>... populators) {
    RuleDefinitionDto rule = db.rules().insertHotspotRule();
    IssueDto issue = newIssue(rule, project, file).setType(SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setResolution(null);
    stream(populators).forEach(p -> p.accept(issue));
    return insertHotspot(issue);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto)

Aggregations

RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)654 Test (org.junit.Test)583 ComponentDto (org.sonar.db.component.ComponentDto)305 IssueDto (org.sonar.db.issue.IssueDto)219 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)144 UserDto (org.sonar.db.user.UserDto)96 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)93 DbTester (org.sonar.db.DbTester)93 System2 (org.sonar.api.utils.System2)91 UserSessionRule (org.sonar.server.tester.UserSessionRule)84 List (java.util.List)80 Rule (org.junit.Rule)77 DbClient (org.sonar.db.DbClient)68 RuleParamDto (org.sonar.db.rule.RuleParamDto)67 Mockito.mock (org.mockito.Mockito.mock)65 TestRequest (org.sonar.server.ws.TestRequest)64 Consumer (java.util.function.Consumer)63 EsTester (org.sonar.server.es.EsTester)61 Random (java.util.Random)60 RuleType (org.sonar.api.rules.RuleType)60