diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-01-13 17:25:48 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-01-13 17:25:48 +0100 |
commit | 33d67845c7f8271b620e113628765d3acb032f45 (patch) | |
tree | ffd4fe1ed811976da6433e0c8315e36bb00f21e3 | |
parent | 0734a8b37a4416abc6bf57894e0d5d2c3786c5b4 (diff) | |
download | sonarqube-33d67845c7f8271b620e113628765d3acb032f45.tar.gz sonarqube-33d67845c7f8271b620e113628765d3acb032f45.zip |
merge 2.5: fix IT and web service TimeMachine
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb | 12 | ||||
-rw-r--r-- | tests/integration/tests/src/test/java/org/sonar/tests/integration/ViolationsTimeMachineIT.java | 44 |
2 files changed, 47 insertions, 9 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb index 5f089e9e011..be2ca947203 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb @@ -174,13 +174,13 @@ class ProjectMeasure < ActiveRecord::Base def typed_value case metric().val_type when Metric::VALUE_TYPE_INT - value + (value ? value.to_i : nil) when Metric::VALUE_TYPE_FLOAT - value + (value ? value.to_f : nil) when Metric::VALUE_TYPE_PERCENT - value + (value ? value.to_f : nil) when Metric::VALUE_TYPE_MILLISEC - value + (value ? value.to_i : nil) when Metric::VALUE_TYPE_BOOLEAN value when Metric::VALUE_TYPE_LEVEL @@ -188,9 +188,9 @@ class ProjectMeasure < ActiveRecord::Base when Metric::VALUE_TYPE_STRING text_value when Metric::VALUE_TYPE_RATING - text_value || value.to_i.to_s + text_value || (value ? value.to_i : nil) else - text_value || value + text_value || (value ? value.to_i : nil) end end diff --git a/tests/integration/tests/src/test/java/org/sonar/tests/integration/ViolationsTimeMachineIT.java b/tests/integration/tests/src/test/java/org/sonar/tests/integration/ViolationsTimeMachineIT.java index 89354e75ead..19cb48869a2 100644 --- a/tests/integration/tests/src/test/java/org/sonar/tests/integration/ViolationsTimeMachineIT.java +++ b/tests/integration/tests/src/test/java/org/sonar/tests/integration/ViolationsTimeMachineIT.java @@ -1,3 +1,22 @@ +/* + * 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.tests.integration; import org.junit.BeforeClass; @@ -47,10 +66,29 @@ public class ViolationsTimeMachineIT { TimeMachineCell cell2 = timemachine.getCells()[1]; assertThat(cell1.getDate().getMonth(), is(9)); - assertThat(cell1.getValues(), is(new Object[]{0.0, 0.0, 3.0, 4.0, 0.0})); + assertThat(cell1.getValues(), is(new Object[]{0L, 0L, 3L, 4L, 0L})); assertThat(cell2.getDate().getMonth(), is(10)); - assertThat(cell2.getValues(), is(new Object[]{0.0, 0.0, 5.0, 4.0, 0.0})); + assertThat(cell2.getValues(), is(new Object[]{0L, 0L, 5L, 4L, 0L})); + } + + @Test + public void testHistoryOfMeasures() { + TimeMachineQuery query = TimeMachineQuery.createForMetrics(PROJECT, + CoreMetrics.LINES_KEY,//int + CoreMetrics.VIOLATIONS_DENSITY_KEY // double + ); + TimeMachine timemachine = sonar.find(query); + assertThat(timemachine.getCells().length, is(2)); + + TimeMachineCell cell1 = timemachine.getCells()[0]; + TimeMachineCell cell2 = timemachine.getCells()[1]; + + assertThat(cell1.getDate().getMonth(), is(9)); + assertThat(cell1.getValues(), is(new Object[]{30L, 38.1})); + + assertThat(cell2.getDate().getMonth(), is(10)); + assertThat(cell2.getValues(), is(new Object[]{41L, 34.5})); } @Test @@ -79,7 +117,7 @@ public class ViolationsTimeMachineIT { assertThat(timemachine.getCells().length, is(2)); for (TimeMachineCell cell : timemachine.getCells()) { assertThat(cell.getValues().length, is(1)); - assertThat(cell.getValues()[0], is(Double.class)); + assertThat(cell.getValues()[0], is(Long.class)); } timemachine = sonar.find(TimeMachineQuery.createForMetrics(PROJECT)); |