diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-07-22 16:41:02 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-07-22 16:41:02 +0200 |
commit | 8c41e822e3a24b4f2504a15330188ce609d3b573 (patch) | |
tree | 0ead9f70d0e88b43715a68020fe26331c4ab917f | |
parent | d002e2a3a694c7477ca337d45e0025f9402ecfa3 (diff) | |
download | sonarqube-8c41e822e3a24b4f2504a15330188ce609d3b573.tar.gz sonarqube-8c41e822e3a24b4f2504a15330188ce609d3b573.zip |
SONAR-5338 When data is coming from the 'test_data' metric, time field can return a float
3 files changed, 25 insertions, 1 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/test/ws/TestsShowAction.java b/sonar-server/src/main/java/org/sonar/server/test/ws/TestsShowAction.java index ca756649a80..4213c5553be 100644 --- a/sonar-server/src/main/java/org/sonar/server/test/ws/TestsShowAction.java +++ b/sonar-server/src/main/java/org/sonar/server/test/ws/TestsShowAction.java @@ -117,7 +117,8 @@ public class TestsShowAction implements RequestHandler { json.prop("name", cursor.getAttrValue("name")); json.prop("status", cursor.getAttrValue("status").toUpperCase()); - json.prop("durationInMs", Long.parseLong(cursor.getAttrValue("time"))); + // time can contain float value, we have to truncate it + json.prop("durationInMs", ((Double) Double.parseDouble(cursor.getAttrValue("time"))).longValue()); SMInputCursor errorCursor = cursor.childElementCursor(); if (errorCursor.getNext() != null) { diff --git a/sonar-server/src/test/java/org/sonar/server/test/ws/TestsShowActionTest.java b/sonar-server/src/test/java/org/sonar/server/test/ws/TestsShowActionTest.java index 49c28868be6..9f7648e975a 100644 --- a/sonar-server/src/test/java/org/sonar/server/test/ws/TestsShowActionTest.java +++ b/sonar-server/src/test/java/org/sonar/server/test/ws/TestsShowActionTest.java @@ -117,6 +117,20 @@ public class TestsShowActionTest { request.execute().assertJson(getClass(), "show_from_test_data.json"); } + @Test + public void show_from_test_data_with_a_time_in_float() throws Exception { + MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "SonarQube", TEST_PLAN_KEY); + + when(measureDao.findByComponentKeyAndMetricKey(TEST_PLAN_KEY, "test_data", session)).thenReturn(MeasureDto.createFor(MeasureKey.of(TEST_PLAN_KEY, "test_data")) + .setTextValue("<tests-details>" + + "<testcase status=\"ok\" time=\"12.5\" name=\"test1\"/>" + + "</tests-details>")); + + WsTester.TestRequest request = tester.newGetRequest("api/tests", "show").setParam("key", TEST_PLAN_KEY); + + request.execute().assertJson(getClass(), "show_from_test_data_with_a_time_in_float.json"); + } + private MutableTestCase testCase(String name, TestCase.Status status, Long durationInMs, int coveredLines, @Nullable String message, @Nullable String stackTrace) { MutableTestCase testCase = mock(MutableTestCase.class); when(testCase.name()).thenReturn(name); diff --git a/sonar-server/src/test/resources/org/sonar/server/test/ws/TestsShowActionTest/show_from_test_data_with_a_time_in_float.json b/sonar-server/src/test/resources/org/sonar/server/test/ws/TestsShowActionTest/show_from_test_data_with_a_time_in_float.json new file mode 100644 index 00000000000..3f45bdbbe10 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/test/ws/TestsShowActionTest/show_from_test_data_with_a_time_in_float.json @@ -0,0 +1,9 @@ +{ + "tests": [ + { + "name": "test1", + "status": "OK", + "durationInMs": 12 + } + ] +} |