]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13999 remove orgs from favorite WS
authorMichal Duda <michal.duda@sonarsource.com>
Tue, 8 Dec 2020 15:55:56 +0000 (16:55 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Dec 2020 20:09:35 +0000 (20:09 +0000)
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/favorite/ws/search-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java
sonar-ws/src/main/protobuf/ws-favorites.proto

index e91b49a23ecf474af51d889f33b20477f3987f5a..d617b3cddaaa68be1608343a80adb22733a32541 100644 (file)
@@ -185,9 +185,8 @@ public class ComponentDbTester {
     return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, defaults(), dtoPopulator);
   }
 
-
   public final ComponentDto insertPrivateProjectWithCustomBranch(String branchKey) {
-    return insertPrivateProjectWithCustomBranch(db.getDefaultOrganization(), b ->  b.setBranchType(BRANCH).setKey(branchKey), defaults());
+    return insertPrivateProjectWithCustomBranch(db.getDefaultOrganization(), b -> b.setBranchType(BRANCH).setKey(branchKey), defaults());
   }
 
   public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator) {
@@ -342,21 +341,21 @@ public class ComponentDbTester {
   }
 
   public void addApplicationProject(ComponentDto application, ComponentDto... projects) {
-    for(ComponentDto project : projects){
+    for (ComponentDto project : projects) {
       dbClient.applicationProjectsDao().addProject(dbSession, application.uuid(), project.uuid());
     }
     db.commit();
   }
 
   public void addApplicationProject(ProjectDto application, ProjectDto... projects) {
-    for(ProjectDto project : projects){
+    for (ProjectDto project : projects) {
       dbClient.applicationProjectsDao().addProject(dbSession, application.getUuid(), project.getUuid());
     }
     db.commit();
   }
 
   public void addProjectBranchToApplicationBranch(BranchDto applicationBranch, BranchDto... projectBranches) {
-    for(BranchDto projectBranch : projectBranches){
+    for (BranchDto projectBranch : projectBranches) {
       dbClient.applicationProjectsDao().addProjectBranchToAppBranch(dbSession, applicationBranch, projectBranch);
     }
     db.commit();
@@ -378,6 +377,9 @@ public class ComponentDbTester {
   private ComponentDto insertComponentImpl(ComponentDto component, @Nullable Boolean isPrivate, Consumer<ComponentDto> dtoPopulator) {
     dtoPopulator.accept(component);
     checkState(isPrivate == null || component.isPrivate() == isPrivate, "Illegal modification of private flag");
+    if (component.getOrganizationUuid() == null) {
+      component.setOrganizationUuid(db.getDefaultOrganization().getUuid());
+    }
     dbClient.componentDao().insert(dbSession, component);
     db.commit();
 
@@ -389,6 +391,13 @@ public class ComponentDbTester {
   }
 
   public void insertComponents(ComponentDto... components) {
+    String defaultOrgUuid = db.getDefaultOrganization().getUuid();
+    Arrays.stream(components).forEach(c -> {
+      if (c.getOrganizationUuid() == null) {
+        c.setOrganizationUuid(defaultOrgUuid);
+      }
+    });
+
     dbClient.componentDao().insert(dbSession, asList(components));
     db.commit();
   }
index eaf1028f7f160328f44c938c0016ce9c6ed7cfdc..070891812f07463d6b22760862c876828ba3573e 100644 (file)
@@ -121,26 +121,46 @@ public class ComponentTesting {
     return newModuleDto(Uuids.createFast(), subProjectOrProject);
   }
 
+  public static ComponentDto newPrivateProjectDto() {
+    return newProjectDto(Uuids.createFast(), true);
+  }
+
+  // TODO remove
+  @Deprecated
   public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto) {
     return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
   }
 
+  // TODO remove
+  @Deprecated
   public static ProjectDto createPrivateProjectDto(OrganizationDto organizationDto) {
     return createProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
   }
 
+  public static ComponentDto newPrivateProjectDto(String uuid) {
+    return newProjectDto(uuid, true);
+  }
+
+  // TODO remove
+  @Deprecated
   public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto, String uuid) {
     return newProjectDto(organizationDto.getUuid(), uuid, true);
   }
 
+  // TODO remove
+  @Deprecated
   public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto) {
     return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), false);
   }
 
+  // TODO remove
+  @Deprecated
   public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto, String uuid) {
     return newProjectDto(organizationDto.getUuid(), uuid, false);
   }
 
+  // TODO remove
+  @Deprecated
   private static ProjectDto createProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
     return new ProjectDto()
       .setOrganizationUuid(organizationUuid)
@@ -152,6 +172,25 @@ public class ComponentTesting {
       .setPrivate(isPrivate);
   }
 
+  private static ComponentDto newProjectDto(String uuid, boolean isPrivate) {
+    return new ComponentDto()
+      .setUuid(uuid)
+      .setUuidPath(UUID_PATH_OF_ROOT)
+      .setProjectUuid(uuid)
+      .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
+      .setRootUuid(uuid)
+      .setDbKey("KEY_" + uuid)
+      .setName("NAME_" + uuid)
+      .setLongName("LONG_NAME_" + uuid)
+      .setDescription("DESCRIPTION_" + uuid)
+      .setScope(Scopes.PROJECT)
+      .setQualifier(Qualifiers.PROJECT)
+      .setPath(null)
+      .setLanguage(null)
+      .setEnabled(true)
+      .setPrivate(isPrivate);
+  }
+
   private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
     return new ComponentDto()
       .setOrganizationUuid(organizationUuid)
@@ -199,7 +238,6 @@ public class ComponentTesting {
     return newApplication(organizationDto.getUuid(), uuid);
   }
 
-
   public static ComponentDto newApplication(String organizationUuid) {
     return newApplication(organizationUuid, Uuids.createFast());
   }
@@ -293,7 +331,6 @@ public class ComponentTesting {
       .setPrivate(project.isPrivate());
   }
 
-
   public static ComponentDto newBranchComponent(ComponentDto project, BranchDto branchDto) {
     checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP));
     checkArgument(project.getMainBranchProjectUuid() == null);
index e289deb88452aaa138b513174f0ac9096649b2e4..4b00b628673aacc0e4ef2d78790ab857f4bae18e 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.favorite.ws;
 
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -29,31 +27,25 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.Paging;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.util.stream.MoreCollectors;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.server.favorite.FavoriteFinder;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Favorites.Favorite;
 import org.sonarqube.ws.Favorites.SearchResponse;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Optional.ofNullable;
-import static org.sonar.server.ws.WsUtils.writeProtobuf;
 import static org.sonar.server.favorite.ws.FavoritesWsParameters.ACTION_SEARCH;
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class SearchAction implements FavoritesWsAction {
   private static final int MAX_PAGE_SIZE = 500;
 
   private final FavoriteFinder favoriteFinder;
-  private final DbClient dbClient;
   private final UserSession userSession;
 
-  public SearchAction(FavoriteFinder favoriteFinder, DbClient dbClient, UserSession userSession) {
+  public SearchAction(FavoriteFinder favoriteFinder, UserSession userSession) {
     this.favoriteFinder = favoriteFinder;
-    this.dbClient = dbClient;
     this.userSession = userSession;
   }
 
@@ -85,16 +77,14 @@ public class SearchAction implements FavoritesWsAction {
 
   private SearchResults toSearchResults(SearchRequest request) {
     userSession.checkLoggedIn();
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      List<ComponentDto> authorizedFavorites = getAuthorizedFavorites();
-      Paging paging = Paging.forPageIndex(Integer.parseInt(request.getP())).withPageSize(Integer.parseInt(request.getPs())).andTotal(authorizedFavorites.size());
-      List<ComponentDto> displayedFavorites = authorizedFavorites.stream()
-        .skip(paging.offset())
-        .limit(paging.pageSize())
-        .collect(MoreCollectors.toList());
-      Map<String, OrganizationDto> organizationsByUuid = getOrganizationsOfComponents(dbSession, displayedFavorites);
-      return new SearchResults(paging, displayedFavorites, organizationsByUuid);
-    }
+
+    List<ComponentDto> authorizedFavorites = getAuthorizedFavorites();
+    Paging paging = Paging.forPageIndex(Integer.parseInt(request.getP())).withPageSize(Integer.parseInt(request.getPs())).andTotal(authorizedFavorites.size());
+    List<ComponentDto> displayedFavorites = authorizedFavorites.stream()
+      .skip(paging.offset())
+      .limit(paging.pageSize())
+      .collect(MoreCollectors.toList());
+    return new SearchResults(paging, displayedFavorites);
   }
 
   private List<ComponentDto> getAuthorizedFavorites() {
@@ -102,24 +92,13 @@ public class SearchAction implements FavoritesWsAction {
     return userSession.keepAuthorizedComponents(UserRole.USER, componentDtos);
   }
 
-  private Map<String, OrganizationDto> getOrganizationsOfComponents(DbSession dbSession, List<ComponentDto> displayedFavorites) {
-    Set<String> organizationUuids = displayedFavorites.stream()
-      .map(ComponentDto::getOrganizationUuid)
-      .collect(MoreCollectors.toSet());
-    return dbClient.organizationDao().selectByUuids(dbSession, organizationUuids)
-      .stream()
-      .collect(MoreCollectors.uniqueIndex(OrganizationDto::getUuid));
-  }
-
   private static class SearchResults {
     private final List<ComponentDto> favorites;
     private final Paging paging;
-    private final Map<String, OrganizationDto> organizationsByUuid;
 
-    private SearchResults(Paging paging, List<ComponentDto> favorites, Map<String, OrganizationDto> organizationsByUuid) {
+    private SearchResults(Paging paging, List<ComponentDto> favorites) {
       this.paging = paging;
       this.favorites = favorites;
-      this.organizationsByUuid = organizationsByUuid;
     }
   }
 
@@ -141,18 +120,13 @@ public class SearchAction implements FavoritesWsAction {
   private static void addFavorites(SearchResponse.Builder builder, SearchResults results) {
     Favorite.Builder favoriteBuilder = Favorite.newBuilder();
     results.favorites.stream()
-      .map(componentDto -> toWsFavorite(favoriteBuilder, results, componentDto))
+      .map(componentDto -> toWsFavorite(favoriteBuilder, componentDto))
       .forEach(builder::addFavorites);
   }
 
-  private static Favorite toWsFavorite(Favorite.Builder builder, SearchResults results, ComponentDto componentDto) {
-    OrganizationDto organization = results.organizationsByUuid.get(componentDto.getOrganizationUuid());
-    checkArgument(organization != null,
-      "Organization with uuid '%s' not found for favorite with uuid '%s'",
-      componentDto.getOrganizationUuid(), componentDto.uuid());
+  private static Favorite toWsFavorite(Favorite.Builder builder, ComponentDto componentDto) {
     builder
       .clear()
-      .setOrganization(organization.getKey())
       .setKey(componentDto.getDbKey());
     ofNullable(componentDto.name()).ifPresent(builder::setName);
     ofNullable(componentDto.qualifier()).ifPresent(builder::setQualifier);
index 414b8d7d4a94d4e0c8fdd78d99952c08ce22711a..74d0909f62520427ee10992fd6aaf073f617fd5b 100644 (file)
@@ -6,19 +6,16 @@
   },
   "favorites": [
     {
-      "organization": "my-org",
       "key": "K2",
       "name": "Apache HBase",
       "qualifier": "TRK"
     },
     {
-      "organization": "openjdk",
       "key": "K3",
       "name": "JDK9",
       "qualifier": "TRK"
     },
     {
-      "organization": "my-org",
       "key": "K1",
       "name": "Samba",
       "qualifier": "TRK"
index 172464290ce7e1503f81bdb8d5624a38f288f4e5..593bda90a65c6ccbe77e19343458817b96d27b2f 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.property.PropertyDto;
 import org.sonar.db.property.PropertyQuery;
 import org.sonar.db.user.UserDto;
@@ -63,11 +62,10 @@ public class AddActionTest {
   @Rule
   public DbTester db = DbTester.create();
 
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-
-  private FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient);
-  private WsActionTester ws = new WsActionTester(new AddAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db)));
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient);
+  private final WsActionTester ws = new WsActionTester(new AddAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db)));
 
   @Test
   public void add_a_project() {
@@ -119,8 +117,7 @@ public class AddActionTest {
 
   @Test
   public void fail_when_using_branch_db_key() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     ComponentDto branch = db.components().insertProjectBranch(project);
     UserDto user = db.users().insertUser();
     userSession.logIn(user).addProjectPermission(USER, project);
@@ -176,7 +173,9 @@ public class AddActionTest {
 
     assertThat(definition.key()).isEqualTo("add");
     assertThat(definition.isPost()).isTrue();
-    assertThat(definition.param("component").isRequired()).isTrue();
+    WebService.Param param = definition.param("component");
+    assertThat(param).isNotNull();
+    assertThat(param.isRequired()).isTrue();
   }
 
   private TestResponse call(@Nullable String componentKey) {
index f6228f5e4634d25fc428b4704490fc21a72450a8..29182789ce8df77e22127cc8c20cec5d16962de8 100644 (file)
@@ -23,13 +23,11 @@ import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.NotFoundException;
@@ -44,6 +42,7 @@ import static java.lang.String.format;
 import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.server.favorite.ws.FavoritesWsParameters.PARAM_COMPONENT;
@@ -53,17 +52,14 @@ public class RemoveActionTest {
   private static final String PROJECT_UUID = "project-uuid";
   private UserDto user;
 
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
   public DbTester db = DbTester.create();
 
-  private DbClient dbClient = db.getDbClient();
-
-  private FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient);
-  private WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db)));
+  private final DbClient dbClient = db.getDbClient();
+  private final FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient);
+  private final WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db)));
 
   @Before
   public void before() {
@@ -88,41 +84,37 @@ public class RemoveActionTest {
   public void fail_if_not_already_a_favorite() {
     insertProjectAndPermissions();
 
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Component '" + PROJECT_KEY + "' is not a favorite");
-
-    call(PROJECT_KEY);
+    assertThatThrownBy(() -> call(PROJECT_KEY))
+      .isInstanceOf(IllegalArgumentException.class)
+      .hasMessage("Component '" + PROJECT_KEY + "' is not a favorite");
   }
 
   @Test
   public void fail_when_component_is_not_found() {
     userSession.logIn();
 
-    expectedException.expect(NotFoundException.class);
-
-    call("P42");
+    assertThatThrownBy(() -> call("P42"))
+      .isInstanceOf(NotFoundException.class);
   }
 
   @Test
   public void fail_when_user_is_not_authenticated() {
     insertProject();
 
-    expectedException.expect(UnauthorizedException.class);
-
-    call(PROJECT_KEY);
+    assertThatThrownBy(() -> call(PROJECT_KEY))
+      .isInstanceOf(UnauthorizedException.class);
   }
 
   @Test
   public void fail_when_using_branch_db_key() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto project = db.components().insertPrivateProject();
     userSession.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto branch = db.components().insertProjectBranch(project);
+    String branchKey = branch.getDbKey();
 
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey()));
-
-    call(branch.getDbKey());
+    assertThatThrownBy(() -> call(branchKey))
+      .isInstanceOf(NotFoundException.class)
+      .hasMessage(format("Component key '%s' not found", branchKey));
   }
 
   @Test
@@ -131,11 +123,13 @@ public class RemoveActionTest {
 
     assertThat(definition.key()).isEqualTo("remove");
     assertThat(definition.isPost()).isTrue();
-    assertThat(definition.param("component").isRequired()).isTrue();
+    WebService.Param param = definition.param("component");
+    assertThat(param).isNotNull();
+    assertThat(param.isRequired()).isTrue();
   }
 
   private ComponentDto insertProject() {
-    return db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID).setDbKey(PROJECT_KEY));
+    return db.components().insertComponent(newPrivateProjectDto(PROJECT_UUID).setDbKey(PROJECT_KEY));
   }
 
   private ComponentDto insertProjectAndPermissions() {
index d902436a5fd10415b2244d19114afa51056f660a..98cfb8e9114760f218a434d46664e42dfea0b9fd 100644 (file)
@@ -24,7 +24,6 @@ import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.web.UserRole;
@@ -32,7 +31,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.favorite.FavoriteFinder;
@@ -45,6 +43,7 @@ import org.sonarqube.ws.Favorites.SearchResponse;
 
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.resources.Qualifiers.FILE;
 import static org.sonar.api.resources.Qualifiers.PROJECT;
@@ -55,17 +54,16 @@ import static org.sonarqube.ws.client.WsRequest.Method.POST;
 
 public class SearchActionTest {
   private String userUuid;
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
+
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
   public DbTester db = DbTester.create();
-  private DbClient dbClient = db.getDbClient();
+  private final DbClient dbClient = db.getDbClient();
 
-  private FavoriteFinder favoriteFinder = new FavoriteFinder(dbClient, userSession);
+  private final FavoriteFinder favoriteFinder = new FavoriteFinder(dbClient, userSession);
 
-  private WsActionTester ws = new WsActionTester(new SearchAction(favoriteFinder, dbClient, userSession));
+  private final WsActionTester ws = new WsActionTester(new SearchAction(favoriteFinder, userSession));
 
   @Before
   public void before() {
@@ -76,10 +74,10 @@ public class SearchActionTest {
 
   @Test
   public void return_favorites() {
-    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "P1").setDbKey("K1").setName("N1");
+    ComponentDto project = newPrivateProjectDto("P1").setDbKey("K1").setName("N1");
     addComponent(project);
     addComponent(newFileDto(project).setDbKey("K11").setName("N11"));
-    addComponent(newPrivateProjectDto(db.getDefaultOrganization(), "P2").setDbKey("K2").setName("N2"));
+    addComponent(newPrivateProjectDto("P2").setDbKey("K2").setName("N2"));
 
     SearchResponse result = call();
 
@@ -104,9 +102,8 @@ public class SearchActionTest {
 
   @Test
   public void filter_authorized_components() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("K1"));
-    ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
+    addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1"));
+    ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto());
     db.favorites().add(unauthorizedProject, userUuid);
 
     SearchResponse result = call();
@@ -118,8 +115,8 @@ public class SearchActionTest {
   @Test
   public void paginate_results() {
     IntStream.rangeClosed(1, 9)
-      .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("K" + i).setName("N" + i)));
-    ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
+      .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K" + i).setName("N" + i)));
+    ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto());
     db.favorites().add(unauthorizedProject, userUuid);
 
     SearchResponse result = call(2, 3);
@@ -133,9 +130,8 @@ public class SearchActionTest {
 
   @Test
   public void return_only_users_favorite() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("K1"));
-    ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("K42");
+    addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1"));
+    ComponentDto otherUserFavorite = ComponentTesting.newPrivateProjectDto().setDbKey("K42");
     db.components().insertComponent(otherUserFavorite);
     db.favorites().add(otherUserFavorite, "42");
     db.commit();
@@ -147,10 +143,9 @@ public class SearchActionTest {
 
   @Test
   public void favorites_ordered_by_name() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("N2"));
-    addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("N3"));
-    addComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("N1"));
+    addComponent(ComponentTesting.newPrivateProjectDto().setName("N2"));
+    addComponent(ComponentTesting.newPrivateProjectDto().setName("N3"));
+    addComponent(ComponentTesting.newPrivateProjectDto().setName("N1"));
 
     SearchResponse result = call();
 
@@ -160,14 +155,13 @@ public class SearchActionTest {
 
   @Test
   public void json_example() {
-    OrganizationDto organization1 = db.organizations().insertForKey("my-org");
-    OrganizationDto organization2 = db.organizations().insertForKey("openjdk");
-    addComponent(ComponentTesting.newPrivateProjectDto(organization1).setDbKey("K1").setName("Samba"));
-    addComponent(ComponentTesting.newPrivateProjectDto(organization1).setDbKey("K2").setName("Apache HBase"));
-    addComponent(ComponentTesting.newPrivateProjectDto(organization2).setDbKey("K3").setName("JDK9"));
+    addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K1").setName("Samba"));
+    addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K2").setName("Apache HBase"));
+    addComponent(ComponentTesting.newPrivateProjectDto().setDbKey("K3").setName("JDK9"));
 
     String result = ws.newRequest().execute().getInput();
 
+    assertThat(ws.getDef().responseExampleAsString()).isNotNull();
     assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
   }
 
@@ -183,9 +177,8 @@ public class SearchActionTest {
   public void fail_if_not_authenticated() {
     userSession.anonymous();
 
-    expectedException.expect(UnauthorizedException.class);
-
-    call();
+    assertThatThrownBy(this::call)
+      .isInstanceOf(UnauthorizedException.class);
   }
 
   private void addComponent(ComponentDto component) {
index 7cdb6eceb94940cc82dd8b8f69f26555afa2ef46..64a75848238a0702f2077c9134563415f6331da6 100644 (file)
@@ -33,7 +33,6 @@ message SearchResponse {
 }
 
 message Favorite {
-  optional string organization = 4;
   optional string key = 1;
   optional string name = 2;
   optional string qualifier = 3;