]> source.dussan.org Git - sonarqube.git/commitdiff
Remove error-prone params Organization in UserDbTester
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sat, 28 Jan 2017 14:09:38 +0000 (15:09 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 29 Jan 2017 09:25:20 +0000 (10:25 +0100)
17 files changed:
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/UserDbTester.java

index 811f4047b4f78ea2014e7438073cf44eb52fef1d..4f0db1df33ab7796847eb76e917020dede11b0d8 100644 (file)
@@ -229,8 +229,8 @@ public class DeleteActionTest {
     dbTester.users().insertPermissionOnUser(otherOrganizationDto, user1, "not deleted u2");
     dbTester.users().insertPermissionOnGroup(group1, "u3");
     dbTester.users().insertPermissionOnGroup(otherGroup1, "not deleted u3");
-    dbTester.users().insertProjectPermissionOnAnyone(organizationDto, "u4", projectDto);
-    dbTester.users().insertProjectPermissionOnAnyone(otherOrganizationDto, "not deleted u4", otherProjectDto);
+    dbTester.users().insertProjectPermissionOnAnyone("u4", projectDto);
+    dbTester.users().insertProjectPermissionOnAnyone("not deleted u4", otherProjectDto);
     dbTester.users().insertProjectPermissionOnGroup(group1, "u5", projectDto);
     dbTester.users().insertProjectPermissionOnGroup(otherGroup1, "not deleted u5", otherProjectDto);
     dbTester.users().insertProjectPermissionOnUser(user1, "u6", projectDto);
index 605243003662cd951d1b43c13799b33e21c7b7bb..eea75e83ae15f355d4e995ef300339841926f65c 100644 (file)
@@ -138,7 +138,7 @@ public class UserPermissionChangerTest {
   @Test
   public void remove_project_permission_from_user() {
     ComponentDto project2 = db.components().insertProject(org1);
-    db.users().insertPermissionOnUser(org1, user1, QUALITY_GATE_ADMIN);
+    db.users().insertPermissionOnUser(user1, QUALITY_GATE_ADMIN);
     db.users().insertProjectPermissionOnUser(user1, ISSUE_ADMIN, project);
     db.users().insertProjectPermissionOnUser(user1, USER, project);
     db.users().insertProjectPermissionOnUser(user2, ISSUE_ADMIN, project);
index ee82c2ab15508e3b625310c48f637ea36d8a4f00..6af72e6da70507bc56338efb1f8757f76dfc7b6c 100644 (file)
@@ -214,11 +214,11 @@ public class PermissionIndexerDaoTest {
     userDbTester.insertProjectPermissionOnGroup(group, ADMIN, view1);
 
     // Anyone group has user access on both projects
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, project1);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), ADMIN, project1);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, project2);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, view1);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), ADMIN, view1);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, view2);
+    userDbTester.insertProjectPermissionOnAnyone(USER, project1);
+    userDbTester.insertProjectPermissionOnAnyone(ADMIN, project1);
+    userDbTester.insertProjectPermissionOnAnyone(USER, project2);
+    userDbTester.insertProjectPermissionOnAnyone(USER, view1);
+    userDbTester.insertProjectPermissionOnAnyone(ADMIN, view1);
+    userDbTester.insertProjectPermissionOnAnyone(USER, view2);
   }
 }
index c53c220a949625be7780fe4df0f274041d8c0e70..4efccb44cdd6217754dfd956e1eb2c4a6bf506c7 100644 (file)
@@ -87,9 +87,9 @@ public class PermissionIndexerTest {
     userDbTester.insertProjectPermissionOnUser(user, ADMIN, view);
     GroupDto group = userDbTester.insertGroup();
     userDbTester.insertProjectPermissionOnGroup(group, USER, project);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, project);
+    userDbTester.insertProjectPermissionOnAnyone(USER, project);
     userDbTester.insertProjectPermissionOnGroup(group, USER, view);
-    userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, view);
+    userDbTester.insertProjectPermissionOnAnyone(USER, view);
 
     underTest.indexAllIfEmpty();
 
index 9d24e5c9e946432d7c06fa7ee394e5a41214c458..4f22e7c5f2a20c73b61591dd76327452db0921dd 100644 (file)
@@ -38,7 +38,6 @@ import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
-import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
@@ -108,7 +107,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
 
   @Test
   public void remove_with_view_uuid() throws Exception {
-    ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setKey("view-key"));
+    ComponentDto view = db.components().insertView();
     db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
     db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, view);
     db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, view);
@@ -299,17 +298,17 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
 
   private void executeRequest(GroupDto groupDto, String permission) throws Exception {
     newRequest()
-        .setParam(PARAM_GROUP_NAME, groupDto.getName())
-        .setParam(PARAM_PERMISSION, permission)
-        .execute();
+      .setParam(PARAM_GROUP_NAME, groupDto.getName())
+      .setParam(PARAM_PERMISSION, permission)
+      .execute();
   }
 
   private void executeRequest(GroupDto groupDto, OrganizationDto organizationDto, String permission) throws Exception {
     newRequest()
-        .setParam(PARAM_GROUP_NAME, groupDto.getName())
-        .setParam(PARAM_PERMISSION, permission)
-        .setParam(PARAM_ORGANIZATION_KEY, organizationDto.getKey())
-        .execute();
+      .setParam(PARAM_GROUP_NAME, groupDto.getName())
+      .setParam(PARAM_PERMISSION, permission)
+      .setParam(PARAM_ORGANIZATION_KEY, organizationDto.getKey())
+      .execute();
   }
 
   @Test
index 7f4818938e678f2db9e3f94fb347ea3647a21336..6bc84b237a557c5f6a491fe0222b4e223b9462ff 100644 (file)
@@ -91,11 +91,11 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
     // global permission
     db.users().insertPermissionOnUser(user1, GlobalPermissions.SYSTEM_ADMIN);
 
-    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization());
-    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization());
-    GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization());
+    GroupDto group1 = db.users().insertGroup();
+    GroupDto group2 = db.users().insertGroup();
+    GroupDto group3 = db.users().insertGroup();
 
-    db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), UserRole.ADMIN, jdk7);
+    db.users().insertProjectPermissionOnAnyone(UserRole.ADMIN, jdk7);
     db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, jdk7);
     db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, jdk7);
     db.users().insertProjectPermissionOnGroup(group3, UserRole.ADMIN, jdk7);
@@ -266,7 +266,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
   }
 
   private ComponentDto insertJdk7() {
-    return db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid-1")
+    return db.components().insertComponent(newProjectDto(db.getDefaultOrganization())
       .setName("JDK 7")
       .setKey("net.java.openjdk:jdk7")
       .setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
index 4f8b01afc2c20289eca7f5675cbecb4826b6e4f2..3daadeeb18af94648dacb0d9e462939e00cc7656 100644 (file)
@@ -105,12 +105,12 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> {
   @Test
   public void search_only_for_users_with_permission_when_no_search_query() throws Exception {
     // User have permission on project
-    ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
-    UserDto user = db.users().insertUser(newUserDto());
+    ComponentDto project = db.components().insertProject();
+    UserDto user = db.users().insertUser();
     db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
 
     // User has no permission
-    UserDto withoutPermission = db.users().insertUser(newUserDto());
+    UserDto withoutPermission = db.users().insertUser();
 
     loginAsAdminOnDefaultOrganization();
     String result = newRequest()
index 87fc2067f070014ac1ce862690af0ce07fd1d349..39d5fadbe25a7f66ed3fae3d36d7001a5750cab3 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.api.config.MapSettings;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.permission.PermissionQuery;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
@@ -51,7 +50,6 @@ import org.sonar.server.ws.TestResponse;
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
@@ -86,11 +84,10 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
 
   @Before
   public void setUp() {
-    user1 = db.users().insertUser("user-login-1");
-    user2 = db.users().insertUser("user-login-2");
-    OrganizationDto defaultOrg = db.getDefaultOrganization();
-    group1 = db.users().insertGroup(defaultOrg, "group-name-1");
-    group2 = db.users().insertGroup(defaultOrg, "group-name-2");
+    user1 = db.users().insertUser();
+    user2 = db.users().insertUser();
+    group1 = db.users().insertGroup();
+    group2 = db.users().insertGroup();
 
     // template 1
     template1 = insertTemplate();
@@ -105,7 +102,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
     addGroupToTemplate(group1, template2, UserRole.USER);
     addGroupToTemplate(group2, template2, UserRole.USER);
 
-    project = db.components().insertComponent(newProjectDto(defaultOrg, "project-uuid-1"));
+    project = db.components().insertProject();
     db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project);
     db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, project);
     db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, project);
index 548116a418c5bbf0bbe3f085ccb151c6d25028a7..af187494a7efbe72bc03c8b607c05784e1100aca 100644 (file)
@@ -67,11 +67,10 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
 
   @Before
   public void setUp() {
-    user1 = db.users().insertUser("user-login-1");
-    user2 = db.users().insertUser("user-login-2");
-    OrganizationDto defaultOrg = db.getDefaultOrganization();
-    group1 = db.users().insertGroup(defaultOrg, "group-name-1");
-    group2 = db.users().insertGroup(defaultOrg, "group-name-2");
+    user1 = db.users().insertUser();
+    user2 = db.users().insertUser();
+    group1 = db.users().insertGroup();
+    group2 = db.users().insertGroup();
 
     // template 1
     template1 = insertTemplate();
@@ -89,13 +88,13 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
 
   @Test
   public void bulk_apply_template_by_template_uuid() throws Exception {
-    OrganizationDto organization = db.getDefaultOrganization();
-    ComponentDto project = db.components().insertComponent(newProjectDto(organization));
-    ComponentDto view = db.components().insertComponent(newView(organization));
-    db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, view);
-    db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, view);
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, view);
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, view);
+    ComponentDto project = db.components().insertProject();
+    ComponentDto view = db.components().insertView();
+    ComponentDto developer = db.components().insertDeveloper("developer-name");
+    db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, developer);
+    db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, developer);
+    db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, developer);
+    db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, developer);
     loginAsAdminOnDefaultOrganization();
 
     newRequest().setParam(PARAM_TEMPLATE_ID, template1.getUuid()).execute();
index 1741d176ff93a782e640c6bf14e0b9e33171cc01..21081972202e02482cb91721a16fc9a9f0b28c6c 100644 (file)
@@ -63,7 +63,6 @@ import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class SearchMyProjectsActionTest {
-  private static final String USER_LOGIN = "TESTER";
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -80,8 +79,8 @@ public class SearchMyProjectsActionTest {
 
   @Before
   public void setUp() {
-    user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN));
-    userSession.login(this.user.getLogin()).setUserId(user.getId().intValue());
+    user = db.users().insertUser();
+    userSession.login(user);
     alertStatusMetric = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(ALERT_STATUS_KEY).setValueType(ValueType.LEVEL.name()));
     db.commit();
 
@@ -196,11 +195,11 @@ public class SearchMyProjectsActionTest {
 
   @Test
   public void admin_via_groups() {
-    OrganizationDto organization = db.organizations().insert();
-    ComponentDto jdk7 = insertJdk7(organization);
-    ComponentDto cLang = insertClang(organization);
+    OrganizationDto org = db.organizations().insert();
+    ComponentDto jdk7 = insertJdk7(org);
+    ComponentDto cLang = insertClang(org);
 
-    GroupDto group = db.users().insertGroup(organization);
+    GroupDto group = db.users().insertGroup(org);
     db.users().insertMember(group, user);
 
     db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, jdk7);
@@ -214,12 +213,12 @@ public class SearchMyProjectsActionTest {
 
   @Test
   public void admin_via_groups_and_users() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    ComponentDto jdk7 = insertJdk7(organizationDto);
-    ComponentDto cLang = insertClang(organizationDto);
-    ComponentDto sonarqube = db.components().insertProject(organizationDto);
+    OrganizationDto org = db.organizations().insert();
+    ComponentDto jdk7 = insertJdk7(org);
+    ComponentDto cLang = insertClang(org);
+    ComponentDto sonarqube = db.components().insertProject(org);
 
-    GroupDto group = db.users().insertGroup(organizationDto);
+    GroupDto group = db.users().insertGroup(org);
     db.users().insertMember(group, user);
 
     db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7);
index fce6b6422142f97aae4bbc53ab722dcb9041aab3..955061df4ddb971c12ddf18b7e4f55daeacf0bad 100644 (file)
@@ -88,9 +88,9 @@ public class QgateProjectFinderTest {
 
   @Test
   public void return_all_projects() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto associatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
-    ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
+    OrganizationDto org = dbTester.organizations().insert();
+    ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+    ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
     associateProjectToQualitGate(associatedProject.getId());
 
     Association result = underTest.find(
@@ -107,9 +107,9 @@ public class QgateProjectFinderTest {
 
   @Test
   public void return_only_associated_project() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto associatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
-    insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
+    OrganizationDto org = dbTester.organizations().insert();
+    ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+    insertProjectAuthorizedToAnyone(newProjectDto(org));
     associateProjectToQualitGate(associatedProject.getId());
 
     Association result = underTest.find(
@@ -125,9 +125,9 @@ public class QgateProjectFinderTest {
 
   @Test
   public void return_only_unassociated_project() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto associatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
-    ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
+    OrganizationDto org = dbTester.organizations().insert();
+    ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+    ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
     associateProjectToQualitGate(associatedProject.getId());
 
     Association result = underTest.find(
@@ -162,10 +162,10 @@ public class QgateProjectFinderTest {
 
   @Test
   public void test_paging() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto project1 = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto).setName("Project 1"));
-    ComponentDto project2 = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto).setName("Project 2"));
-    ComponentDto project3 = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto).setName("Project 3"));
+    OrganizationDto org = dbTester.organizations().insert();
+    ComponentDto project1 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 1"));
+    ComponentDto project2 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 2"));
+    ComponentDto project3 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 3"));
     associateProjectToQualitGate(project1.getId());
 
     // Return partial result on first page
@@ -237,9 +237,9 @@ public class QgateProjectFinderTest {
     dbTester.commit();
   }
 
-  private ComponentDto insertProjectAuthorizedToAnyone(OrganizationDto organizationDto, ComponentDto project) {
+  private ComponentDto insertProjectAuthorizedToAnyone(ComponentDto project) {
     dbTester.components().insertComponent(project);
-    dbTester.users().insertProjectPermissionOnAnyone(organizationDto, UserRole.USER, project);
+    dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
     return project;
   }
 
index 1478791ad5edf1425d83a1a227866419f25d24ed..7a602f022dd2e156b8ca2a32dd98eaa6390a91d8 100644 (file)
@@ -216,7 +216,7 @@ public class ProjectsActionTest {
 
   private void addBrowsePermissionToAnyone(ComponentDto... projects) {
     for (ComponentDto project : projects) {
-      db.users().insertProjectPermissionOnAnyone(organizationDto, UserRole.USER, project);
+      db.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
     }
   }
 
index 439fd23f9bb9d5bfd3234d4627c25a18c80ab966..df4243e055d0bf6f156e4c638b2a78fe7fa856b5 100644 (file)
@@ -338,7 +338,7 @@ public class ServerUserSessionTest {
   @Test
   public void hasOrganizationPermission_for_logged_in_user() {
     OrganizationDto org = db.organizations().insert();
-    ComponentDto project = db.components().insertProject();
+    ComponentDto project = db.components().insertProject(org);
     db.users().insertPermissionOnUser(org, userDto, GlobalPermissions.PROVISIONING);
     db.users().insertProjectPermissionOnUser(userDto, UserRole.ADMIN, project);
 
@@ -385,12 +385,12 @@ public class ServerUserSessionTest {
     }
   }
 
-  private void addAnyonePermissions(OrganizationDto organizationDto, @Nullable ComponentDto component, String... permissions) {
+  private void addAnyonePermissions(OrganizationDto org, @Nullable ComponentDto component, String... permissions) {
     for (String permission : permissions) {
       if (component == null) {
-        db.users().insertPermissionOnAnyone(organizationDto, permission);
+        db.users().insertPermissionOnAnyone(org, permission);
       } else {
-        db.users().insertProjectPermissionOnAnyone(organizationDto, permission, component);
+        db.users().insertProjectPermissionOnAnyone(permission, component);
       }
     }
   }
index f830c6e596677870e780135edf5bd8ea9ce2020c..0b166917f810c078fc3fbab7a4b1547f4e3a4038 100644 (file)
@@ -172,11 +172,11 @@ public class ViewIndexerTest {
     assertThat(issueIndex.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(viewUuid)).build(), new SearchOptions()).getDocs()).hasSize(2);
   }
 
-  private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto organizationDto) {
-    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+  private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto org) {
+    ComponentDto project = ComponentTesting.newProjectDto(org);
     ComponentDto file = ComponentTesting.newFileDto(project, null);
     dbTester.components().insertComponents(project, file);
-    dbTester.users().insertProjectPermissionOnAnyone(organizationDto, UserRole.USER, project);
+    dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
 
     IssueDto issue = IssueTesting.newDto(rule, file, project);
     dbClient.issueDao().insert(dbSession, issue);
index b44fcf8c1b753e1a9912cb85f049bad82f2a4c31..ec9a57cb12668cae1229069e22080080cc50cd5a 100644 (file)
@@ -119,7 +119,7 @@ public class AuthorizationDaoTest {
   public void selectRootComponentPermissions_for_logged_in_user() {
     db.users().insertMember(group1, user);
     ComponentDto project1 = db.components().insertProject(org);
-    db.users().insertProjectPermissionOnAnyone(org, "perm1", project1);
+    db.users().insertProjectPermissionOnAnyone("perm1", project1);
     db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
     db.users().insertProjectPermissionOnUser(user, "perm3", project1);
 
@@ -143,7 +143,7 @@ public class AuthorizationDaoTest {
   @Test
   public void selectRootComponentPermissions_for_anonymous_user() {
     ComponentDto project1 = db.components().insertProject(org);
-    db.users().insertProjectPermissionOnAnyone(org, "perm1", project1);
+    db.users().insertProjectPermissionOnAnyone("perm1", project1);
 
     // ignored permissions
     db.users().insertPermissionOnAnyone(org, "ignored");
index 3383821e73307995c87365c6f7039df366a3f8cd..0db3f4c6bc9b2b9e7dbcfe0e21322663d7a7a141 100644 (file)
@@ -78,7 +78,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group2, ADMIN, project2);
     db.users().insertProjectPermissionOnGroup(group3, ADMIN, project2);
     // anyone group
-    db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), ADMIN, project2);
+    db.users().insertProjectPermissionOnAnyone(ADMIN, project2);
     db.users().insertProjectPermissionOnGroup(group1, USER, project2);
     db.users().insertProjectPermissionOnGroup(group1, USER, project3);
 
@@ -161,10 +161,10 @@ public class GroupPermissionDaoTest {
 
     db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
     db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
-    db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), USER, project);
+    db.users().insertProjectPermissionOnAnyone(USER, project);
 
     db.users().insertProjectPermissionOnGroup(group1, SYSTEM_ADMIN, anotherProject);
-    db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), SYSTEM_ADMIN, anotherProject);
+    db.users().insertProjectPermissionOnAnyone(SYSTEM_ADMIN, anotherProject);
     db.users().insertProjectPermissionOnGroup(group3, SCAN_EXECUTION, anotherProject);
     db.users().insertPermissionOnGroup(group2, SCAN_EXECUTION);
 
@@ -202,8 +202,8 @@ public class GroupPermissionDaoTest {
 
     assertThat(underTest.selectGroupNamesByQuery(dbSession,
       defaultOrganizationUuid, PermissionQuery.builder().build()))
-        .doesNotContain(ANYONE)
-        .containsExactly(group.getName());
+      .doesNotContain(ANYONE)
+      .containsExactly(group.getName());
   }
 
   @Test
@@ -247,39 +247,39 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void selectByGroupIds_on_projects() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    GroupDto group1 = db.users().insertGroup(organizationDto, "Group-1");
+    OrganizationDto org = db.organizations().insert();
+    GroupDto group1 = db.users().insertGroup(org, "Group-1");
     db.users().insertPermissionOnGroup(group1, PROVISIONING);
 
-    GroupDto group2 = db.users().insertGroup(organizationDto, "Group-2");
-    ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto));
+    GroupDto group2 = db.users().insertGroup(org, "Group-2");
+    ComponentDto project = db.components().insertComponent(newProjectDto(org));
     db.users().insertProjectPermissionOnGroup(group2, USER, project);
 
-    GroupDto group3 = db.users().insertGroup(organizationDto, "Group-3");
+    GroupDto group3 = db.users().insertGroup(org, "Group-3");
     db.users().insertProjectPermissionOnGroup(group3, USER, project);
 
     // Anyone group
-    db.users().insertPermissionOnAnyone(organizationDto, SCAN_EXECUTION);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, PROVISIONING, project);
+    db.users().insertPermissionOnAnyone(org, SCAN_EXECUTION);
+    db.users().insertProjectPermissionOnAnyone(PROVISIONING, project);
 
     assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.getId())).isEmpty();
 
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(group2.getId()), project.getId()))
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.getId()))
       .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
       .containsOnly(tuple(group2.getId(), USER, project.getId()));
 
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(group3.getId()), project.getId()))
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.getId()))
       .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
       .containsOnly(tuple(group3.getId(), USER, project.getId()));
 
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(ANYONE_ID), project.getId()))
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId()))
       .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
       .containsOnly(tuple(0L, PROVISIONING, project.getId()));
 
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2);
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
-    assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2);
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
+    assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
   }
 
   @Test
@@ -295,7 +295,7 @@ public class GroupPermissionDaoTest {
     db.users().insertPermissionOnGroup(group1, "perm3");
     db.users().insertPermissionOnGroup(group2, "perm4");
     db.users().insertProjectPermissionOnGroup(group1, "perm5", project);
-    db.users().insertProjectPermissionOnAnyone(org1, "perm6", project);
+    db.users().insertProjectPermissionOnAnyone("perm6", project);
 
     assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId())).containsOnly("perm2", "perm3");
     assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), group2.getId())).containsOnly("perm4");
@@ -318,7 +318,7 @@ public class GroupPermissionDaoTest {
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnGroup(group1, "perm4", project1);
     db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
-    db.users().insertProjectPermissionOnAnyone(org1, "perm6", project1);
+    db.users().insertProjectPermissionOnAnyone("perm6", project1);
 
     assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.getId()))
       .containsOnly("perm3", "perm4");
@@ -351,10 +351,10 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void projectHasPermissions_is_true_if_at_least_one_permission_on_anyone() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    ComponentDto project1 = db.components().insertProject(organizationDto);
-    ComponentDto project2 = db.components().insertProject(organizationDto);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, "perm1", project1);
+    OrganizationDto org = db.organizations().insert();
+    ComponentDto project1 = db.components().insertProject(org);
+    ComponentDto project2 = db.components().insertProject(org);
+    db.users().insertProjectPermissionOnAnyone("perm1", project1);
 
     assertThat(underTest.hasRootComponentPermissions(dbSession, project1.getId())).isTrue();
     assertThat(underTest.hasRootComponentPermissions(dbSession, project2.getId())).isFalse();
@@ -362,14 +362,14 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void deleteByRootComponentId() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    GroupDto group1 = db.users().insertGroup(organizationDto);
-    GroupDto group2 = db.users().insertGroup(organizationDto);
-    ComponentDto project1 = db.components().insertProject(organizationDto);
-    ComponentDto project2 = db.components().insertProject(organizationDto);
+    OrganizationDto org = db.organizations().insert();
+    GroupDto group1 = db.users().insertGroup(org);
+    GroupDto group2 = db.users().insertGroup(org);
+    ComponentDto project1 = db.components().insertProject(org);
+    ComponentDto project2 = db.components().insertProject(org);
     db.users().insertPermissionOnGroup(group1, "perm1");
     db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, "perm3", project1);
+    db.users().insertProjectPermissionOnAnyone("perm3", project1);
     db.users().insertProjectPermissionOnGroup(group2, "perm4", project2);
 
     underTest.deleteByRootComponentId(dbSession, project1.getId());
@@ -381,13 +381,13 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void delete_global_permission_from_group() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    GroupDto group1 = db.users().insertGroup(organizationDto);
-    ComponentDto project1 = db.components().insertProject(organizationDto);
-    db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+    OrganizationDto org = db.organizations().insert();
+    GroupDto group1 = db.users().insertGroup(org);
+    ComponentDto project1 = db.components().insertProject(org);
+    db.users().insertPermissionOnAnyone(org, "perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+    db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
     dbSession.commit();
@@ -398,13 +398,13 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void delete_global_permission_from_anyone() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    GroupDto group1 = db.users().insertGroup(organizationDto);
-    ComponentDto project1 = db.components().insertProject(organizationDto);
-    db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+    OrganizationDto org = db.organizations().insert();
+    GroupDto group1 = db.users().insertGroup(org);
+    ComponentDto project1 = db.components().insertProject(org);
+    db.users().insertPermissionOnAnyone(org, "perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+    db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm1", group1.getOrganizationUuid(), null, null);
     dbSession.commit();
@@ -415,13 +415,13 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void delete_project_permission_from_group() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    GroupDto group1 = db.users().insertGroup(organizationDto);
-    ComponentDto project1 = db.components().insertProject(organizationDto);
-    db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+    OrganizationDto org = db.organizations().insert();
+    GroupDto group1 = db.users().insertGroup(org);
+    ComponentDto project1 = db.components().insertProject(org);
+    db.users().insertPermissionOnAnyone(org, "perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+    db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.getId());
     dbSession.commit();
@@ -432,13 +432,13 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void delete_project_permission_from_anybody() {
-    OrganizationDto organizationDto = db.organizations().insert();
-    GroupDto group1 = db.users().insertGroup(organizationDto);
-    ComponentDto project1 = db.components().insertProject(organizationDto);
-    db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+    OrganizationDto org = db.organizations().insert();
+    GroupDto group1 = db.users().insertGroup(org);
+    ComponentDto project1 = db.components().insertProject(org);
+    db.users().insertPermissionOnAnyone(org, "perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
     db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
-    db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+    db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm4", group1.getOrganizationUuid(), null, project1.getId());
     dbSession.commit();
index b62e2b6e765052c00d2ffbd7015824dbd3297726..51f1193de376e2f31488558379da4bf3db23fb5e 100644 (file)
@@ -262,9 +262,9 @@ public class UserDbTester {
     db.commit();
   }
 
-  public GroupPermissionDto insertProjectPermissionOnAnyone(OrganizationDto org, String permission, ComponentDto project) {
+  public GroupPermissionDto insertProjectPermissionOnAnyone(String permission, ComponentDto project) {
     GroupPermissionDto dto = new GroupPermissionDto()
-      .setOrganizationUuid(org.getUuid())
+      .setOrganizationUuid(project.getOrganizationUuid())
       .setGroupId(null)
       .setRole(permission)
       .setResourceId(project.getId());
@@ -274,6 +274,7 @@ public class UserDbTester {
   }
 
   public GroupPermissionDto insertProjectPermissionOnGroup(GroupDto group, String permission, ComponentDto project) {
+    checkArgument(group.getOrganizationUuid().equals(project.getOrganizationUuid()), "Different organizations");
     GroupPermissionDto dto = new GroupPermissionDto()
       .setOrganizationUuid(group.getOrganizationUuid())
       .setGroupId(group.getId())
@@ -298,6 +299,7 @@ public class UserDbTester {
       return db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(),
         org.getUuid(), null);
     }
+    checkArgument(org.getUuid().equals(project.getOrganizationUuid()), "Different organizations");
     return db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(),
       org.getUuid(), null, project.getId());
   }
@@ -322,7 +324,11 @@ public class UserDbTester {
   }
 
   /**
+<<<<<<< HEAD
    * Grant permission on given project in default organization
+=======
+   * Grant permission on given project
+>>>>>>> 6772c5b73a... SONAR-8704 remove error-prone params Organization in UserDbTester
    */
   public UserPermissionDto insertProjectPermissionOnUser(UserDto user, String permission, ComponentDto project) {
     UserPermissionDto dto = new UserPermissionDto(project.getOrganizationUuid(), permission, user.getId(), project.getId());