]> source.dussan.org Git - sonarqube.git/commitdiff
WS project_analyses/search accepts portfolios
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 11 Sep 2017 16:22:06 +0000 (18:22 +0200)
committerTeryk Bellahsene <teryk@users.noreply.github.com>
Wed, 20 Sep 2017 07:15:23 +0000 (09:15 +0200)
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java

index 1b1dc030b0b034b73816f150534a198dd22475d4..455441d3a127e4489373c8f996e2cb9f1b9ff305 100644 (file)
@@ -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<String> ALLOWED_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.APP);
+  private static final Set<String> 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);
   }
 
index c711aec2fa135ce92138604ef5e9f5815f8fd6ec..4d5954ce0fe1e12cbe9b29d171f2e9d6bc4855ae 100644 (file)
@@ -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<Analysis> 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<Analysis> 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