From 8c41e822e3a24b4f2504a15330188ce609d3b573 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 22 Jul 2014 16:41:02 +0200 Subject: [PATCH] SONAR-5338 When data is coming from the 'test_data' metric, time field can return a float --- .../org/sonar/server/test/ws/TestsShowAction.java | 3 ++- .../sonar/server/test/ws/TestsShowActionTest.java | 14 ++++++++++++++ .../show_from_test_data_with_a_time_in_float.json | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 sonar-server/src/test/resources/org/sonar/server/test/ws/TestsShowActionTest/show_from_test_data_with_a_time_in_float.json 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("" + + "" + + "")); + + 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 + } + ] +} -- 2.39.5