Package org.sonar.core.qualityprofile.db

Examples of org.sonar.core.qualityprofile.db.QualityProfileDto


    assertThat(rule.params().get("min")).isEqualTo("minimum");
  }

  @Test
  public void find_active_rules() throws Exception {
    QualityProfileDto profile1 = QProfileTesting.newXooP1();
    QualityProfileDto profile2 = QProfileTesting.newXooP2();
    db.qualityProfileDao().insert(dbSession, profile1, profile2);

    RuleDto rule1 = RuleTesting.newXooX1().setSeverity(Severity.MAJOR);
    RuleDto rule2 = RuleTesting.newXooX2().setSeverity(Severity.MAJOR);
    RuleDto removedRule = RuleTesting.newDto(RuleKey.of("xoo", "removed")).setSeverity(Severity.MAJOR).setStatus(RuleStatus.REMOVED);
    db.ruleDao().insert(dbSession, rule1, rule2, removedRule);

    db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR));
    db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER));
    db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL));
    // Removed rule can still be activated for instance when removing the checkstyle plugin, active rules related on checkstyle are not removed
    // because if the plugin is re-install, quality profiles using these rule are not changed.
    db.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, removedRule).setSeverity(Severity.MAJOR));
    dbSession.commit();

    // 1. find by rule key

    // in db
    dbSession.clearCache();
    assertThat(db.activeRuleDao().findByRule(dbSession, rule1)).hasSize(1);
    assertThat(db.activeRuleDao().findByRule(dbSession, rule2)).hasSize(2);

    // in es
    List<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X1);
    assertThat(activeRules).hasSize(1);
    assertThat(activeRules.get(0).key().ruleKey()).isEqualTo(RuleTesting.XOO_X1);

    activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X2);
    assertThat(activeRules).hasSize(2);
    assertThat(activeRules.get(0).key().ruleKey()).isEqualTo(RuleTesting.XOO_X2);

    activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X3);
    assertThat(activeRules).isEmpty();

    // 2. find by profile
    activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile1.getKey());
    assertThat(activeRules).hasSize(2);
    assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile1.getKey());
    assertThat(activeRules.get(1).key().qProfile()).isEqualTo(profile1.getKey());

    activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile2.getKey());
    assertThat(activeRules).hasSize(1);
    assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile2.getKey());

    activeRules = index.get(ActiveRuleIndex.class).findByProfile("unknown");
    assertThat(activeRules).isEmpty();
  }
View Full Code Here


  }

  @Test
  public void find_many_active_rules_by_profile() {
    // insert and index
    QualityProfileDto profileDto = QProfileTesting.newXooP1();
    db.qualityProfileDao().insert(dbSession, profileDto);
    int nb = 100;
    for (int i = 0; i < nb; i++) {
      RuleDto rule = newRuleDto(RuleKey.of("xoo", "S00" + i));
      db.ruleDao().insert(dbSession, rule);

      ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, rule).setSeverity(Severity.MAJOR);
      db.activeRuleDao().insert(dbSession, activeRule);
    }
    dbSession.commit();
    dbSession.clearCache();

    // verify index
    Collection<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey());
    assertThat(activeRules).hasSize(nb);
  }
View Full Code Here

    assertThat(activeRules).hasSize(nb);
  }

  @Test
  public void count_by_profile() {
    QualityProfileDto profileDto1 = QProfileTesting.newXooP1();
    QualityProfileDto profileDto2 = QProfileTesting.newXooP2();
    db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);

    RuleKey ruleKey = RuleTesting.XOO_X1;
    RuleDto ruleDto = newRuleDto(ruleKey);
    db.ruleDao().insert(dbSession, ruleDto);

    ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR);
    ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR);
    db.activeRuleDao().insert(dbSession, activeRule1, activeRule2);
    dbSession.commit();

    // 0. Test base case
    assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(2);

    // 1. Assert by profileKey
    assertThat(index.get(ActiveRuleIndex.class).countByQualityProfileKey(profileDto1.getKey())).isEqualTo(1);

    // 2. Assert by term aggregation;
    Map<String, Long> counts = index.get(ActiveRuleIndex.class).countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
    assertThat(counts).hasSize(2);
    assertThat(counts.values()).containsOnly(1L, 1L);
    assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString());
  }
View Full Code Here

    assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString());
  }

  @Test
  public void count_all_by_index_field() {
    QualityProfileDto profileDto1 = QProfileTesting.newXooP1();
    QualityProfileDto profileDto2 = QProfileTesting.newXooP2();
    db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);

    RuleKey ruleKey = RuleTesting.XOO_X1;
    RuleDto ruleDto = newRuleDto(ruleKey);
    db.ruleDao().insert(dbSession, ruleDto);

    ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR);
    ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR);
    db.activeRuleDao().insert(dbSession, activeRule1, activeRule2);
    dbSession.commit();

    // 0. Test base case
    assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(2);

    // 1. Assert by term aggregation;
    Map<String, Long> counts = index.get(ActiveRuleIndex.class).countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
    assertThat(counts).hasSize(2);
    assertThat(counts.values()).containsOnly(1L, 1L);
    assertThat(counts.keySet()).containsOnly(profileDto1.getKey(), profileDto2.getKey());
  }
View Full Code Here

    assertThat(counts.keySet()).containsOnly(profileDto1.getKey(), profileDto2.getKey());
  }

  @Test
  public void stats_for_all() {
    QualityProfileDto profileDto1 = QProfileTesting.newXooP1();
    QualityProfileDto profileDto2 = QProfileTesting.newXooP2();
    db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);

    RuleDto ruleDto1 = newRuleDto(RuleTesting.XOO_X1);
    RuleDto ruleDto2 = newRuleDto(RuleTesting.XOO_X2);
    db.ruleDao().insert(dbSession, ruleDto1, ruleDto2);

    db.activeRuleDao().insert(dbSession,
      ActiveRuleDto.createFor(profileDto1, ruleDto1)
        .setInheritance(ActiveRule.Inheritance.INHERITED.name())
        .setSeverity(Severity.BLOCKER),
      ActiveRuleDto.createFor(profileDto2, ruleDto1)
        .setInheritance(ActiveRule.Inheritance.INHERITED.name())
        .setSeverity(Severity.MINOR),
      ActiveRuleDto.createFor(profileDto1, ruleDto2)
        .setInheritance(ActiveRule.Inheritance.OVERRIDES.name())
        .setSeverity(Severity.MAJOR),
      ActiveRuleDto.createFor(profileDto2, ruleDto2)
        .setInheritance(ActiveRule.Inheritance.INHERITED.name())
        .setSeverity(Severity.BLOCKER)
    );
    dbSession.commit();
    dbSession.clearCache();

    // 0. Test base case
    assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(4);

    // 1. Assert by term aggregation;
    Map<String, Multimap<String, FacetValue>> stats = index.get(ActiveRuleIndex.class).getStatsByProfileKeys(
      ImmutableList.of(profileDto1.getKey(),
        profileDto2.getKey()));

    assertThat(stats).hasSize(2);
  }
View Full Code Here

    RuleDto ruleDto2 = newRuleDto(RuleTesting.XOO_X2);
    db.ruleDao().insert(dbSession, ruleDto1, ruleDto2);

    List<String> profileKeys = newArrayList();
    for (int i = 0; i<30; i++) {
      QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor("xoo", "profile-" + i), "profile-" + i);
      profileKeys.add(profileDto.getKey());
      db.qualityProfileDao().insert(dbSession, profileDto);

      db.activeRuleDao().insert(dbSession,
        ActiveRuleDto.createFor(profileDto, ruleDto1)
          .setSeverity(Severity.BLOCKER),
View Full Code Here

    // copy child -> profile2 is created with parent P1
    copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName());

    verifyOneActiveRule(QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
    QualityProfileDto profile2Dto = db.qualityProfileDao().getByKey(dbSession, QProfileTesting.XOO_P2_KEY);
    assertThat(profile2Dto.getParentKee()).isEqualTo(QProfileTesting.XOO_P1_KEY);
  }
View Full Code Here

    }
  }

  private void verifyOneActiveRule(QProfileName profileName, String expectedSeverity,
    @Nullable String expectedInheritance, Map<String, String> expectedParams) {
    QualityProfileDto dto = db.qualityProfileDao().getByNameAndLanguage(profileName.getName(), profileName.getLanguage());
    verifyOneActiveRule(dto.getKey(), expectedSeverity, expectedInheritance, expectedParams);
  }
View Full Code Here

    String propertyKey = "sonar.profile." + language;
    boolean upToDate = false;
    String currentDefault = settings.getString(propertyKey);
    if (currentDefault != null) {
      // check validity
      QualityProfileDto profile = dbClient.qualityProfileDao().getByNameAndLanguage(currentDefault, language, session);
      if (profile != null) {
        upToDate = true;
      }
    }
View Full Code Here

    DbSession dbSession = db.openSession(false);
    try {
      ListMultimap<QProfileName, RulesProfile> profilesByName = loadDefinitionsGroupedByName(language);
      for (Map.Entry<QProfileName, Collection<RulesProfile>> entry : profilesByName.asMap().entrySet()) {
        QProfileName profileName = entry.getKey();
        QualityProfileDto profile = factory.getOrCreate(dbSession, profileName);
        List<RuleActivation> activations = Lists.newArrayList();
        for (RulesProfile def : entry.getValue()) {
          for (ActiveRule activeRule : def.getActiveRules()) {
            RuleActivation activation = new RuleActivation(RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()));
            activation.setSeverity(activeRule.getSeverity().name());
View Full Code Here

TOP

Related Classes of org.sonar.core.qualityprofile.db.QualityProfileDto

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.