diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-30 10:40:19 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-30 10:40:19 +0000 |
commit | a5fe1c55fd695711edf087fed2e4b437cd25e2b4 (patch) | |
tree | ea2c50924ef1bc0eb0e588a9f68522e744040454 /sonar-batch | |
parent | 0b875cc83530e92fdf5a22d9d808aee1cc33ea91 (diff) | |
download | sonarqube-a5fe1c55fd695711edf087fed2e4b437cd25e2b4.tar.gz sonarqube-a5fe1c55fd695711edf087fed2e4b437cd25e2b4.zip |
SONAR-249 fix detection of "best value measures" in delayed mode - add unit tests
Diffstat (limited to 'sonar-batch')
6 files changed, 76 insertions, 11 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java index 5c556b8a53a..aa7f42a44bb 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java @@ -45,25 +45,34 @@ import static org.mockito.Mockito.when; public class MeasurePersisterTest extends AbstractDbUnitTestCase { + public static final int PROJECT_SNAPSHOT_ID = 3001; + public static final int PACKAGE_SNAPSHOT_ID = 3002; + public static final int FILE_SNAPSHOT_ID = 3003; + public static final int COVERAGE_METRIC_ID = 2; + private ResourcePersister resourcePersister; private MeasurePersister measurePersister; private Project project = new Project("foo"); private JavaPackage aPackage = new JavaPackage("org.foo"); - private Snapshot projectSnapshot, packageSnapshot; + private JavaFile aFile = new JavaFile("org.foo.Bar"); + private Snapshot projectSnapshot, packageSnapshot, fileSnapshot; private Metric ncloc, coverage; @Before public void mockResourcePersister() { setupData("shared"); resourcePersister = mock(ResourcePersister.class); - projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 3001); - packageSnapshot = getSession().getSingleResult(Snapshot.class, "id", 3002); + projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", PROJECT_SNAPSHOT_ID); + packageSnapshot = getSession().getSingleResult(Snapshot.class, "id", PACKAGE_SNAPSHOT_ID); + fileSnapshot = getSession().getSingleResult(Snapshot.class, "id", FILE_SNAPSHOT_ID); ncloc = getSession().getSingleResult(Metric.class, "key", "ncloc"); coverage = getSession().getSingleResult(Metric.class, "key", "coverage"); when(resourcePersister.saveResource((Project) anyObject(), eq(project))).thenReturn(projectSnapshot); when(resourcePersister.saveResource((Project) anyObject(), eq(aPackage))).thenReturn(packageSnapshot); + when(resourcePersister.saveResource((Project) anyObject(), eq(aFile))).thenReturn(fileSnapshot); when(resourcePersister.getSnapshot(project)).thenReturn(projectSnapshot); when(resourcePersister.getSnapshot(aPackage)).thenReturn(packageSnapshot); + when(resourcePersister.getSnapshot(aFile)).thenReturn(fileSnapshot); measurePersister = new MeasurePersister(getSession(), resourcePersister, new DefaultRuleFinder(getSessionFactory())); } @@ -97,7 +106,7 @@ public class MeasurePersisterTest extends AbstractDbUnitTestCase { measurePersister.dump(); - List<MeasureModel> coverageMeasures = getSession().getResults(MeasureModel.class, "snapshotId", 3001, "metricId", 1); + List<MeasureModel> coverageMeasures = getSession().getResults(MeasureModel.class, "snapshotId", PROJECT_SNAPSHOT_ID, "metricId", 1); assertThat(coverageMeasures.size(), is(1)); assertThat(coverageMeasures.get(0).getValue(), is(300.0)); } @@ -148,6 +157,21 @@ public class MeasurePersisterTest extends AbstractDbUnitTestCase { } @Test + public void shouldNotSaveBestValueMeasuresInDelayedMode() { + measurePersister.setDelayedMode(true); + + measurePersister.saveMeasure(project, aFile, new Measure(coverage).setValue(100.0)); + + assertThat(getSession().getResults(MeasureModel.class, "metricId", COVERAGE_METRIC_ID, "snapshotId", FILE_SNAPSHOT_ID).size(), is(0)); + + measurePersister.dump(); + + // not saved because it's a best value measure + assertThat(getSession().getResults(MeasureModel.class, "metricId", COVERAGE_METRIC_ID, "snapshotId", FILE_SNAPSHOT_ID).size(), is(0)); + } + + + @Test public void shouldNotSaveMemoryOnlyMeasures() { Measure measure = new Measure("ncloc").setPersistenceMode(PersistenceMode.MEMORY); assertThat(MeasurePersister.shouldPersistMeasure(aPackage, measure), is(false)); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shared.xml index 3a12e1fde0b..86703017b20 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shared.xml @@ -9,10 +9,14 @@ name="project name" long_name="project name" description="project description" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> - <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="[null]" + <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001" name="org.foo" long_name="org.foo" description="[null]" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <projects id="1003" scope="FIL" qualifier="CLA" kee="foo:org.foo.Bar" root_id="1001" + name="Bar" long_name="org.foo.Bar" description="[null]" + enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path="" status="U" islast="false" depth="0" /> @@ -21,6 +25,11 @@ scope="DIR" qualifier="PAC" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001." status="U" islast="false" depth="1" /> + <snapshots id="3003" project_id="1003" parent_snapshot_id="3002" root_project_id="1001" root_snapshot_id="3001" + scope="FIL" qualifier="CLA" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001.3002." + status="U" islast="false" depth="2" /> + + <project_measures id="1" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml index 53312994cbe..e3751107915 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml @@ -10,17 +10,25 @@ name="project name" long_name="project name" description="project description" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> - <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="[null]" + <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001" name="org.foo" long_name="org.foo" description="[null]" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <projects id="1003" scope="FIL" qualifier="CLA" kee="foo:org.foo.Bar" root_id="1001" + name="Bar" long_name="org.foo.Bar" description="[null]" + enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path="" - status="U" islast="false" depth="0"/> + status="U" islast="false" depth="0" /> <snapshots id="3002" project_id="1002" parent_snapshot_id="3001" root_project_id="1001" root_snapshot_id="3001" scope="DIR" qualifier="PAC" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001." - status="U" islast="false" depth="1"/> + status="U" islast="false" depth="1" /> + + <snapshots id="3003" project_id="1003" parent_snapshot_id="3002" root_project_id="1001" root_snapshot_id="3001" + scope="FIL" qualifier="CLA" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001.3002." + status="U" islast="false" depth="2" /> <project_measures id="1" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml index 56cd3d33cf7..67c9c6da5de 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml @@ -10,10 +10,14 @@ name="project name" long_name="project name" description="project description" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> - <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="[null]" + <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001" name="org.foo" long_name="org.foo" description="[null]" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <projects id="1003" scope="FIL" qualifier="CLA" kee="foo:org.foo.Bar" root_id="1001" + name="Bar" long_name="org.foo.Bar" description="[null]" + enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path="" status="U" islast="false" depth="0" /> @@ -22,6 +26,10 @@ scope="DIR" qualifier="PAC" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001." status="U" islast="false" depth="1" /> + <snapshots id="3003" project_id="1003" parent_snapshot_id="3002" root_project_id="1001" root_snapshot_id="3001" + scope="FIL" qualifier="CLA" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001.3002." + status="U" islast="false" depth="2" /> + <project_measures id="1" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldNotDelaySavingWithDatabaseOnlyMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldNotDelaySavingWithDatabaseOnlyMeasure-result.xml index 3392e2cf5cd..564742e5ddf 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldNotDelaySavingWithDatabaseOnlyMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldNotDelaySavingWithDatabaseOnlyMeasure-result.xml @@ -10,10 +10,14 @@ name="project name" long_name="project name" description="project description" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> - <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="[null]" + <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001" name="org.foo" long_name="org.foo" description="[null]" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <projects id="1003" scope="FIL" qualifier="CLA" kee="foo:org.foo.Bar" root_id="1001" + name="Bar" long_name="org.foo.Bar" description="[null]" + enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path="" status="U" islast="false" depth="0" /> @@ -22,6 +26,10 @@ scope="DIR" qualifier="PAC" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001." status="U" islast="false" depth="1" /> + <snapshots id="3003" project_id="1003" parent_snapshot_id="3002" root_project_id="1001" root_snapshot_id="3001" + scope="FIL" qualifier="CLA" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001.3002." + status="U" islast="false" depth="2" /> + <project_measures id="1" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml index 927067c218b..f1543adc8cc 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml @@ -10,10 +10,14 @@ name="project name" long_name="project name" description="project description" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> - <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="[null]" + <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001" name="org.foo" long_name="org.foo" description="[null]" enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <projects id="1003" scope="FIL" qualifier="CLA" kee="foo:org.foo.Bar" root_id="1001" + name="Bar" long_name="org.foo.Bar" description="[null]" + enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> + <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path="" status="U" islast="false" depth="0" /> @@ -22,6 +26,10 @@ scope="DIR" qualifier="PAC" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001." status="U" islast="false" depth="1" /> + <snapshots id="3003" project_id="1003" parent_snapshot_id="3002" root_project_id="1001" root_snapshot_id="3001" + scope="FIL" qualifier="CLA" created_at="2010-12-23 00:00:00.00" version="[null]" path="3001.3002." + status="U" islast="false" depth="2" /> + <project_measures id="1" VALUE="12.5" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" |