From 22f492680dc81eb607881fe8ca39671085246a77 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Mon, 11 Sep 2017 18:22:06 +0200 Subject: [PATCH] WS project_analyses/search accepts portfolios --- .../projectanalysis/ws/SearchAction.java | 4 +-- .../projectanalysis/ws/SearchActionTest.java | 35 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java index 1b1dc030b0b..455441d3a12 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java @@ -60,7 +60,7 @@ import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameter import static org.sonarqube.ws.client.projectanalysis.SearchRequest.DEFAULT_PAGE_SIZE; public class SearchAction implements ProjectAnalysesWsAction { - private static final Set ALLOWED_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.APP); + private static final Set ALLOWED_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.APP, Qualifiers.VIEW); private final DbClient dbClient; private final ComponentFinder componentFinder; @@ -163,7 +163,7 @@ public class SearchAction implements ProjectAnalysesWsAction { private void addProject(SearchData.Builder data) { ComponentDto project = loadComponent(data.getDbSession(), data.getRequest()); - checkArgument(Scopes.PROJECT.equals(project.scope()) && ALLOWED_QUALIFIERS.contains(project.qualifier()), "A project or application is required"); + checkArgument(Scopes.PROJECT.equals(project.scope()) && ALLOWED_QUALIFIERS.contains(project.qualifier()), "A project, portfolio or application is required"); data.setProject(project); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java index c711aec2fa1..4d5954ce0fe 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java @@ -56,6 +56,7 @@ import static org.sonar.api.utils.DateUtils.formatDate; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.core.util.Protobuf.setNullable; +import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.SnapshotTesting.newAnalysis; import static org.sonar.db.event.EventTesting.newEvent; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; @@ -171,8 +172,25 @@ public class SearchActionTest { List result = call(application.getDbKey()).getAnalysesList(); - assertThat(result).hasSize(3); - assertThat(result).extracting(Analysis::getKey).containsExactly(thirdAnalysis.getUuid(), secondAnalysis.getUuid(), firstAnalysis.getUuid()); + assertThat(result) + .hasSize(3) + .extracting(Analysis::getKey).containsExactly(thirdAnalysis.getUuid(), secondAnalysis.getUuid(), firstAnalysis.getUuid()); + } + + @Test + public void return_analyses_of_portfolio() { + OrganizationDto organization = db.organizations().insert(); + ComponentDto view = db.components().insertView(organization); + userSession.registerComponents(view); + SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(1_000_000L)); + SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(2_000_000L)); + SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(3_000_000L)); + + List result = call(view.getDbKey()).getAnalysesList(); + + assertThat(result) + .hasSize(3) + .extracting(Analysis::getKey).containsExactly(thirdAnalysis.getUuid(), secondAnalysis.getUuid(), firstAnalysis.getUuid()); } @Test @@ -370,15 +388,16 @@ public class SearchActionTest { } @Test - public void fail_if_not_a_project_or_application() { - ComponentDto view = db.components().insertView(); - db.components().insertSnapshot(newAnalysis(view)); - userSession.registerComponents(view); + public void fail_if_not_a_project_portfolio_or_application() { + ComponentDto project = db.components().insertPrivateProject(); + ComponentDto file = db.components().insertComponent(newFileDto(project)); + db.components().insertSnapshot(newAnalysis(project)); + userSession.registerComponents(project, file); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("A project or application is required"); + expectedException.expectMessage("A project, portfolio or application is required"); - call(view.getDbKey()); + call(file.getDbKey()); } @Test -- 2.39.5