@Test public void search_custom_rules_from_template_key() { RuleDefinitionDto templateRule = db.rules().insert(r -> r.setLanguage("java") .setIsTemplate(true)); RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java") .setTemplateId(templateRule.getId())); indexRules(); SearchResponse result = ws.newRequest() .setParam("f", "templateKey") .setParam("template_key", templateRule.getRepositoryKey() + ":" + templateRule.getRuleKey()) .executeProtobuf(SearchResponse.class); assertThat(result.getTotal()).isEqualTo(1); assertThat(result.getRulesCount()).isEqualTo(1); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); assertThat(searchedRule.getKey()).isEqualTo(rule.getRepositoryKey() + ":" + rule.getRuleKey()); assertThat(searchedRule.getTemplateKey()).isEqualTo(templateRule.getRepositoryKey() + ":" + templateRule.getRuleKey()); }
loadedRule.setInternalKey(r.getInternalKey()); if (r.hasTemplateKey()) { RuleKey templateRuleKey = RuleKey.parse(r.getTemplateKey()); loadedRule.setTemplateRuleKey(templateRuleKey.rule());
@Test public void encode_html_description_of_custom_rule() { // Template rule RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001")); db.rules().insert(templateRule.getDefinition()); // Custom rule RuleDefinitionDto customRule = newCustomRule(templateRule.getDefinition()) .setDescription("<div>line1\nline2</div>") .setDescriptionFormat(MARKDOWN); db.rules().insert(customRule); doReturn("<div>line1<br/>line2</div>").when(macroInterpreter).interpret("<div>line1\nline2</div>"); ShowResponse result = ws.newRequest() .setParam("key", customRule.getKey().toString()) .executeProtobuf(ShowResponse.class); assertThat(result.getRule().getHtmlDesc()).isEqualTo(INTERPRETED); assertThat(result.getRule().getTemplateKey()).isEqualTo(templateRule.getKey().toString()); verify(macroInterpreter).interpret("<div>line1<br/>line2</div>"); }
.setHtmlNote(r.getHtmlNote()) .setIsTemplate(r.getIsTemplate()) .setTemplateKey(r.getTemplateKey());
loadedRule.setInternalKey(r.getInternalKey()); if (r.hasTemplateKey()) { RuleKey templateRuleKey = RuleKey.parse(r.getTemplateKey()); loadedRule.setTemplateRuleKey(templateRuleKey.rule());
loadedRule.setInternalKey(r.getInternalKey()); if (r.hasTemplateKey()) { RuleKey templateRuleKey = RuleKey.parse(r.getTemplateKey()); loadedRule.setTemplateRuleKey(templateRuleKey.rule());