예제 #1
0
  @Test
  public void search_by_template_key_with_params() throws InterruptedException {
    RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S001")).setIsTemplate(true);
    RuleParamDto ruleParamDto =
        RuleParamDto.createFor(templateRule)
            .setName("regex")
            .setType("STRING")
            .setDescription("Reg ex")
            .setDefaultValue(".*");
    dao.insert(dbSession, templateRule);
    dao.addRuleParam(dbSession, templateRule, ruleParamDto);

    RuleDto customRule =
        RuleTesting.newDto(RuleKey.of("java", "S001_MY_CUSTOM"))
            .setTemplateId(templateRule.getId());
    RuleParamDto customRuleParam =
        RuleParamDto.createFor(customRule)
            .setName("regex")
            .setType("STRING")
            .setDescription("Reg ex")
            .setDefaultValue("a.*");
    dao.insert(dbSession, customRule);
    dao.addRuleParam(dbSession, customRule, customRuleParam);
    dbSession.commit();

    // find all
    RuleQuery query = new RuleQuery();
    Result<Rule> results = index.search(query, new QueryContext());
    assertThat(results.getHits()).hasSize(2);

    // get params
    assertThat(index.getByKey(templateRule.getKey()).params()).hasSize(1);
    assertThat(index.getByKey(customRule.getKey()).params()).hasSize(1);
  }
예제 #2
0
  @Test
  public void search_protected_chars() throws InterruptedException {
    String nameWithProtectedChars = "ja#va&sc\"r:ipt";

    RuleDto ruleDto = RuleTesting.newXooX1().setName(nameWithProtectedChars);
    dao.insert(dbSession, ruleDto);
    dbSession.commit();

    Rule rule = index.getByKey(RuleTesting.XOO_X1);
    assertThat(rule.name()).isEqualTo(nameWithProtectedChars);

    RuleQuery protectedCharsQuery = new RuleQuery().setQueryText(nameWithProtectedChars);
    List<Rule> results = index.search(protectedCharsQuery, new QueryContext()).getHits();
    assertThat(results).hasSize(1);
    assertThat(results.get(0).key()).isEqualTo(RuleTesting.XOO_X1);
  }
예제 #3
0
  @Test
  public void show_custom_rule() throws InterruptedException {
    RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S001")).setIsTemplate(true);
    dao.insert(dbSession, templateRule);
    dao.insert(
        dbSession,
        RuleTesting.newDto(RuleKey.of("java", "S001_MY_CUSTOM"))
            .setTemplateId(templateRule.getId()));
    dbSession.commit();

    // find all
    RuleQuery query = new RuleQuery();
    Result<Rule> results = index.search(query, new QueryContext());
    assertThat(results.getHits()).hasSize(2);

    // find custom rule
    assertThat(index.getByKey(RuleKey.of("java", "S001_MY_CUSTOM")).templateKey())
        .isEqualTo(RuleKey.of("java", "S001"));
  }
예제 #4
0
  @Test
  public void complex_param_value() throws InterruptedException {
    String value =
        "//expression[primary/qualifiedIdentifier[count(IDENTIFIER) = 2]/IDENTIFIER[2]/@tokenValue = 'firstOf' and primary/identifierSuffix/arguments/expression[not(primary) or primary[not(qualifiedIdentifier) or identifierSuffix]]]";

    QualityProfileDto profile = QProfileTesting.newXooP1();
    db.qualityProfileDao().insert(dbSession, profile);

    RuleDto rule = RuleTesting.newXooX1();
    dao.insert(dbSession, rule);

    RuleParamDto param =
        RuleParamDto.createFor(rule).setName("testing").setType("STRING").setDefaultValue(value);
    dao.addRuleParam(dbSession, rule, param);

    dbSession.commit();

    assertThat(index.getByKey(rule.getKey()).params()).hasSize(1);
    assertThat(index.getByKey(rule.getKey()).params().get(0).defaultValue()).isEqualTo(value);
  }
예제 #5
0
  @Test
  public void getByKey() throws InterruptedException {
    RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("javascript", "S001"));
    dao.insert(dbSession, ruleDto);
    dbSession.commit();

    Rule rule = index.getByKey(RuleKey.of("javascript", "S001"));

    assertThat(rule.htmlDescription()).isEqualTo(ruleDto.getDescription());
    assertThat(rule.key()).isEqualTo(ruleDto.getKey());

    // TODO
    // assertThat(rule.debtSubCharacteristicKey())
    // .isEqualTo(ruleDto.getDefaultSubCharacteristicId().toString());
    assertThat(rule.debtRemediationFunction().type().name())
        .isEqualTo(ruleDto.getRemediationFunction());

    assertThat(Sets.newHashSet(rule.tags())).isEqualTo(ruleDto.getTags());
    assertThat(Sets.newHashSet(rule.systemTags())).isEqualTo(ruleDto.getSystemTags());
  }
예제 #6
0
  @Test
  public void getByKey_null_if_not_found() throws InterruptedException {
    Rule rule = index.getByKey(RuleKey.of("javascript", "unknown"));

    assertThat(rule).isNull();
  }