Search in sources :

Example 1 with PARAM_ACTIVATION

use of org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVATION in project sonarqube by SonarSource.

the class SearchActionTest method compare_to_another_profile.

@Test
public void compare_to_another_profile() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(JAVA));
    QProfileDto anotherProfile = db.qualityProfiles().insert(p -> p.setLanguage(JAVA));
    RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
    RuleDefinitionDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
    RuleDefinitionDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
    RuleDefinitionDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
    RuleDefinitionDto anotherProfileRule1 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
    RuleDefinitionDto anotherProfileRule2 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
    db.qualityProfiles().activateRule(profile, commonRule);
    db.qualityProfiles().activateRule(profile, profileRule1);
    db.qualityProfiles().activateRule(profile, profileRule2);
    db.qualityProfiles().activateRule(profile, profileRule3);
    db.qualityProfiles().activateRule(anotherProfile, commonRule);
    db.qualityProfiles().activateRule(anotherProfile, anotherProfileRule1);
    db.qualityProfiles().activateRule(anotherProfile, anotherProfileRule2);
    indexRules();
    indexActiveRules();
    SearchResponse result = ws.newRequest().setParam(PARAM_QPROFILE, profile.getKee()).setParam(PARAM_ACTIVATION, "false").setParam(PARAM_COMPARE_TO_PROFILE, anotherProfile.getKee()).executeProtobuf(SearchResponse.class);
    assertThat(result.getRulesList()).extracting(Rule::getKey).containsExactlyInAnyOrder(anotherProfileRule1.getKey().toString(), anotherProfileRule2.getKey().toString());
}
Also used : RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) Rules(org.sonarqube.ws.Rules) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) Collections.singleton(java.util.Collections.singleton) Assertions.entry(org.assertj.guava.api.Assertions.entry) BLOCKER(org.sonar.api.rule.Severity.BLOCKER) Arrays.asList(java.util.Arrays.asList) DebtRemediationFunction(org.sonar.api.server.debt.DebtRemediationFunction) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) RuleTesting.setSystemTags(org.sonar.db.rule.RuleTesting.setSystemTags) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Mockito.doReturn(org.mockito.Mockito.doReturn) Rule(org.sonarqube.ws.Rules.Rule) DbTester(org.sonar.db.DbTester) QProfileRulesImpl(org.sonar.server.qualityprofile.QProfileRulesImpl) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) System2(org.sonar.api.utils.System2) AlwaysIncreasingSystem2(org.sonar.api.impl.utils.AlwaysIncreasingSystem2) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) Collectors(java.util.stream.Collectors) NotFoundException(org.sonar.server.exceptions.NotFoundException) Common(org.sonarqube.ws.Common) QProfileRules(org.sonar.server.qualityprofile.QProfileRules) RuleTesting.setTags(org.sonar.db.rule.RuleTesting.setTags) List(java.util.List) LanguageTesting(org.sonar.server.language.LanguageTesting) RuleKey(org.sonar.api.rule.RuleKey) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) SearchResponse(org.sonarqube.ws.Rules.SearchResponse) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) RuleActivator(org.sonar.server.qualityprofile.builtin.RuleActivator) RuleStatus(org.sonar.api.rule.RuleStatus) PARAM_ACTIVATION(org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVATION) TypeValidations(org.sonar.server.util.TypeValidations) RuleType(org.sonar.api.rules.RuleType) HashSet(java.util.HashSet) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Extractor(org.assertj.core.api.iterable.Extractor) IntegerTypeValidation(org.sonar.server.util.IntegerTypeValidation) PARAM_COMPARE_TO_PROFILE(org.sonar.server.rule.ws.RulesWsParameters.PARAM_COMPARE_TO_PROFILE) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Before(org.junit.Before) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) UserSessionRule(org.sonar.server.tester.UserSessionRule) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PARAM_QPROFILE(org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE) MacroInterpreter(org.sonar.server.text.MacroInterpreter) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) RuleIndex(org.sonar.server.rule.index.RuleIndex) WsActionTester(org.sonar.server.ws.WsActionTester) PARAM_RULE_KEY(org.sonar.server.rule.ws.RulesWsParameters.PARAM_RULE_KEY) Consumer(java.util.function.Consumer) RuleParamDto(org.sonar.db.rule.RuleParamDto) StringTypeValidation(org.sonar.server.util.StringTypeValidation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchResponse(org.sonarqube.ws.Rules.SearchResponse) Test(org.junit.Test)

Aggregations

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 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Extractor (org.assertj.core.api.iterable.Extractor)1 Assertions.entry (org.assertj.guava.api.Assertions.entry)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 Mockito.mock (org.mockito.Mockito.mock)1 AlwaysIncreasingSystem2 (org.sonar.api.impl.utils.AlwaysIncreasingSystem2)1