Example #1
0
  @Test
  public void fail_to_recreate_built_in_profile_when_rule_not_found() throws Exception {
    String name = "Default";
    String language = "java";

    RulesProfile profile = RulesProfile.create(name, language);
    Rule rule = Rule.create("pmd", "rule");
    profile.activateRule(rule, null);

    ProfileDefinition profileDefinition = mock(ProfileDefinition.class);
    when(profileDefinition.createProfile(any(ValidationMessages.class))).thenReturn(profile);
    definitions.add(profileDefinition);

    when(ruleDao.getNullableByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(null);

    when(qProfileOperations.newProfile(
            eq(name), eq(language), eq(true), any(UserSession.class), eq(session)))
        .thenReturn(new QProfile().setId(1));

    try {
      backup.recreateBuiltInProfilesByLanguage(language);
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(NotFoundException.class);
    }
    verifyZeroInteractions(qProfileActiveRuleOperations);
  }
Example #2
0
  @Test
  public void
      recreate_built_in_profiles_from_language_with_multiple_profiles_with_same_name_and_same_language()
          throws Exception {
    RulesProfile profile1 = RulesProfile.create("Default", "java");
    profile1.activateRule(Rule.create("pmd", "rule").setSeverity(RulePriority.BLOCKER), null);
    ProfileDefinition profileDefinition1 = mock(ProfileDefinition.class);
    when(profileDefinition1.createProfile(any(ValidationMessages.class))).thenReturn(profile1);
    definitions.add(profileDefinition1);

    RulesProfile profile2 = RulesProfile.create("Default", "java");
    profile2.activateRule(Rule.create("checkstyle", "rule").setSeverity(RulePriority.MAJOR), null);
    ProfileDefinition profileDefinition2 = mock(ProfileDefinition.class);
    when(profileDefinition2.createProfile(any(ValidationMessages.class))).thenReturn(profile2);
    definitions.add(profileDefinition2);

    when(ruleDao.getNullableByKey(session, RuleKey.of("pmd", "rule")))
        .thenReturn(new RuleDto().setId(10).setSeverity("INFO"));
    when(ruleDao.getNullableByKey(session, RuleKey.of("checkstyle", "rule")))
        .thenReturn(new RuleDto().setId(11).setSeverity("INFO"));

    when(qProfileOperations.newProfile(
            eq("Default"), eq("java"), eq(true), any(UserSession.class), eq(session)))
        .thenReturn(new QProfile().setId(1));

    backup.recreateBuiltInProfilesByLanguage("java");

    verify(qProfileActiveRuleOperations)
        .createActiveRule(
            eq(QualityProfileKey.of("Default", "java")),
            eq(RuleKey.of("pmd", "rule")),
            eq("BLOCKER"),
            eq(session));
    verify(qProfileActiveRuleOperations)
        .createActiveRule(
            eq(QualityProfileKey.of("Default", "java")),
            eq(RuleKey.of("checkstyle", "rule")),
            eq("MAJOR"),
            eq(session));
    verifyNoMoreInteractions(qProfileActiveRuleOperations);

    verify(dryRunCache).reportGlobalModification(session);
    verify(session).commit();
  }
Example #3
0
  @Test
  public void recreate_built_in_profiles_from_language() throws Exception {
    String name = "Default";
    String language = "java";

    RulesProfile profile = RulesProfile.create(name, language);
    Rule rule = Rule.create("pmd", "rule");
    rule.createParameter("max");
    ActiveRule activeRule = profile.activateRule(rule, RulePriority.BLOCKER);
    activeRule.setParameter("max", "10");

    ProfileDefinition profileDefinition = mock(ProfileDefinition.class);
    when(profileDefinition.createProfile(any(ValidationMessages.class))).thenReturn(profile);
    definitions.add(profileDefinition);

    when(ruleDao.getNullableByKey(session, RuleKey.of("pmd", "rule")))
        .thenReturn(new RuleDto().setId(10).setSeverity("INFO"));

    when(qProfileOperations.newProfile(
            eq(name), eq(language), eq(true), any(UserSession.class), eq(session)))
        .thenReturn(new QProfile().setId(1));

    backup.recreateBuiltInProfilesByLanguage(language);

    verify(qProfileActiveRuleOperations)
        .createActiveRule(
            eq(QualityProfileKey.of(name, language)),
            eq(RuleKey.of("pmd", "rule")),
            eq("BLOCKER"),
            eq(session));
    verify(qProfileActiveRuleOperations)
        .updateActiveRuleParam(any(ActiveRuleDto.class), eq("max"), eq("10"), eq(session));
    verifyNoMoreInteractions(qProfileActiveRuleOperations);

    verify(dryRunCache).reportGlobalModification(session);
    verify(session).commit();
  }