]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5338 When data is coming from the 'test_data' metric, time field can return...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 22 Jul 2014 14:41:02 +0000 (16:41 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 22 Jul 2014 14:41:02 +0000 (16:41 +0200)
sonar-server/src/main/java/org/sonar/server/test/ws/TestsShowAction.java
sonar-server/src/test/java/org/sonar/server/test/ws/TestsShowActionTest.java
sonar-server/src/test/resources/org/sonar/server/test/ws/TestsShowActionTest/show_from_test_data_with_a_time_in_float.json [new file with mode: 0644]

index ca756649a807b36eaecccb9722a0ffc5c64d43a0..4213c5553beed43c63a67f606f4eab0ceedf2a7f 100644 (file)
@@ -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) {
index 49c28868be609a091920dfa2be71acae3180422d..9f7648e975a66afc61fe6588dac40305785d6f18 100644 (file)
@@ -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 (file)
index 0000000..3f45bdb
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "tests": [
+    {
+      "name": "test1",
+      "status": "OK",
+      "durationInMs": 12
+    }
+  ]
+}