Search in sources :

Example 16 with RuleMetadataDto

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

the class ShowActionTest method show_rule_tags.

@Test
public void show_rule_tags() {
    RuleDefinitionDto rule = db.rules().insert();
    RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(rule, setTags("tag1", "tag2"), m -> m.setNoteData(null).setNoteUserUuid(null));
    ShowResponse result = ws.newRequest().setParam(PARAM_KEY, rule.getKey().toString()).executeProtobuf(ShowResponse.class);
    assertThat(result.getRule().getTags().getTagsList()).containsExactly(metadata.getTags().toArray(new String[0]));
}
Also used : ShowResponse(org.sonarqube.ws.Rules.ShowResponse) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 17 with RuleMetadataDto

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

the class SearchActionTest method issue_on_external_adhoc_rule_with_metadata.

@Test
public void issue_on_external_adhoc_rule_with_metadata() {
    ComponentDto project = db.components().insertPublicProject();
    indexPermissions();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo").setIsAdHoc(true));
    RuleMetadataDto ruleMetadata = db.rules().insertOrUpdateMetadata(rule, m -> m.setAdHocName("different_rule_name"));
    IssueDto issue = db.issues().insertIssue(rule, project, file);
    indexIssues();
    SearchWsResponse response = ws.newRequest().setParam("additionalFields", "rules").executeProtobuf(SearchWsResponse.class);
    assertThat(response.getIssuesList()).extracting(Issue::getKey, Issue::getRule, Issue::getExternalRuleEngine).containsExactlyInAnyOrder(tuple(issue.getKey(), rule.getKey().toString(), "xoo"));
    assertThat(response.getRules().getRulesList()).extracting(Common.Rule::getKey, Common.Rule::getName).containsExactlyInAnyOrder(tuple(rule.getKey().toString(), ruleMetadata.getAdHocName()));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Aggregations

RuleMetadataDto (org.sonar.db.rule.RuleMetadataDto)17 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)15 Test (org.junit.Test)13 UserSessionRule (org.sonar.server.tester.UserSessionRule)7 Rule (org.sonarqube.ws.Rules.Rule)7 SearchResponse (org.sonarqube.ws.Rules.SearchResponse)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Rules (org.sonarqube.ws.Rules)3 ShowResponse (org.sonarqube.ws.Rules.ShowResponse)3 RuleType (org.sonar.api.rules.RuleType)2 RuleDto (org.sonar.db.rule.RuleDto)2 Common (org.sonarqube.ws.Common)2 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1