From 018423d4751bf1f508433127bc7271f72232e406 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 24 Aug 2017 19:05:26 +0200 Subject: [PATCH] SONAR-9616 Return branch in api/tests/list --- .../java/org/sonar/server/test/ws/ListAction.java | 9 ++++++--- .../org/sonar/server/test/ws/ListActionTest.java | 13 +++++++++---- sonar-ws/src/main/protobuf/ws-tests.proto | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java index 4d74a46d916..41d40efd5dc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java @@ -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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java index f38ce3efc24..48ff6b83a57 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java @@ -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 diff --git a/sonar-ws/src/main/protobuf/ws-tests.proto b/sonar-ws/src/main/protobuf/ws-tests.proto index 13a070a34a2..7f98ff6aa13 100644 --- a/sonar-ws/src/main/protobuf/ws-tests.proto +++ b/sonar-ws/src/main/protobuf/ws-tests.proto @@ -56,6 +56,7 @@ message Test { optional int32 coveredLines = 8; optional string message = 9; optional string stacktrace = 10; + optional string fileBranch = 11; } enum TestStatus { -- 2.39.5