aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-04-28 09:21:40 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-04-28 18:36:09 +0200
commit70ff3c22c1f2da24601ec099fa48a55ca5a9f035 (patch)
tree0e4651797dcf140fa475a4c017c8177a491d6021
parent65a250757f5c7d60c03a8d94a78ba716729cf379 (diff)
downloadsonarqube-70ff3c22c1f2da24601ec099fa48a55ca5a9f035.tar.gz
sonarqube-70ff3c22c1f2da24601ec099fa48a55ca5a9f035.zip
SONAR-9130 Extract checkCanUpdateProjectsVisibility to ProjectsWsSupport
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java3
6 files changed, 31 insertions, 21 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
index 829c70bae58..3a044b3d43e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
@@ -24,6 +24,8 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.server.organization.BillingValidations;
+import org.sonar.server.organization.BillingValidationsProxy;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
@@ -33,8 +35,11 @@ public class ProjectsWsSupport {
private final DbClient dbClient;
- public ProjectsWsSupport(DbClient dbClient) {
+ private final BillingValidationsProxy billingValidations;
+
+ public ProjectsWsSupport(DbClient dbClient, BillingValidationsProxy billingValidations) {
this.dbClient = dbClient;
+ this.billingValidations = billingValidations;
}
void addOrganizationParam(WebService.NewAction action) {
@@ -50,4 +55,12 @@ public class ProjectsWsSupport {
dbClient.organizationDao().selectByKey(dbSession, organizationKey),
"No organization for key '%s'", organizationKey);
}
+
+ void checkCanUpdateProjectsVisibility(OrganizationDto organization, boolean newProjectsPrivate) {
+ try {
+ billingValidations.checkCanUpdateProjectVisibility(new BillingValidations.Organization(organization.getKey(), organization.getUuid()), newProjectsPrivate);
+ } catch (BillingValidations.BillingValidationsException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
index c1f0fd0a259..6e117741622 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
@@ -34,8 +34,6 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.GroupPermissionDto;
import org.sonar.db.permission.UserPermissionDto;
import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.organization.BillingValidations;
-import org.sonar.server.organization.BillingValidationsProxy;
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.project.Visibility;
import org.sonar.server.user.UserSession;
@@ -56,15 +54,15 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
private final ComponentFinder componentFinder;
private final UserSession userSession;
private final PermissionIndexer permissionIndexer;
- private final BillingValidationsProxy billingValidations;
+ private final ProjectsWsSupport projectsWsSupport;
public UpdateVisibilityAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession,
- PermissionIndexer permissionIndexer, BillingValidationsProxy billingValidations) {
+ PermissionIndexer permissionIndexer, ProjectsWsSupport projectsWsSupport) {
this.dbClient = dbClient;
this.componentFinder = componentFinder;
this.userSession = userSession;
this.permissionIndexer = permissionIndexer;
- this.billingValidations = billingValidations;
+ this.projectsWsSupport = projectsWsSupport;
}
public void define(WebService.NewController context) {
@@ -103,7 +101,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
if (changeToPrivate != component.isPrivate()) {
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, component.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(format("Could not find organization with uuid '%s' of project '%s'", component.getOrganizationUuid(), projectKey)));
- checkCanUpdateProjectsVisibility(organization, changeToPrivate);
+ projectsWsSupport.checkCanUpdateProjectsVisibility(organization, changeToPrivate);
dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, component.uuid(), changeToPrivate);
if (changeToPrivate) {
updatePermissionsToPrivate(dbSession, component);
@@ -157,12 +155,4 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
});
}
- private void checkCanUpdateProjectsVisibility(OrganizationDto organization, boolean newProjectsPrivate) {
- try {
- billingValidations.checkCanUpdateProjectsVisibility(new BillingValidations.Organization(organization.getKey(), organization.getUuid()), newProjectsPrivate);
- } catch (BillingValidations.BillingValidationsException e) {
- throw new IllegalArgumentException(e.getMessage());
- }
- }
-
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
index 36cb89ea124..acada2ea8f3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
@@ -33,6 +33,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
+import org.sonar.server.organization.BillingValidationsProxy;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -60,7 +61,7 @@ public class BulkDeleteActionTest {
private ComponentCleanerService componentCleanerService = mock(ComponentCleanerService.class);
private WsTester ws;
private DbClient dbClient = db.getDbClient();
- private BulkDeleteAction underTest = new BulkDeleteAction(componentCleanerService, dbClient, userSession, new ProjectsWsSupport(dbClient));
+ private BulkDeleteAction underTest = new BulkDeleteAction(componentCleanerService, dbClient, userSession, new ProjectsWsSupport(dbClient, mock(BillingValidationsProxy.class)));
private OrganizationDto org1;
private OrganizationDto org2;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
index 32b4feee118..1326c44a467 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
@@ -37,6 +37,7 @@ import org.sonar.db.component.SnapshotTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.organization.BillingValidationsProxy;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
@@ -45,6 +46,7 @@ import org.sonar.server.ws.WsActionTester;
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.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.OrganizationPermission.SCAN;
import static org.sonar.test.JsonAssert.assertJson;
@@ -62,7 +64,8 @@ public class ProvisionedActionTest {
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private DbClient dbClient = db.getDbClient();
- private WsActionTester underTest = new WsActionTester(new ProvisionedAction(new ProjectsWsSupport(dbClient), dbClient, userSessionRule, defaultOrganizationProvider));
+ private WsActionTester underTest = new WsActionTester(new ProvisionedAction(new ProjectsWsSupport(dbClient, mock(BillingValidationsProxy.class)),
+ dbClient, userSessionRule, defaultOrganizationProvider));
@Test
public void verify_definition() {
@@ -73,8 +76,7 @@ public class ProvisionedActionTest {
assertThat(action.since()).isEqualTo("5.2");
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
tuple("6.4", "The 'uuid' field is deprecated in the response"),
- tuple("6.4", "Paging response fields is now in a Paging object")
- );
+ tuple("6.4", "Paging response fields is now in a Paging object"));
assertThat(action.params()).hasSize(5);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
index 7b159ea5114..f46707cb609 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
@@ -35,6 +35,7 @@ import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.organization.BillingValidationsProxy;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
@@ -49,6 +50,7 @@ import org.sonarqube.ws.client.project.SearchWsRequest;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
@@ -80,7 +82,8 @@ public class SearchActionTest {
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private WsActionTester ws = new WsActionTester(new SearchAction(db.getDbClient(), userSession, defaultOrganizationProvider, new ProjectsWsSupport(db.getDbClient())));
+ private WsActionTester ws = new WsActionTester(
+ new SearchAction(db.getDbClient(), userSession, defaultOrganizationProvider, new ProjectsWsSupport(db.getDbClient(), mock(BillingValidationsProxy.class))));
@Test
public void search_by_key_query() throws IOException {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
index 5deb6b149e5..9c4c23d3d47 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
@@ -91,7 +91,8 @@ public class UpdateVisibilityActionTest {
private PermissionIndexer permissionIndexer = mock(PermissionIndexer.class);
private BillingValidationsProxy billingValidations = mock(BillingValidationsProxy.class);
- private UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, new ComponentFinder(dbClient), userSessionRule, permissionIndexer, billingValidations);
+ private UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, new ComponentFinder(dbClient), userSessionRule, permissionIndexer,
+ new ProjectsWsSupport(dbClient, billingValidations));
private WsActionTester actionTester = new WsActionTester(underTest);
private final Random random = new Random();