1 package test.net.sourceforge.pmd.jsp.rules; 2 3 import net.sourceforge.pmd.Rule; 4 import net.sourceforge.pmd.RuleSetFactory; 5 import net.sourceforge.pmd.RuleSetNotFoundException; 6 import net.sourceforge.pmd.SourceType; 7 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 8 import test.net.sourceforge.pmd.testframework.TestDescriptor; 9 10 /*** 11 * Test the "NoScriptlets" rule. 12 * 13 * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be 14 */ 15 public class NoScriptletsTest extends SimpleAggregatorTst { 16 17 public void testAll() throws RuleSetNotFoundException { 18 Rule rule = new RuleSetFactory() 19 .createSingleRuleSet("rulesets/basic-jsp.xml").getRuleByName("NoScriptlets"); 20 runTests(new TestDescriptor[]{ 21 new TestDescriptor(VIOLATION1, "Two scriptlets.", 2, rule), 22 new TestDescriptor(NO_VIOLATION1, "No scriptlets.", 0, rule), 23 }, SourceType.JSP); 24 } 25 26 private static final String VIOLATION1 = 27 "<HTML>" + 28 "<HEAD>" + 29 "<% response.setHeader(\"Pragma\", \"No-cache\"); %>" + 30 "</HEAD>" + 31 "<BODY>" + 32 " <jsp:scriptlet>String title = \"Hello world!\";</jsp:scriptlet>" + 33 "</BODY>" + 34 "</HTML>"; 35 36 37 private static final String NO_VIOLATION1 = 38 "<html><body><p>text</p></body></html>"; 39 }