aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-10-19 16:26:14 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-10-21 14:11:11 +0200
commit4181367147d2eed06119ecdc39820334f664432c (patch)
tree00c0ded7ce5a12cc9f4571d5e83023eabfbf8722 /server/sonar-server
parent24c4856b33cfb6a44f05863eedc86df1b2e04ced (diff)
downloadsonarqube-4181367147d2eed06119ecdc39820334f664432c.tar.gz
sonarqube-4181367147d2eed06119ecdc39820334f664432c.zip
SONAR-6416 apply naming conventions to parameters of WS api/tests
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java42
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java14
5 files changed, 49 insertions, 42 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java
index f862d5dd85d..a1c01d3d5ea 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java
@@ -98,7 +98,7 @@ public class TestIndex extends BaseIndex {
return new TestDoc(hit.sourceAsMap());
}
- throw new IllegalStateException(String.format("Test uuid '%s' not found", testUuid));
+ throw new IllegalStateException(String.format("Test id '%s' not found", testUuid));
}
public SearchResult<TestDoc> searchByTestUuid(String testUuid, SearchOptions searchOptions) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java
index bfa087156a6..bcbd4b11096 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java
@@ -31,6 +31,7 @@ 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;
import org.sonar.db.MyBatis;
@@ -44,7 +45,7 @@ import org.sonarqube.ws.WsTests;
public class CoveredFilesAction implements TestsWsAction {
- public static final String TEST_UUID = "testUuid";
+ public static final String TEST_ID = "testId";
private final DbClient dbClient;
private final TestIndex index;
@@ -66,18 +67,18 @@ public class CoveredFilesAction implements TestsWsAction {
.addPagingParams(100);
action
- .createParam(TEST_UUID)
+ .createParam(TEST_ID)
.setRequired(true)
- .setDescription("Test uuid")
- .setExampleValue("ce4c03d6-430f-40a9-b777-ad877c00aa4d");
+ .setDescription("Test ID")
+ .setExampleValue(Uuids.UUID_EXAMPLE_01);
}
@Override
public void handle(Request request, Response response) throws Exception {
- String testUuid = request.mandatoryParam(TEST_UUID);
- userSession.checkComponentUuidPermission(UserRole.CODEVIEWER, index.searchByTestUuid(testUuid).fileUuid());
+ String testId = request.mandatoryParam(TEST_ID);
+ userSession.checkComponentUuidPermission(UserRole.CODEVIEWER, index.searchByTestUuid(testId).fileUuid());
- List<CoveredFileDoc> coveredFiles = index.coveredFiles(testUuid);
+ List<CoveredFileDoc> coveredFiles = index.coveredFiles(testId);
Map<String, ComponentDto> componentsByUuid = buildComponentsByUuid(coveredFiles);
WsTests.CoveredFilesResponse.Builder responseBuilder = WsTests.CoveredFilesResponse.newBuilder();
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 17917e5728a..da29bcaafe9 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
@@ -51,10 +51,10 @@ import org.sonarqube.ws.Common;
import org.sonarqube.ws.WsTests;
public class ListAction implements TestsWsAction {
- public static final String TEST_UUID = "testUuid";
- public static final String TEST_FILE_UUID = "testFileUuid";
+ public static final String TEST_ID = "testId";
+ public static final String TEST_FILE_ID = "testFileId";
public static final String TEST_FILE_KEY = "testFileKey";
- public static final String SOURCE_FILE_UUID = "sourceFileUuid";
+ public static final String SOURCE_FILE_ID = "sourceFileId";
public static final String SOURCE_FILE_LINE_NUMBER = "sourceFileLineNumber";
private final DbClient dbClient;
@@ -78,9 +78,9 @@ public class ListAction implements TestsWsAction {
"Require Browse permission on file's project.<br /> " +
"One (and only one) of the following combination of parameters must be provided: " +
"<ul>" +
- "<li>Test file UUID</li>" +
- "<li>Test UUID</li>" +
- "<li>Source file UUID and Source file line number</li>" +
+ "<li>" + TEST_FILE_ID + "</li>" +
+ "<li>" + TEST_ID + "</li>" +
+ "<li>" + SOURCE_FILE_ID + " and " + SOURCE_FILE_LINE_NUMBER + "</li>" +
"</ul>")
.setSince("5.2")
.setResponseExample(Resources.getResource(getClass(), "tests-example-list.json"))
@@ -88,37 +88,37 @@ public class ListAction implements TestsWsAction {
.addPagingParams(100);
action
- .createParam(TEST_FILE_UUID)
- .setDescription("Test file UUID")
+ .createParam(TEST_FILE_ID)
+ .setDescription("ID of test file")
.setExampleValue(Uuids.UUID_EXAMPLE_01);
action
.createParam(TEST_FILE_KEY)
- .setDescription("Test file key")
- .setExampleValue("org.codehaus.sonar:sonar-server:src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java");
+ .setDescription("Key of test file")
+ .setExampleValue("MY_PROJECT:src/test/java/foo/BarTest.java");
action
- .createParam(TEST_UUID)
- .setDescription("Test UUID")
+ .createParam(TEST_ID)
+ .setDescription("ID of test")
.setExampleValue(Uuids.UUID_EXAMPLE_02);
action
- .createParam(SOURCE_FILE_UUID)
- .setDescription("Source file UUID. Must be provided with the source file line number.")
+ .createParam(SOURCE_FILE_ID)
+ .setDescription("IF of source file. Must be provided with the source file line number.")
.setExampleValue(Uuids.UUID_EXAMPLE_03);
action
.createParam(SOURCE_FILE_LINE_NUMBER)
- .setDescription("Source file line number. Must be provided with the source file UUID.")
+ .setDescription("Source file line number. Must be provided with the source file ID.")
.setExampleValue("10");
}
@Override
public void handle(Request request, Response response) throws Exception {
- String testUuid = request.param(TEST_UUID);
- String testFileUuid = request.param(TEST_FILE_UUID);
+ String testUuid = request.param(TEST_ID);
+ String testFileUuid = request.param(TEST_FILE_ID);
String testFileKey = request.param(TEST_FILE_KEY);
- String sourceFileUuid = request.param(SOURCE_FILE_UUID);
+ String sourceFileUuid = request.param(SOURCE_FILE_ID);
Integer sourceFileLineNumber = request.paramAsInt(SOURCE_FILE_LINE_NUMBER);
SearchOptions searchOptions = new SearchOptions().setPage(
request.mandatoryParamAsInt(WebService.Param.PAGE),
@@ -153,7 +153,9 @@ public class ListAction implements TestsWsAction {
testBuilder.setFileName(component.longName());
}
testBuilder.setStatus(WsTests.TestStatus.valueOf(testDoc.status()));
- testBuilder.setDurationInMs(testDoc.durationInMs());
+ if (testDoc.durationInMs() != null) {
+ testBuilder.setDurationInMs(testDoc.durationInMs());
+ }
testBuilder.setCoveredLines(coveredLines(testDoc.coveredFiles()));
if (testDoc.message() != null) {
testBuilder.setMessage(testDoc.message());
@@ -163,7 +165,7 @@ public class ListAction implements TestsWsAction {
}
responseBuilder.addTests(testBuilder.build());
}
- WsUtils.writeProtobuf(responseBuilder.build(), request, response);
+ WsUtils.writeProtobuf(responseBuilder.build(), request, response);
}
private static int coveredLines(List<CoveredFileDoc> coveredFiles) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java
index fbfe377f5f5..fae15c0bb06 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java
@@ -40,9 +40,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
-import static org.sonar.server.test.ws.CoveredFilesAction.TEST_UUID;
+import static org.sonar.server.test.ws.CoveredFilesAction.TEST_ID;
public class CoveredFilesActionTest {
+
+ public static final String FILE_1_ID = "FILE1";
+ public static final String FILE_2_ID = "FILE2";
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -63,15 +67,15 @@ public class CoveredFilesActionTest {
when(testIndex.searchByTestUuid(anyString()).fileUuid()).thenReturn("test-file-uuid");
when(testIndex.coveredFiles("test-uuid")).thenReturn(Arrays.asList(
- new CoveredFileDoc().setFileUuid("FILE1").setCoveredLines(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
- new CoveredFileDoc().setFileUuid("FILE2").setCoveredLines(Arrays.asList(1, 2, 3))
- ));
+ new CoveredFileDoc().setFileUuid(FILE_1_ID).setCoveredLines(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
+ new CoveredFileDoc().setFileUuid(FILE_2_ID).setCoveredLines(Arrays.asList(1, 2, 3))
+ ));
when(dbClient.componentDao().selectByUuids(any(DbSession.class), anyList())).thenReturn(
Arrays.asList(
- newFileDto(newProjectDto(), "FILE1").setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"),
- newFileDto(newProjectDto(), "FILE2").setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
+ newFileDto(newProjectDto(), FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"),
+ newFileDto(newProjectDto(), FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
- WsTester.TestRequest request = ws.newGetRequest("api/tests", "covered_files").setParam(TEST_UUID, "test-uuid");
+ WsTester.TestRequest request = ws.newGetRequest("api/tests", "covered_files").setParam(TEST_ID, "test-uuid");
request.execute().assertJson(getClass(), "tests-covered-files.json");
}
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 4280af90d3b..4bc61ea3f15 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
@@ -90,7 +90,7 @@ public class ListActionTest {
.setStackTrace(TestFile1.STACKTRACE)
);
- WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_UUID, TestFile1.UUID);
+ WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_ID, TestFile1.UUID);
request.execute().assertJson(getClass(), "list-test-uuid.json");
}
@@ -113,7 +113,7 @@ public class ListActionTest {
.setMessage(TestFile1.MESSAGE)
.setStackTrace(TestFile1.STACKTRACE));
- WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_UUID, TestFile1.FILE_UUID);
+ WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_ID, TestFile1.FILE_UUID);
request.execute().assertJson(getClass(), "list-test-uuid.json");
}
@@ -187,7 +187,7 @@ public class ListActionTest {
.setStackTrace(TestFile2.STACKTRACE));
WsTester.TestRequest request = ws.newGetRequest("api/tests", "list")
- .setParam(ListAction.SOURCE_FILE_UUID, mainFileUuid)
+ .setParam(ListAction.SOURCE_FILE_ID, mainFileUuid)
.setParam(ListAction.SOURCE_FILE_LINE_NUMBER, "10");
request.execute().assertJson(getClass(), "list-main-file.json");
@@ -200,7 +200,7 @@ public class ListActionTest {
@Test(expected = IllegalArgumentException.class)
public void fail_when_main_file_uuid_without_line_number() throws Exception {
- ws.newGetRequest("api/tests", "list").setParam(ListAction.SOURCE_FILE_UUID, "ANY-UUID").execute();
+ ws.newGetRequest("api/tests", "list").setParam(ListAction.SOURCE_FILE_ID, "ANY-UUID").execute();
}
@Test(expected = ForbiddenException.class)
@@ -208,7 +208,7 @@ public class ListActionTest {
userSessionRule.addProjectUuidPermissions(UserRole.USER, TestFile1.PROJECT_UUID);
dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
db.getSession().commit();
- ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_UUID, TestFile1.FILE_UUID).execute();
+ ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_ID, TestFile1.FILE_UUID).execute();
}
@Test(expected = ForbiddenException.class)
@@ -216,7 +216,7 @@ public class ListActionTest {
userSessionRule.addProjectUuidPermissions(UserRole.USER, TestFile1.PROJECT_UUID);
dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
db.getSession().commit();
- ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_UUID, TestFile1.FILE_UUID).execute();
+ ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_ID, TestFile1.FILE_UUID).execute();
}
@Test(expected = ForbiddenException.class)
@@ -235,7 +235,7 @@ public class ListActionTest {
db.getSession().commit();
ws.newGetRequest("api/tests", "list")
- .setParam(ListAction.SOURCE_FILE_UUID, mainFileUuid)
+ .setParam(ListAction.SOURCE_FILE_ID, mainFileUuid)
.setParam(ListAction.SOURCE_FILE_LINE_NUMBER, "10")
.execute();
}