From: Teryk Bellahsene Date: Mon, 27 Jun 2016 22:38:00 +0000 (+0200) Subject: SONAR-7789 WS api/qualityprofiles/search return lastUsed field when searching by... X-Git-Tag: 6.0-RC1~248 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a903ae093c0744034e74ae6fab20f2b50a1250b;p=sonarqube.git SONAR-7789 WS api/qualityprofiles/search return lastUsed field when searching by project key --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java index 0a74e250924..d05b2c18604 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java @@ -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)) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java index c639f67cd5b..2d60e4043e0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java @@ -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()); } } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index dcf5081e29a..02e23926595 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -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