]> source.dussan.org Git - sonarqube.git/commitdiff
fix OrganizationIt 1596/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 31 Jan 2017 08:41:49 +0000 (09:41 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 31 Jan 2017 09:38:09 +0000 (10:38 +0100)
it/it-tests/src/test/java/it/organization/OrganizationIt.java
sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java

index e950f73cbcae6206c76be1302593c49c195770b4..327c9f2499e91096785a42a30ecb562e4476ee0d 100644 (file)
@@ -265,23 +265,26 @@ public class OrganizationIt {
       .contains("grp1", "grp2");
 
     ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample",
-        "sonar.organization", orgKeyAndName);
+      "sonar.organization", orgKeyAndName);
     ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components();
-    assertThat(searchSampleProject(componentsService).getComponentsList()).hasSize(1);
+    assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsList()).hasSize(1);
 
     adminOrganizationService.delete(orgKeyAndName);
 
-    assertThat(searchSampleProject(componentsService).getComponentsList()).hasSize(0);
+    expect404HttpError(() -> searchSampleProject(orgKeyAndName, componentsService));
     assertThat(groupManagement.getUserGroups("bob").getGroups())
-        .extracting(Groups.Group::getName)
-        .doesNotContain("grp1", "grp2");
+      .extracting(Groups.Group::getName)
+      .doesNotContain("grp1", "grp2");
 
     verifyNoExtraOrganization();
   }
 
-  private WsComponents.SearchWsResponse searchSampleProject(ComponentsService componentsService) {
+  private WsComponents.SearchWsResponse searchSampleProject(String organizationKey, ComponentsService componentsService) {
     return componentsService
-      .search(new org.sonarqube.ws.client.component.SearchWsRequest().setQualifiers(singletonList("TRK")).setQuery("sample"));
+      .search(new org.sonarqube.ws.client.component.SearchWsRequest()
+        .setOrganization(organizationKey)
+        .setQualifiers(singletonList("TRK"))
+        .setQuery("sample"));
   }
 
   private void expect403HttpError(Runnable runnable) {
@@ -293,6 +296,15 @@ public class OrganizationIt {
     }
   }
 
+  private void expect404HttpError(Runnable runnable) {
+    try {
+      runnable.run();
+      fail("Ws call should have failed");
+    } catch (HttpException e) {
+      assertThat(e.code()).isEqualTo(404);
+    }
+  }
+
   private void verifyNoExtraOrganization() {
     Organizations.SearchWsResponse searchWsResponse = anonymousOrganizationService.search(new SearchWsRequest.Builder().build());
     List<Organizations.Organization> organizationsList = searchWsResponse.getOrganizationsList();
@@ -302,7 +314,8 @@ public class OrganizationIt {
 
   private void verifySingleSearchResult(Organizations.Organization createdOrganization, String name, String description, String url,
     String avatarUrl) {
-    List<Organizations.Organization> organizations = anonymousOrganizationService.search(new SearchWsRequest.Builder().build()).getOrganizationsList();
+    List<Organizations.Organization> organizations = anonymousOrganizationService.search(new SearchWsRequest.Builder()
+        .build()).getOrganizationsList();
     assertThat(organizations).hasSize(2);
     Organizations.Organization searchedOrganization = organizations.stream()
       .filter(organization -> !DEFAULT_ORGANIZATION_KEY.equals(organization.getKey()))
index bd555b39a44ce69a67ca935e390167a26743f28c..64bf9753360b9b98960ac0797853ed2f4da6674e 100644 (file)
@@ -58,6 +58,7 @@ public class ComponentsService extends BaseService {
 
   public SearchWsResponse search(SearchWsRequest request) {
     GetRequest get = new GetRequest(path(ACTION_SEARCH))
+      .setParam(PARAM_ORGANIZATION, request.getOrganization())
       .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(request.getQualifiers()))
       .setParam(Param.PAGE, request.getPage())
       .setParam(Param.PAGE_SIZE, request.getPageSize())