use of net.sourceforge.pmd.lang.rule.XPathRule in project pmd by pmd.
the class XPathRuleTest method setUp.
@Before
public void setUp() {
rule = new XPathRule();
rule.setLanguage(LanguageRegistry.getLanguage(JavaLanguageModule.NAME));
rule.setMessage("XPath Rule Failed");
}
use of net.sourceforge.pmd.lang.rule.XPathRule in project pmd by pmd.
the class PLSQLXPathRuleTest method testXPathRule1Compatibility.
/**
* See https://sourceforge.net/p/pmd/bugs/1166/
*/
@Test
public void testXPathRule1Compatibility() {
XPathRule rule = createRule("1.0 compatibility");
rule.apply(Arrays.asList(node), ctx);
Assert.assertEquals(2, ctx.getReport().treeSize());
}
use of net.sourceforge.pmd.lang.rule.XPathRule in project pmd by pmd.
the class CodeClimateRendererTest method testXPathRule.
@Test
public void testXPathRule() throws Exception {
DummyNode node = createNode(1);
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename(getSourceCodeFilename());
Report report = new Report();
XPathRule theRule = new XPathRule();
theRule.setProperty(XPathRule.XPATH_DESCRIPTOR, "//dummyNode");
// Setup as FooRule
theRule.setDescription("desc");
theRule.setName("Foo");
report.addRuleViolation(new ParametricRuleViolation<Node>(theRule, ctx, node, "blah"));
String rendered = ReportTest.render(getRenderer(), report);
// Output should be the exact same as for non xpath rules
assertEquals(filter(getExpected()), filter(rendered));
}
use of net.sourceforge.pmd.lang.rule.XPathRule in project pmd by pmd.
the class RuleSetFactory method createSingleRuleRuleSet.
/**
* Creates a new RuleSet for a single rule
*
* @param rule
* The rule being created
* @return The newly created RuleSet
*/
public RuleSet createSingleRuleRuleSet(final Rule rule) {
final long checksum;
if (rule instanceof XPathRule) {
checksum = rule.getProperty(XPathRule.XPATH_DESCRIPTOR).hashCode();
} else {
// TODO : Is this good enough? all properties' values + rule name
checksum = rule.getPropertiesByPropertyDescriptor().values().hashCode() * 31 + rule.getName().hashCode();
}
final RuleSetBuilder builder = new RuleSetBuilder(checksum).withName(rule.getName()).withDescription("RuleSet for " + rule.getName());
builder.addRule(rule);
return builder.build();
}
use of net.sourceforge.pmd.lang.rule.XPathRule in project pmd by pmd.
the class XPathJspRuleTest method testExpressionMatching.
/**
* Test matching a XPath expression against a JSP source.
* @throws PMDException
*/
@Test
public void testExpressionMatching() throws PMDException {
Rule rule = new XPathRule(XPATH_EXPRESSION);
rule.setMessage("Test");
rule.setLanguage(LanguageRegistry.getLanguage(JspLanguageModule.NAME));
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
RuleContext ctx = new RuleContext();
Report report = new Report();
ctx.setReport(report);
ctx.setSourceCodeFilename("n/a");
ctx.setLanguageVersion(LanguageRegistry.getLanguage(JspLanguageModule.NAME).getDefaultVersion());
PMD p = new PMD();
p.getSourceCodeProcessor().processSourceCode(new StringReader(MATCH), new RuleSets(rules), ctx);
assertEquals("One violation expected!", 1, report.size());
RuleViolation rv = report.iterator().next();
assertEquals(1, rv.getBeginLine());
}
Aggregations