Search in sources :

Example 11 with QProfileName

use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.

the class QProfileFactoryImplTest method checkAndCreateCustom_throws_BadRequestException_if_name_empty.

@Test
public void checkAndCreateCustom_throws_BadRequestException_if_name_empty() {
    QProfileName name = new QProfileName("xoo", "");
    expectBadRequestException(() -> underTest.checkAndCreateCustom(dbSession, name), "quality_profiles.profile_name_cant_be_blank");
}
Also used : QProfileName(org.sonar.server.qualityprofile.builtin.QProfileName) Test(org.junit.Test)

Example 12 with QProfileName

use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.

the class QProfileFactoryImplTest method checkAndCreateCustom.

@Test
public void checkAndCreateCustom() {
    QProfileDto profile = underTest.checkAndCreateCustom(dbSession, new QProfileName("xoo", "P1"));
    assertThat(profile.getKee()).isNotEmpty();
    assertThat(profile.getName()).isEqualTo("P1");
    assertThat(profile.getLanguage()).isEqualTo("xoo");
    assertThat(profile.getRulesProfileUuid()).isNotNull();
    assertThat(profile.isBuiltIn()).isFalse();
    QProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(dbSession, profile.getName(), profile.getLanguage());
    assertEqual(profile, reloaded);
    assertThat(db.getDbClient().qualityProfileDao().selectAll(dbSession)).extracting(QProfileDto::getKee).containsExactly(profile.getKee());
}
Also used : QProfileName(org.sonar.server.qualityprofile.builtin.QProfileName) OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Test(org.junit.Test)

Example 13 with QProfileName

use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.

the class RegisterQualityProfilesNotificationTest method send_notification_when_a_new_rule_is_activated.

@Test
public void send_notification_when_a_new_rule_is_activated() {
    String language = newLanguageKey();
    RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(language));
    RulesProfileDto dbProfile = insertBuiltInProfile(language);
    activateRuleInDb(dbProfile, existingRule, MAJOR);
    RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(language));
    addPluginProfile(dbProfile, existingRule, newRule);
    builtInQProfileRepositoryRule.initialize();
    underTest.start();
    ArgumentCaptor<Multimap> captor = ArgumentCaptor.forClass(Multimap.class);
    verify(builtInQualityProfilesNotification).onChange(captor.capture(), anyLong(), anyLong());
    Multimap<QProfileName, ActiveRuleChange> updatedProfiles = captor.getValue();
    assertThat(updatedProfiles.keySet()).extracting(QProfileName::getName, QProfileName::getLanguage).containsExactlyInAnyOrder(tuple(dbProfile.getName(), dbProfile.getLanguage()));
    assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(newRule.getUuid(), ACTIVATED));
}
Also used : QProfileName(org.sonar.server.qualityprofile.builtin.QProfileName) Arrays(java.util.Arrays) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) SecureRandom(java.security.SecureRandom) UPDATED(org.sonar.server.qualityprofile.ActiveRuleChange.Type.UPDATED) Collections.singleton(java.util.Collections.singleton) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) Map(java.util.Map) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) RandomUtils.nextLong(org.apache.commons.lang.math.RandomUtils.nextLong) RulePriority(org.sonar.api.rules.RulePriority) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) BuiltInQProfileInsertImpl(org.sonar.server.qualityprofile.builtin.BuiltInQProfileInsertImpl) BuiltInQualityProfilesUpdateListener(org.sonar.server.qualityprofile.builtin.BuiltInQualityProfilesUpdateListener) BuiltInQProfileUpdateImpl(org.sonar.server.qualityprofile.builtin.BuiltInQProfileUpdateImpl) QProfileName(org.sonar.server.qualityprofile.builtin.QProfileName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DbClient(org.sonar.db.DbClient) List(java.util.List) BuiltInQProfileRepositoryRule(org.sonar.server.qualityprofile.builtin.BuiltInQProfileRepositoryRule) MAJOR(org.sonar.api.rules.RulePriority.MAJOR) RuleKey(org.sonar.api.rule.RuleKey) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ACTIVATED(org.sonar.server.qualityprofile.ActiveRuleChange.Type.ACTIVATED) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ServerRuleFinder(org.sonar.server.rule.ServerRuleFinder) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) RuleActivator(org.sonar.server.qualityprofile.builtin.RuleActivator) DEACTIVATED(org.sonar.server.qualityprofile.ActiveRuleChange.Type.DEACTIVATED) Multimap(com.google.common.collect.Multimap) TypeValidations(org.sonar.server.util.TypeValidations) BuiltInQProfileInsert(org.sonar.server.qualityprofile.builtin.BuiltInQProfileInsert) BuiltInQProfileUpdate(org.sonar.server.qualityprofile.builtin.BuiltInQProfileUpdate) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) Severity(org.sonar.api.rule.Severity) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) BuiltInQProfile(org.sonar.server.qualityprofile.builtin.BuiltInQProfile) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) UserSessionRule(org.sonar.server.tester.UserSessionRule) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Assertions.tuple(org.assertj.core.api.Assertions.tuple) BuiltInActiveRule(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule) DefaultRuleFinder(org.sonar.server.rule.DefaultRuleFinder) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RuleIndex(org.sonar.server.rule.index.RuleIndex) QualityProfileTesting.newRuleProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newRuleProfileDto) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Multimap(com.google.common.collect.Multimap) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) Test(org.junit.Test)

Aggregations

QProfileName (org.sonar.server.qualityprofile.builtin.QProfileName)13 Test (org.junit.Test)10 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)9 RuleKey (org.sonar.api.rule.RuleKey)7 Preconditions.checkState (com.google.common.base.Preconditions.checkState)6 Multimap (com.google.common.collect.Multimap)6 SecureRandom (java.security.SecureRandom)6 Arrays (java.util.Arrays)6 Collections.singleton (java.util.Collections.singleton)6 List (java.util.List)6 Map (java.util.Map)6 Random (java.util.Random)6 Consumer (java.util.function.Consumer)6 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)6 RandomUtils.nextLong (org.apache.commons.lang.math.RandomUtils.nextLong)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Assertions.tuple (org.assertj.core.api.Assertions.tuple)6 Rule (org.junit.Rule)6 ArgumentCaptor (org.mockito.ArgumentCaptor)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6