import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
messages = ValidationMessages.create();
/*
-
- The mocked rule finder defines 2 rules :
-
- - JavadocCheck with 2 paramters format and ignore, default priority is MAJOR
- - EqualsHashCodeCheck without parameters, default priority is BLOCKER
-
+ * The mocked rule finder defines 2 rules :
+ *
+ * - JavadocCheck with 2 paramters format and ignore, default priority is MAJOR
+ * - EqualsHashCodeCheck without parameters, default priority is BLOCKER
*/
importer = new CheckstyleProfileImporter(newRuleFinder());
}
if (StringUtils.equals(query.getConfigKey(), "Checker/JavadocPackage")) {
rule = Rule.create(query.getRepositoryKey(), "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc Package")
.setConfigKey("Checker/JavadocPackage")
- .setPriority(RulePriority.MAJOR);
+ .setSeverity(RulePriority.MAJOR);
rule.createParameter("format");
rule.createParameter("ignore");
} else if (StringUtils.equals(query.getConfigKey(), "Checker/TreeWalker/EqualsHashCode")) {
rule = Rule.create(query.getRepositoryKey(), "com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck", "Equals HashCode")
.setConfigKey("Checker/TreeWalker/EqualsHashCode")
- .setPriority(RulePriority.BLOCKER);
+ .setSeverity(RulePriority.BLOCKER);
} else if (StringUtils.equals(query.getKey(), "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345")) {
rule = Rule.create(query.getRepositoryKey(), "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345", "Javadoc Package")
.setConfigKey("Checker/JavadocPackage")
- .setPriority(RulePriority.MAJOR);
+ .setSeverity(RulePriority.MAJOR);
rule.createParameter("format");
rule.createParameter("ignore");
}
*/
package org.sonar.plugins.pmd;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.Reader;
-import java.io.StringReader;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.RuleQuery;
+import org.sonar.api.rules.*;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.plugins.pmd.xml.PmdRuleset;
import org.sonar.test.TestUtils;
+import java.io.Reader;
+import java.io.StringReader;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class PmdProfileImporterTest {
private PmdProfileImporter importer;
public Rule answer(InvocationOnMock iom) throws Throwable {
RuleQuery query = (RuleQuery) iom.getArguments()[0];
Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
- .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+ .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
if (rule.getConfigKey().equals("rulesets/coupling.xml/ExcessiveImports")) {
rule.createParameter("max");
}
*/
package org.sonar.plugins.pmd;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.utils.ValidationMessages;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class SonarWayProfileTest {
@Test
public Rule answer(InvocationOnMock iom) throws Throwable {
RuleQuery query = (RuleQuery) iom.getArguments()[0];
Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
- .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+ .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
return rule;
}
});
*/
package org.sonar.plugins.pmd;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.utils.ValidationMessages;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class SonarWayWithFindbugsProfileTest {
@Test
public Rule answer(InvocationOnMock iom) throws Throwable {
RuleQuery query = (RuleQuery) iom.getArguments()[0];
Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
- .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+ .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
return rule;
}
});
*/
package org.sonar.plugins.pmd;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.utils.ValidationMessages;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class SunConventionsProfileTest {
@Test
public void shouldCreateProfile() {
public Rule answer(InvocationOnMock iom) throws Throwable {
RuleQuery query = (RuleQuery) iom.getArguments()[0];
Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
- .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+ .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
return rule;
}
});
private List<CheckTemplate> templates;
private Map<String, CheckTemplate> templatesByKey;
-
public CheckTemplateRepository() {
}
return key.hashCode();
}
-
public static CheckTemplateRepository createFromXml(String repositoryKey, Language language, String pathToXml) {
InputStream input = CheckTemplateRepository.class.getResourceAsStream(pathToXml);
try {
return repository;
}
-
/*
-
- CODE FOR BACKWARD COMPATIBLITY
- This class should not extend RulesRepository in next versions
-
- */
-
+ * CODE FOR BACKWARD COMPATIBLITY
+ * This class should not extend RulesRepository in next versions
+ */
public List<Rule> getInitialReferential() {
List<Rule> rules = new ArrayList<Rule>();
Rule rule = new Rule(getKey(), checkTemplate.getKey());
rule.setDescription(checkTemplate.getDescription(Locale.ENGLISH));
rule.setName(checkTemplate.getTitle(Locale.ENGLISH));
- rule.setPriority(RulePriority.fromCheckPriority(checkTemplate.getPriority()));
+ rule.setSeverity(RulePriority.fromCheckPriority(checkTemplate.getPriority()));
for (CheckTemplateProperty checkTemplateProperty : checkTemplate.getProperties()) {
RuleParam param = rule.createParameter(checkTemplateProperty.getKey());
param.setDescription(checkTemplateProperty.getDescription(Locale.ENGLISH));
/**
* EXPERIMENTAL - will be used in version 2.2
+ *
* @since 2.1
*/
public class XmlCheckTemplateFactory {
template.setConfigKey(rule.getConfigKey());
template.setDescription(rule.getDescription());
- template.setPriority(rule.getPriority().toCheckPriority());
+ template.setPriority(rule.getSeverity().toCheckPriority());
template.setTitle(rule.getName());
if (rule.getParams() != null) {
return property;
}
-}
\ No newline at end of file
+}
InputStream inputStream = null;
try {
inputStream = IOUtils.toInputStream(xml, CharEncoding.UTF_8);
- return setDefaultRulePriorities((List<Rule>) getXStream().fromXML(inputStream));
+ return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(inputStream));
} catch (IOException e) {
throw new SonarException("Can't parse xml file", e);
}
public List<Rule> parse(Reader reader) {
- return setDefaultRulePriorities((List<Rule>) getXStream().fromXML(reader));
+ return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(reader));
}
public List<Rule> parse(InputStream input) {
try {
- return setDefaultRulePriorities((List<Rule>) getXStream().fromXML(new InputStreamReader(input, CharEncoding.UTF_8)));
+ return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(new InputStreamReader(input, CharEncoding.UTF_8)));
} catch (UnsupportedEncodingException e) {
throw new SonarException("Can't parse xml file", e);
}
}
- private List<Rule> setDefaultRulePriorities(List<Rule> rules) {
+ private List<Rule> setDefaultRuleSeverities(List<Rule> rules) {
for (Rule rule : rules) {
- if (rule.getPriority() == null) {
- rule.setPriority(RulePriority.MAJOR);
+ if (rule.getSeverity() == null) {
+ rule.setSeverity(RulePriority.MAJOR);
}
}
return rules;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
public class StandardRulesXmlParserTest {
@Test
StandardRulesXmlParser parser = new StandardRulesXmlParser();
String xml = "<rules><rule key='1' priority='CRITICAL'><category name='cat1'/></rule></rules>";
List<Rule> rules = parser.parse(xml);
- Assert.assertEquals(RulePriority.CRITICAL, rules.get(0).getPriority());
+ Assert.assertEquals(RulePriority.CRITICAL, rules.get(0).getSeverity());
}
@Test
StandardRulesXmlParser parser = new StandardRulesXmlParser();
String xml = "<rules><rule key='1'><category name='cat1'/></rule></rules>";
List<Rule> rules = parser.parse(xml);
- Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getPriority());
+ Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getSeverity());
}
@Test
String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), ruleKey);
Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
rule.setDescription(ruleAnnotation.description());
- rule.setPriority(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
+ rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
rule.setCardinality(ruleAnnotation.cardinality());
Field[] fields = clazz.getDeclaredFields();
String ruleName = StringUtils.defaultIfEmpty(checkAnnotation.title(), ruleKey);
Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
rule.setDescription(checkAnnotation.description());
- rule.setPriority(RulePriority.fromCheckPriority(checkAnnotation.priority()));
+ rule.setSeverity(RulePriority.fromCheckPriority(checkAnnotation.priority()));
Field[] fields = clazz.getDeclaredFields();
if (fields != null) {
}\r
\r
/**\r
- * @deprecated Use the factory method {@link #create()}\r
+ * @deprecated since 2.3. Use the factory method {@link #create()}\r
*/\r
@Deprecated\r
public Rule(String name, String key, RulesCategory rulesCategory, String pluginName, String description) {\r
}\r
\r
/**\r
- * @deprecated visibility should be decreased to protected or package\r
+ * @deprecated since 2.3. visibility should be decreased to protected or package\r
*/\r
@Deprecated\r
public void setId(Integer id) {\r
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
+
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
String priorityAttribute = ruleC.getAttrValue("priority");
if (StringUtils.isNotBlank(priorityAttribute)) {
- rule.setPriority(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
+ rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
}
SMInputCursor cursor = ruleC.childElementCursor();
rule.setConfigKey(StringUtils.trim(cursor.collectDescendantText(false)));
} else if (StringUtils.equalsIgnoreCase("priority", nodeName)) {
- rule.setPriority(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
+ rule.setSeverity(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
} else if (StringUtils.equalsIgnoreCase("cardinality", nodeName)) {
rule.setCardinality(Cardinality.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
@Test
public void activateRuleWithDefaultPriority() {
RulesProfile profile = RulesProfile.create();
- Rule rule = Rule.create("repo", "key1", "name1").setPriority(RulePriority.CRITICAL);
+ Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, null);
- assertThat(profile.getActiveRule("repo", "key1").getPriority(), is(RulePriority.CRITICAL));
+ assertThat(profile.getActiveRule("repo", "key1").getSeverity(), is(RulePriority.CRITICAL));
}
@Test
public void activateRuleWithSpecificPriority() {
RulesProfile profile = RulesProfile.create();
- Rule rule = Rule.create("repo", "key1", "name1").setPriority(RulePriority.CRITICAL);
+ Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, RulePriority.MINOR);
- assertThat(profile.getActiveRule("repo", "key1").getPriority(), is(RulePriority.MINOR));
+ assertThat(profile.getActiveRule("repo", "key1").getSeverity(), is(RulePriority.MINOR));
}
}
Rule rule = rules.get(0);
assertThat(rule.getKey(), is("foo"));
assertThat(rule.getName(), is("bar"));
- assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
+ assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
assertThat(rule.getParams().size(), is(1));
RuleParam prop = rule.getParam("property");
assertThat(prop.getKey(), is("property"));
Rule rule = rules.get(0);
assertThat(rule.getKey(), is("foo"));
assertThat(rule.getName(), is("foo"));
- assertThat(rule.getPriority(), is(RulePriority.MAJOR));
+ assertThat(rule.getSeverity(), is(RulePriority.MAJOR));
}
@Test
Rule rule = rules.get(0);
assertThat(rule.getKey(), is(RuleWithoutKey.class.getCanonicalName()));
assertThat(rule.getName(), is("foo"));
- assertThat(rule.getPriority(), is(RulePriority.MAJOR));
+ assertThat(rule.getSeverity(), is(RulePriority.MAJOR));
}
@Test
assertThat(rule.getKey(), is(Check.class.getCanonicalName()));
assertThat(rule.getName(), is(Check.class.getCanonicalName()));
assertThat(rule.getDescription(), is("Deprecated check"));
- assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
+ assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
}
private List<Rule> parseAnnotatedClass(Class annotatedClass) {
*/
package org.sonar.api.rules;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
-
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
public class RuleTest {
@Test
public void shouldRemoveNewLineCharactersInNameWithSecondConstructor() {
Rule rule;
for (String example : getExamplesContainingNewLineCharacter()) {
- rule = new Rule(null, null, example, (RulesCategory)null, null);
+ rule = new Rule(null, null, example, (RulesCategory) null, null);
assertThat(rule.getName(), is("test"));
}
}
@Test
public void defaultPriorityIsMajor() {
Rule rule = new Rule();
- assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+ assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
rule = new Rule("name", "key");
- assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+ assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
rule = new Rule("pkey", "key", "name", Iso9126RulesCategories.EFFICIENCY, null, null);
- assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+ assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
- rule.setPriority(RulePriority.BLOCKER);
- assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
+ rule.setSeverity(RulePriority.BLOCKER);
+ assertThat(rule.getSeverity(), Is.is(RulePriority.BLOCKER));
- rule.setPriority(null);
- assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+ rule.setSeverity(null);
+ assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
}
-
private List<String> getExamplesContainingNewLineCharacter() {
return Arrays.asList("te\nst", "te\ns\nt", "te\rst", "te\n\rst", "te\r\nst");
}
-
}
Rule rule = rules.get(0);
assertThat(rule.getName(), is("Local Variable Name"));
assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property."));
- assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
+ assertThat(rule.getSeverity(), Is.is(RulePriority.BLOCKER));
assertThat(rule.getCardinality(), Is.is(Cardinality.MULTIPLE));
assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName"));
List<Rule> rules = new XMLRuleParser().parse(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml"));
assertThat(rules.size(), is(1));
Rule rule = rules.get(0);
- assertThat(rule.getPriority(), Is.is(RulePriority.CRITICAL));
+ assertThat(rule.getSeverity(), Is.is(RulePriority.CRITICAL));
assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck"));
assertThat(rule.getParam("minMethodsCount"), not(nullValue()));
}
}
}
-
class DeprecatedRuleRepository extends RuleRepository {
private RulesRepository deprecatedRepository;
private Rule cloneRule(Rule deprecatedRule) {
Rule rule = Rule.create(getKey(), deprecatedRule.getKey(), deprecatedRule.getName());
rule.setConfigKey(deprecatedRule.getConfigKey());
- rule.setPriority(deprecatedRule.getPriority());
+ rule.setSeverity(deprecatedRule.getSeverity());
rule.setDescription(deprecatedRule.getDescription());
rule.setEnabled(true);
if (deprecatedRule.getParams() != null) {
List<Integer> deprecatedUserRuleIds = new ArrayList<Integer>();
deprecatedUserRuleIds.addAll(session.createQuery(
"SELECT r.id FROM " + Rule.class.getSimpleName() +
- " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList());
+ " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList());
deprecatedUserRuleIds.addAll(session.createQuery(
"SELECT r.id FROM " + Rule.class.getSimpleName() +
- " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList());
+ " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList());
for (Integer deprecatedUserRuleId : deprecatedUserRuleIds) {
Rule rule = session.getSingleResult(Rule.class, "id", deprecatedUserRuleId);
persistedRule.setName(rule.getName());
persistedRule.setConfigKey(rule.getConfigKey());
persistedRule.setDescription(rule.getDescription());
- persistedRule.setPriority(rule.getPriority());
+ persistedRule.setSeverity(rule.getSeverity());
persistedRule.setEnabled(true);
persistedRule.setCardinality(rule.getCardinality());
import org.sonar.api.utils.ValidationMessages;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
public class DeprecatedProfilesTest {
assertThat(def.getRules().size(), is(2));
assertThat(def.getRulesByRepositoryKey("checkstyle").size(), is(1));
- assertThat(def.getRulesByRepositoryKey("checkstyle").get(0).getPriority(), is(RulePriority.BLOCKER));
+ assertThat(def.getRulesByRepositoryKey("checkstyle").get(0).getSeverity(), is(RulePriority.BLOCKER));
}
@Test
public void priorityIsOptional() {
DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
- def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setPriority(RulePriority.BLOCKER), null);
- assertThat(def.getRules().get(0).getPriority(), is(RulePriority.BLOCKER));
+ def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setSeverity(RulePriority.BLOCKER), null);
+ assertThat(def.getRules().get(0).getSeverity(), is(RulePriority.BLOCKER));
}
}
import org.sonar.api.rules.*;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
public class RegisterRulesTest extends AbstractDbUnitTestCase {
@Test
public void saveNewRepositories() {
setupData("shared");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake");
@Test
public void disableDeprecatedRepositories() {
setupData("shared");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
List<Rule> rules = (List<Rule>) getSession()
@Test
public void disableDeprecatedActiveRules() {
setupData("disableDeprecatedActiveRules");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake");
@Test
public void disableDeprecatedActiveRuleParameters() {
setupData("disableDeprecatedActiveRuleParameters");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
- ActiveRule arule= getSession().getSingleResult(ActiveRule.class, "id", 1);
+ ActiveRule arule = getSession().getSingleResult(ActiveRule.class, "id", 1);
assertThat(arule.getActiveRuleParams().size(), is(2));
assertNull(getSession().getSingleResult(ActiveRuleParam.class, "id", 3));
}
@Test
public void disableDeprecatedRules() {
setupData("disableDeprecatedRules");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
@Test
public void updateRuleFields() {
setupData("updadeRuleFields");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
// fields have been updated with new values
Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
assertThat(rule.getName(), is("One"));
assertThat(rule.getDescription(), is("Description of One"));
- assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
+ assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
assertThat(rule.getConfigKey(), is("config1"));
}
@Test
public void updateRuleParameters() {
setupData("updateRuleParameters");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
@Test
public void doNotDisableUserRulesIfParentIsEnabled() {
setupData("doNotDisableUserRulesIfParentIsEnabled");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
Rule rule = getSession().getSingleResult(Rule.class, "id", 2);
@Test
public void disableUserRulesIfParentIsDisabled() {
setupData("disableUserRulesIfParentIsDisabled");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
task.start();
Rule rule = getSession().getSingleResult(Rule.class, "id", 2);
@Test
public void volumeTesting() {
setupData("shared");
- RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new VolumeRepository()});
+ RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new VolumeRepository() });
task.start();
List<Rule> result = getSession().getResults(Rule.class, "enabled", true);
public List<Rule> createRules() {
Rule rule1 = Rule.create("fake", "rule1", "One");
rule1.setDescription("Description of One");
- rule1.setPriority(RulePriority.BLOCKER);
+ rule1.setSeverity(RulePriority.BLOCKER);
rule1.setConfigKey("config1");
rule1.createParameter("param1").setDescription("parameter one");
rule1.createParameter("param2").setDescription("parameter two");
-
+
Rule rule2 = Rule.create("fake", "rule2", "Two");
- rule2.setPriority(RulePriority.INFO);
-
+ rule2.setSeverity(RulePriority.INFO);
+
return Arrays.asList(rule1, rule2);
}
}
super("volume", "java");
}
-
public List<Rule> createRules() {
List<Rule> rules = new ArrayList<Rule>();
for (int i = 0; i < SIZE; i++) {
Rule rule = Rule.create("volume", "rule" + i, "description of " + i);
- rule.setPriority(RulePriority.BLOCKER);
+ rule.setSeverity(RulePriority.BLOCKER);
for (int j = 0; j < 20; j++) {
rule.createParameter("param" + j);
}
}
return rules;
}
-}
\ No newline at end of file
+}