aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-29 17:00:54 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-29 17:00:54 +0000
commit6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d (patch)
tree0770d083d359e3e644ff64bf06dc8b9abc3ad04b /sonar-core/src
parent0c4893c83a6873b224a50db86311082fd5af555f (diff)
downloadsonarqube-6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d.tar.gz
sonarqube-6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d.zip
SONAR-249 improve core components to load rules and metrics
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java72
-rw-r--r--sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java74
-rw-r--r--sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java (renamed from sonar-core/src/main/java/org/sonar/core/qualitymodel/DefaultModelFinder.java)2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java (renamed from sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java)18
-rw-r--r--sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java65
-rw-r--r--sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java61
-rw-r--r--sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java (renamed from sonar-core/src/test/java/org/sonar/core/qualitymodel/DefaultModelFinderTest.java)3
-rw-r--r--sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java (renamed from sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleFinderTest.java)52
-rw-r--r--sonar-core/src/test/java/org/sonar/core/components/ModelTest.java (renamed from sonar-core/src/test/java/org/sonar/core/qualitymodel/ModelTest.java)7
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/components/CacheMetricFinderTest/shared.xml12
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/components/DefaultModelFinderTest/shared.xml (renamed from sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/components/DefaultRuleFinderTest/shared.xml (renamed from sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleFinderTest/shared.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/components/ModelTest/saveModelAndCharacteristics.xml (renamed from sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/components/ModelTest/testGraphOfCharacteristics.xml (renamed from sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml)0
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/components/ModelTest/testTreeOfCharacteristics.xml (renamed from sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml)0
15 files changed, 337 insertions, 29 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java b/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java
new file mode 100644
index 00000000000..fa125dc9da1
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java
@@ -0,0 +1,72 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.components;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.MetricFinder;
+import org.sonar.jpa.session.DatabaseSessionFactory;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public final class CacheMetricFinder implements MetricFinder {
+
+ private DatabaseSessionFactory sessionFactory;
+ private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
+ private Map<Integer, Metric> metricsById = Maps.newLinkedHashMap();
+
+ public CacheMetricFinder(DatabaseSessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ public void start() {
+ List<Metric> list = sessionFactory.getSession().getResults(Metric.class, "enabled", true);
+ for (Metric metric : list) {
+ metricsByKey.put(metric.getKey(), metric);
+ metricsById.put(metric.getId(), metric);
+ }
+ }
+
+ public Metric findById(int metricId) {
+ return metricsById.get(metricId);
+ }
+
+ public Metric findByKey(String key) {
+ return metricsByKey.get(key);
+ }
+
+ public Collection<Metric> findAll(List<String> metricKeys) {
+ List<Metric> result = Lists.newLinkedList();
+ for (String metricKey : metricKeys) {
+ Metric metric = findByKey(metricKey);
+ if (metric != null) {
+ result.add(metric);
+ }
+ }
+ return result;
+ }
+
+ public Collection<Metric> findAll() {
+ return metricsByKey.values();
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java
new file mode 100644
index 00000000000..1e0b747bb61
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java
@@ -0,0 +1,74 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.components;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Maps;
+import org.sonar.api.rules.Rule;
+import org.sonar.jpa.session.DatabaseSessionFactory;
+
+import java.util.Map;
+
+public final class CacheRuleFinder extends DefaultRuleFinder {
+
+ private BiMap<Integer, Rule> rulesById = HashBiMap.create();
+ private Map<String, Map<String, Rule>> rulesByKey = Maps.newHashMap();
+
+ public CacheRuleFinder(DatabaseSessionFactory sessionFactory) {
+ super(sessionFactory);
+ }
+
+ @Override
+ public Rule findById(int ruleId) {
+ Rule rule = rulesById.get(ruleId);
+ if (rule==null) {
+ rule = doFindById(ruleId);
+ addToCache(rule);
+ }
+ return rule;
+ }
+
+ @Override
+ public Rule findByKey(String repositoryKey, String key) {
+ Map<String,Rule> repoRules = rulesByKey.get(repositoryKey);
+ Rule rule = null;
+ if (repoRules!=null) {
+ rule = repoRules.get(key);
+ }
+ if (rule == null) {
+ rule = doFindByKey(repositoryKey, key);
+ addToCache(rule);
+ }
+ return rule;
+ }
+
+ private void addToCache(Rule rule) {
+ if (rule != null) {
+ rulesById.put(rule.getId(), rule);
+ Map<String, Rule> repoRules = rulesByKey.get(rule.getKey());
+ if (repoRules==null) {
+ repoRules = Maps.newHashMap();
+ rulesByKey.put(rule.getRepositoryKey(), repoRules);
+ }
+ repoRules.put(rule.getKey(), rule);
+ }
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualitymodel/DefaultModelFinder.java b/sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java
index 5606e5e0907..a7a04c7cf24 100644
--- a/sonar-core/src/main/java/org/sonar/core/qualitymodel/DefaultModelFinder.java
+++ b/sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.core.qualitymodel;
+package org.sonar.core.components;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.qualitymodel.Model;
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java
index 6a167b180f7..3c0d50e7bcd 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
+++ b/sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.core.rule;
+package org.sonar.core.components;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.database.DatabaseSession;
@@ -39,17 +39,29 @@ public class DefaultRuleFinder implements RuleFinder {
this.sessionFactory = sessionFactory;
}
+ public Rule findById(int ruleId) {
+ return doFindById(ruleId);
+ }
+
+ protected final Rule doFindById(int ruleId) {
+ return sessionFactory.getSession().getSingleResult(Rule.class, "id", ruleId, "enabled", true);
+ }
+
public Rule findByKey(String repositoryKey, String key) {
+ return doFindByKey(repositoryKey, key);
+ }
+
+ protected final Rule doFindByKey(String repositoryKey, String key) {
return sessionFactory.getSession().getSingleResult(Rule.class, "pluginName", repositoryKey, "key", key, "enabled", true);
}
- public Rule find(RuleQuery query) {
+ public final Rule find(RuleQuery query) {
DatabaseSession session = sessionFactory.getSession();
return (Rule)session.getSingleResult(createHqlQuery(session, query), null);
}
- public Collection<Rule> findAll(RuleQuery query) {
+ public final Collection<Rule> findAll(RuleQuery query) {
DatabaseSession session = sessionFactory.getSession();
return createHqlQuery(session, query).getResultList();
}
diff --git a/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java
new file mode 100644
index 00000000000..a67fd0cf713
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java
@@ -0,0 +1,65 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.components;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import java.util.Arrays;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+
+
+public class CacheMetricFinderTest extends AbstractDbUnitTestCase {
+
+ private CacheMetricFinder finder;
+
+ @Before
+ public void initFinder() {
+ setupData("shared");
+ finder = new CacheMetricFinder(getSessionFactory());
+ finder.start();
+ }
+
+ @Test
+ public void shouldFindAll() {
+ assertThat(finder.findAll().size(), is(2));
+ }
+
+ @Test
+ public void shouldFindByKeys() {
+ assertThat(finder.findAll(Arrays.<String>asList("ncloc", "foo", "coverage")).size(), is(2));
+ }
+
+ @Test
+ public void shouldFindById() {
+ assertThat(finder.findById(1).getKey(), is("ncloc"));
+ assertThat(finder.findById(3), nullValue());
+ }
+
+ @Test
+ public void shouldFindByKey() {
+ assertThat(finder.findByKey("ncloc").getKey(), is("ncloc"));
+ assertThat(finder.findByKey("disabled"), nullValue());
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java
new file mode 100644
index 00000000000..0eb9d239161
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java
@@ -0,0 +1,61 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.components;
+
+import org.junit.Test;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+
+public class CacheRuleFinderTest extends AbstractDbUnitTestCase {
+
+ @Test
+ public void shouldCacheFindById() {
+ setupData("shared");
+ RuleFinder finder = new CacheRuleFinder(getSessionFactory());
+ assertThat(finder.findById(3).getConfigKey(), is("Checker/Treewalker/AnnotationUseStyleCheck"));
+
+ deleteRules();
+
+ assertThat(finder.findById(3), notNullValue());
+ }
+
+ @Test
+ public void shouldCacheFindByKey() {
+ setupData("shared");
+ RuleFinder finder = new CacheRuleFinder(getSessionFactory());
+ Rule rule = finder.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck");
+ assertThat(rule.getConfigKey(), is("Checker/Treewalker/AnnotationUseStyleCheck"));
+
+ deleteRules();
+
+ rule = finder.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck");
+ assertThat(rule, notNullValue());
+ }
+
+ private void deleteRules() {
+ getSession().createQuery("delete " + Rule.class.getSimpleName()).executeUpdate();
+ getSession().commit();
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/qualitymodel/DefaultModelFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java
index 9069fab38f4..222bf4053ed 100644
--- a/sonar-core/src/test/java/org/sonar/core/qualitymodel/DefaultModelFinderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java
@@ -17,10 +17,11 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.core.qualitymodel;
+package org.sonar.core.components;
import org.junit.Test;
import org.sonar.api.qualitymodel.Model;
+import org.sonar.core.components.DefaultModelFinder;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import static org.junit.Assert.assertNotNull;
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java
index c80573be1c0..7d2c2b8176a 100644
--- a/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleFinderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java
@@ -17,10 +17,11 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.core.rule;
+package org.sonar.core.components;
import org.junit.Test;
import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -28,35 +29,48 @@ import java.util.Collection;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.*;
public class DefaultRuleFinderTest extends AbstractDbUnitTestCase {
@Test
- public void findByKey() {
+ public void shouldFindById() {
setupData("shared");
- DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
- Rule rule = provider.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck");
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ assertThat(finder.findById(3).getConfigKey(), is("Checker/Treewalker/AnnotationUseStyleCheck"));
+ }
+
+ @Test
+ public void shouldNotFindDisabledRuleById() {
+ setupData("shared");
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ assertThat(finder.findById(2), nullValue());
+ }
+
+ @Test
+ public void shouldFindByKey() {
+ setupData("shared");
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ Rule rule = finder.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck");
assertNotNull(rule);
assertThat(rule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"));
assertThat(rule.isEnabled(), is(true));
}
@Test
- public void findReturnsNullIfNoResults() {
+ public void findShouldReturnNullIfNoResults() {
setupData("shared");
- DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
- assertNull(provider.findByKey("checkstyle", "unknown"));
- assertNull(provider.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown")));
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ assertNull(finder.findByKey("checkstyle", "unknown"));
+ assertNull(finder.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown")));
}
@Test
public void findRepositoryRules() {
setupData("shared");
- DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
- Collection<Rule> rules = provider.findAll(RuleQuery.create().withRepositoryKey("checkstyle"));
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ Collection<Rule> rules = finder.findAll(RuleQuery.create().withRepositoryKey("checkstyle"));
assertNotNull(rules);
assertThat(rules.size(), is(2)); // only enabled checkstyle rules
}
@@ -64,8 +78,8 @@ public class DefaultRuleFinderTest extends AbstractDbUnitTestCase {
@Test
public void findAllEnabled() {
setupData("shared");
- DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
- Collection<Rule> rules = provider.findAll(RuleQuery.create());
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ Collection<Rule> rules = finder.findAll(RuleQuery.create());
assertNotNull(rules);
assertThat(rules.size(), is(3)); // only enabled checkstyle+pmd rules
for (Rule rule : rules) {
@@ -76,16 +90,16 @@ public class DefaultRuleFinderTest extends AbstractDbUnitTestCase {
@Test
public void doNotFindDisabledRules() {
setupData("shared");
- DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
- Rule rule = provider.findByKey("checkstyle", "DisabledCheck");
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ Rule rule = finder.findByKey("checkstyle", "DisabledCheck");
assertNull(rule);
}
@Test
public void doNotFindUnknownRules() {
setupData("shared");
- DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
- Collection<Rule> rules = provider.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"));
+ RuleFinder finder = new DefaultRuleFinder(getSessionFactory());
+ Collection<Rule> rules = finder.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"));
assertThat(rules.size(), is(0));
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/qualitymodel/ModelTest.java b/sonar-core/src/test/java/org/sonar/core/components/ModelTest.java
index 0c15154140a..b614dfbe8d2 100644
--- a/sonar-core/src/test/java/org/sonar/core/qualitymodel/ModelTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/components/ModelTest.java
@@ -17,18 +17,15 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.core.qualitymodel;
+package org.sonar.core.components;
import org.junit.Test;
import org.sonar.api.qualitymodel.Characteristic;
import org.sonar.api.qualitymodel.Model;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.junit.internal.matchers.IsCollectionContaining.hasItems;
public class ModelTest extends AbstractDbUnitTestCase {
diff --git a/sonar-core/src/test/resources/org/sonar/core/components/CacheMetricFinderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/components/CacheMetricFinderTest/shared.xml
new file mode 100644
index 00000000000..85709bcbf98
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/components/CacheMetricFinderTest/shared.xml
@@ -0,0 +1,12 @@
+<dataset>
+
+ <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+ enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0"
+ hidden="false"/>
+
+ <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+ enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
+
+ <metrics id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+ enabled="false" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/components/DefaultModelFinderTest/shared.xml
index c26de5371bb..c26de5371bb 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/components/DefaultModelFinderTest/shared.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleFinderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/components/DefaultRuleFinderTest/shared.xml
index f6adafee0da..f6adafee0da 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleFinderTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/components/DefaultRuleFinderTest/shared.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml b/sonar-core/src/test/resources/org/sonar/core/components/ModelTest/saveModelAndCharacteristics.xml
index cd0705734b2..cd0705734b2 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/components/ModelTest/saveModelAndCharacteristics.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml b/sonar-core/src/test/resources/org/sonar/core/components/ModelTest/testGraphOfCharacteristics.xml
index ee6e959b85b..ee6e959b85b 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/components/ModelTest/testGraphOfCharacteristics.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml b/sonar-core/src/test/resources/org/sonar/core/components/ModelTest/testTreeOfCharacteristics.xml
index ef3d9a58680..ef3d9a58680 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/components/ModelTest/testTreeOfCharacteristics.xml