]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6416 apply naming conventions to parameters of WS api/tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 19 Oct 2015 14:26:14 +0000 (16:26 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 21 Oct 2015 12:11:11 +0000 (14:11 +0200)
it/it-tests/src/test/java/analysis/suite/testing/CoverageTrackingTest.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java
server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java
server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java

index 5e119d5b1c08ec3421cbe0f470b0d9fa73f19268..a84e4ace549654fdf3bb7ecead19b053d7523685 100644 (file)
@@ -36,15 +36,15 @@ public class CoverageTrackingTest {
     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) : "";
   }
 }
index f862d5dd85d141cdf9a1ab1f583664ffff9d2374..a1c01d3d5ea216b162c2cb961c21bf9ae9225670 100644 (file)
@@ -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) {
index bfa087156a66cb431b12cf218170bffb132193d7..bcbd4b11096d5fdf0dd3556b111fa606be11e90e 100644 (file)
@@ -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();
index 17917e5728af59ec5d226c48ffcfbc8b97b48821..da29bcaafe90dc2b4b8827a9b5aabf9fa61330a7 100644 (file)
@@ -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) {
index fbfe377f5f5edd503f5292c70dc8d08f9e3ffe46..fae15c0bb0635fb5ab743d122434fa8c691dc62e 100644 (file)
@@ -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");
   }
index 4280af90d3b62ec5b9ccf740bcb92615d66588f6..4bc61ea3f15061c6b73df1ed6e8f5e1be58e60ad 100644 (file)
@@ -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();
   }