]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Return branch in api/tests/list
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 24 Aug 2017 17:05:26 +0000 (19:05 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:52 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
sonar-ws/src/main/protobuf/ws-tests.proto

index 4d74a46d9169d695fc838eb8b488da8dfc6ffb13..41d40efd5dceb9cc1934e516531b78ac7fb90951 100644 (file)
@@ -28,10 +28,10 @@ import java.util.Map;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.web.UserRole;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -50,7 +50,8 @@ import org.sonarqube.ws.WsTests;
 
 import static org.sonar.api.server.ws.WebService.Param.PAGE;
 import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
-import static org.sonar.api.web.UserRole.*;
+import static org.sonar.api.web.UserRole.CODEVIEWER;
+import static org.sonar.core.util.Protobuf.setNullable;
 import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
 import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
 import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
@@ -96,6 +97,7 @@ public class ListAction implements TestsWsAction {
       .setResponseExample(Resources.getResource(getClass(), "tests-example-list.json"))
       .setDeprecatedSince("5.6")
       .setHandler(this)
+      .setChangelog(new Change("6.6", "\"fileBranch\" field is now returned"))
       .addPagingParams(100, MAX_LIMIT);
 
     action
@@ -170,8 +172,9 @@ public class ListAction implements TestsWsAction {
       testBuilder.setFileId(testDoc.fileUuid());
       ComponentDto component = componentsByTestFileUuid.get(testDoc.fileUuid());
       if (component != null) {
-        testBuilder.setFileKey(component.getDbKey());
+        testBuilder.setFileKey(component.getKey());
         testBuilder.setFileName(component.longName());
+        setNullable(component.getBranch(), testBuilder::setFileBranch);
       }
       testBuilder.setStatus(WsTests.TestStatus.valueOf(testDoc.status()));
       if (testDoc.durationInMs() != null) {
index f38ce3efc249a0155360376b8303f72f387352ee..48ff6b83a5784c9d3873f9be0a06ad4fc6e45816 100644 (file)
@@ -47,6 +47,7 @@ import org.sonarqube.ws.WsTests.ListResponse;
 import static java.lang.String.format;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.USER;
@@ -200,8 +201,10 @@ public class ListActionTest {
       .setParam("branch", testFile.getBranch()));
 
     assertThat(request.getTestsList())
-      .extracting(WsTests.Test::getId)
-      .containsOnly(test1.getUuid(), test2.getUuid());
+      .extracting(WsTests.Test::getId, WsTests.Test::getFileKey, WsTests.Test::getFileBranch)
+      .containsOnly(
+        tuple(test1.getUuid(), testFile.getKey(), testFile.getBranch()),
+        tuple(test2.getUuid(), testFile.getKey(), testFile.getBranch()));
   }
 
   @Test
@@ -258,8 +261,10 @@ public class ListActionTest {
       .setParam("branch", testFile.getBranch()));
 
     assertThat(request.getTestsList())
-      .extracting(WsTests.Test::getId)
-      .containsOnly(test1.getUuid(), test3.getUuid());
+      .extracting(WsTests.Test::getId, WsTests.Test::getFileKey, WsTests.Test::getFileBranch)
+      .containsOnly(
+        tuple(test1.getUuid(), testFile.getKey(), testFile.getBranch()),
+        tuple(test3.getUuid(), testFile.getKey(), testFile.getBranch()));
   }
 
   @Test
index 13a070a34a2db7dba2c00b6f3b7a75bd404f4388..7f98ff6aa1335c51fb4e4a597648b73ed5a6c57d 100644 (file)
@@ -56,6 +56,7 @@ message Test {
   optional int32 coveredLines = 8;
   optional string message = 9;
   optional string stacktrace = 10;
+  optional string fileBranch = 11;
 }
 
 enum TestStatus {