JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/testing/suite/CoverageTrackingTest/tests-expected.json"), "UTF-8"), tests, false);
String covered_files = orchestrator.getServer().adminWsClient()
- .get("api/tests/covered_files", "testUuid", extractSuccessfulTestUuid(tests));
+ .get("api/tests/covered_files", "testId", extractSuccessfulTestId(tests));
JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/testing/suite/CoverageTrackingTest/covered_files-expected.json"), "UTF-8"), covered_files, false);
}
- private String extractSuccessfulTestUuid(String json) {
+ private String extractSuccessfulTestId(String json) {
Matcher jsonObjectMatcher = Pattern.compile(".*\\{((.*?)success(.*?))\\}.*", Pattern.MULTILINE).matcher(json);
jsonObjectMatcher.find();
- Matcher uuidMatcher = Pattern.compile(".*\"testUuid\"\\s*?:\\s*?\"(\\S*?)\".*", Pattern.MULTILINE).matcher(jsonObjectMatcher.group(1));
- return uuidMatcher.find() ? uuidMatcher.group(1) : "";
+ Matcher idMatcher = Pattern.compile(".*\"id\"\\s*?:\\s*?\"(\\S*?)\".*", Pattern.MULTILINE).matcher(jsonObjectMatcher.group(1));
+ return idMatcher.find() ? idMatcher.group(1) : "";
}
}
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) {
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;
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;
.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();
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;
"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"))
.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),
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());
}
responseBuilder.addTests(testBuilder.build());
}
- WsUtils.writeProtobuf(responseBuilder.build(), request, response);
+ WsUtils.writeProtobuf(responseBuilder.build(), request, response);
}
private static int coveredLines(List<CoveredFileDoc> coveredFiles) {
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();
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");
}
.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");
}
.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");
}
.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");
@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)
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)
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)
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();
}