]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7789 WS api/qualityprofiles/search return lastUsed field when searching by...
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 27 Jun 2016 22:38:00 +0000 (00:38 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 27 Jun 2016 22:50:32 +0000 (00:50 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java

index 0a74e2509241dd953c08a38fc95fcf31ff3d17ad..d05b2c18604d79447e7375a4adce3267bb16dbbf 100644 (file)
@@ -93,7 +93,7 @@ public class SearchAction implements QProfileWsAction {
   }
 
   private static SearchWsRequest toSearchWsRequest(Request request) {
-    return new SearchWsRequest()
+    return  new SearchWsRequest()
       .setProjectKey(request.param(PARAM_PROJECT_KEY))
       .setProfileName(request.param(PARAM_PROFILE_NAME))
       .setDefaults(request.paramAsBoolean(PARAM_DEFAULTS))
index c639f67cd5b83f663b22bf40d7a47561bbc12e27..2d60e4043e00055adc9789846c4240d564ada23c 100644 (file)
@@ -244,7 +244,8 @@ public class SearchDataLoader {
         .setName(input.getName())
         .setLanguage(input.getLanguage())
         .setDefault(input.isDefault())
-        .setRulesUpdatedAt(input.getRulesUpdatedAt());
+        .setRulesUpdatedAt(input.getRulesUpdatedAt())
+        .setLastUsed(input.getLastUsed());
     }
   }
 }
index dcf5081e29a915285e21403c1f931edd6218f573..02e2392659580214d0c792c76d2c466861da2dd1 100644 (file)
@@ -48,11 +48,14 @@ import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 
 import static com.google.common.base.Throwables.propagate;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.api.utils.DateUtils.formatDateTime;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
@@ -148,29 +151,36 @@ public class SearchActionTest {
 
   @Test
   public void search_for_project_qp() {
+    long time = DateUtils.parseDateTime("2016-12-22T19:10:03+0100").getTime();
     QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345")
       .setLanguage(xoo1.getKey())
-      .setRulesUpdatedAtAsDate(new Date())
+      .setRulesUpdatedAt("2016-12-21T19:10:03+0100")
+      .setLastUsed(time)
       .setName("Sonar way");
     QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345")
       .setLanguage(xoo2.getKey())
-      .setRulesUpdatedAtAsDate(new Date())
+      .setRulesUpdatedAt("2016-12-21T19:10:03+0100")
+      .setLastUsed(time)
       .setName("Sonar way");
     QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678")
       .setLanguage(xoo1.getKey())
-      .setRulesUpdatedAtAsDate(new Date())
+      .setRulesUpdatedAt("2016-12-21T19:10:03+0100")
+      .setLastUsed(time)
       .setName("Another way");
     ComponentDto project = newProjectDto("project-uuid");
     qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
     qualityProfileDb.insertProjectWithQualityProfileAssociations(project, qualityProfileOnXoo1, qualityProfileOnXoo2);
 
-    String result = ws.newRequest()
-      .setParam(PARAM_PROJECT_KEY, project.key())
-      .execute().getInput();
+    SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT_KEY, project.key()));
 
-    assertThat(result)
+    assertThat(result.getProfilesList())
+      .hasSize(2)
+      .extracting(QualityProfile::getKey)
       .contains("sonar-way-xoo1-12345", "sonar-way-xoo2-12345")
       .doesNotContain("sonar-way-xoo1-45678");
+    assertThat(result.getProfilesList())
+      .extracting(QualityProfile::getRulesUpdatedAt, QualityProfile::getLastUsed)
+      .contains(tuple("2016-12-21T19:10:03+0100", formatDateTime(time)));
   }
 
   @Test