import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
import org.sonar.server.user.index.UserIndexer;
public DbTester db = DbTester.create(system2);
private Settings settings = new MapSettings();
- private DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private UserUpdater userUpdater = new UserUpdater(
mock(NewUserNotifier.class),
settings,
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.organization;
-
-import java.util.Optional;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.server.property.InternalProperties;
-
-import static com.google.common.base.Preconditions.checkState;
-
-public class DefaultOrganizationProviderRule implements DefaultOrganizationProvider {
-
- private final DbTester dbTester;
-
- public static DefaultOrganizationProviderRule create(DbTester dbTester) {
- return new DefaultOrganizationProviderRule(dbTester);
- }
-
- @Override
- public DefaultOrganization get() {
- DbSession dbSession = dbTester.getSession();
- Optional<String> uuid = dbTester.getDbClient().internalPropertiesDao().selectByKey(dbSession, InternalProperties.DEFAULT_ORGANIZATION);
- checkState(uuid.isPresent() && !uuid.get().isEmpty(), "No Default organization uuid configured");
- Optional<OrganizationDto> dto = dbTester.getDbClient().organizationDao().selectByUuid(dbSession, uuid.get());
- checkState(dto.isPresent(), "Default organization with uuid '%s' does not exist", uuid.get());
- return toDefaultOrganization(dto.get());
- }
-
- public OrganizationDto getDto() {
- String uuid = get().getUuid();
- return dbTester.getDbClient().organizationDao().selectByUuid(dbTester.getSession(), uuid)
- .orElseThrow(() -> new IllegalStateException("Missing default organization in database [uuid=" + uuid + "]"));
- }
-
- private static DefaultOrganization toDefaultOrganization(OrganizationDto organizationDto) {
- return DefaultOrganization.newBuilder()
- .setUuid(organizationDto.getUuid())
- .setKey(organizationDto.getKey())
- .setName(organizationDto.getName())
- .setCreatedAt(organizationDto.getCreatedAt())
- .setUpdatedAt(organizationDto.getUpdatedAt())
- .build();
- }
-
- private DefaultOrganizationProviderRule(DbTester dbTester) {
- this.dbTester = dbTester;
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.organization;
+
+import org.sonar.db.DbTester;
+import org.sonar.db.organization.OrganizationDto;
+
+public class TestDefaultOrganizationProvider implements DefaultOrganizationProvider {
+
+ private final DbTester dbTester;
+
+ private TestDefaultOrganizationProvider(DbTester dbTester) {
+ this.dbTester = dbTester;
+ }
+
+ public static TestDefaultOrganizationProvider from(DbTester dbTester) {
+ return new TestDefaultOrganizationProvider(dbTester);
+ }
+
+ @Override
+ public DefaultOrganization get() {
+ return toDefaultOrganization(dbTester.getDefaultOrganization());
+ }
+
+ private static DefaultOrganization toDefaultOrganization(OrganizationDto organizationDto) {
+ return DefaultOrganization.newBuilder()
+ .setUuid(organizationDto.getUuid())
+ .setKey(organizationDto.getKey())
+ .setName(organizationDto.getName())
+ .setCreatedAt(organizationDto.getCreatedAt())
+ .setUpdatedAt(organizationDto.getUpdatedAt())
+ .build();
+ }
+}
@Test
public void add_permission_to_group_referenced_by_its_name() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
-
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
loginAsAdminOnDefaultOrganization();
+
newRequest()
.setParam(PARAM_GROUP_NAME, "sonar-administrators")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
@Test
public void add_permission_to_group_referenced_by_its_id() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
-
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
loginAsAdminOnDefaultOrganization();
+
newRequest()
.setParam(PARAM_GROUP_ID, group.getId().toString())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
@Test
public void add_permission_to_project_referenced_by_its_id() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY));
-
loginAsAdminOnDefaultOrganization();
+
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
.setParam(PARAM_PROJECT_ID, A_PROJECT_UUID)
@Test
public void add_permission_to_project_referenced_by_its_key() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY));
-
loginAsAdminOnDefaultOrganization();
+
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
.setParam(PARAM_PROJECT_KEY, A_PROJECT_KEY)
@Test
public void add_with_view_uuid() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key"));
-
loginAsAdminOnDefaultOrganization();
+
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
.setParam(PARAM_PROJECT_ID, view.uuid())
@Test
public void fail_if_project_uuid_is_not_found() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
loginAsAdminOnDefaultOrganization();
expectedException.expect(NotFoundException.class);
@Test
public void adding_a_project_permission_fails_if_project_is_not_set() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
loginAsAdminOnDefaultOrganization();
expectedException.expect(BadRequestException.class);
@Test
public void adding_a_project_permission_fails_if_component_is_not_a_project() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project, null, "file-uuid"));
loginAsAdminOnDefaultOrganization();
}
@Test
- public void fail_if_not_administrator_of_organization() throws Exception {
- GroupDto group = db.users().insertGroup();
+ public void fail_when_permission_is_missing() throws Exception {
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
loginAsAdminOnDefaultOrganization();
expectedException.expect(IllegalArgumentException.class);
.execute();
}
+ @Test
+ public void fail_if_not_administrator_of_organization() throws Exception {
+ GroupDto group = db.users().insertGroup();
+ loginAsAdminOnDefaultOrganization();
+
+ expectedException.expect(IllegalArgumentException.class);
+
+ newRequest()
+ .setParam(PARAM_GROUP_NAME, group.getName())
+ .execute();
+ }
+
@Test
public void fail_if_administrator_of_other_organization_only() throws Exception {
OrganizationDto org1 = db.organizations().insert();
@Test
public void adding_global_permission_fails_if_not_administrator_of_organization() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
// user is administrator of another organization
userSession.login().addOrganizationPermission("anotherOrg", SYSTEM_ADMIN);
@Test
public void adding_project_permission_fails_if_not_administrator_of_project() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertProject();
userSession.login();
*/
@Test
public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertProject();
userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
import org.sonar.db.permission.template.PermissionTemplateTesting;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.issue.index.IssueAuthorizationIndexer;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.permission.GroupPermissionChanger;
import org.sonar.server.permission.PermissionUpdater;
import org.sonar.server.permission.UserPermissionChanger;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
-
@Rule
public ExpectedException expectedException = ExpectedException.none();
- protected DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
protected UserSessionRule userSession = UserSessionRule.standalone();
protected WsTester wsTester;
@Before
public void setUp() {
- OrganizationDto defOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defOrg = db.getDefaultOrganization();
group1 = db.users().insertGroup(defOrg, "group-1-name");
group2 = db.users().insertGroup(defOrg, "group-2-name");
group3 = db.users().insertGroup(defOrg, "group-3-name");
@Test
public void search_groups_with_project_permissions() throws Exception {
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid"));
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "project-group-name");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
ComponentDto anotherProject = db.components().insertComponent(newProjectDto());
- GroupDto anotherGroup = db.users().insertGroup(defaultOrganizationProvider.getDto(), "another-project-group-name");
+ GroupDto anotherGroup = db.users().insertGroup(db.getDefaultOrganization(), "another-project-group-name");
db.users().insertProjectPermissionOnGroup(anotherGroup, ISSUE_ADMIN, anotherProject);
- GroupDto groupWithoutPermission = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-without-permission");
+ GroupDto groupWithoutPermission = db.users().insertGroup(db.getDefaultOrganization(), "group-without-permission");
userSession.login().addProjectUuidPermissions(ADMIN, "project-uuid");
String result = newRequest()
@Test
public void return_also_groups_without_permission_when_search_query() throws Exception {
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid"));
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-with-permission");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group-with-permission");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
- GroupDto groupWithoutPermission = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-without-permission");
- GroupDto anotherGroup = db.users().insertGroup(defaultOrganizationProvider.getDto(), "another-group");
+ GroupDto groupWithoutPermission = db.users().insertGroup(db.getDefaultOrganization(), "group-without-permission");
+ GroupDto anotherGroup = db.users().insertGroup(db.getDefaultOrganization(), "another-group");
loginAsAdmin();
String result = newRequest()
@Test
public void return_only_groups_with_permission_when_no_search_query() throws Exception {
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid"));
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "project-group-name");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
- GroupDto groupWithoutPermission = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-without-permission");
+ GroupDto groupWithoutPermission = db.users().insertGroup(db.getDefaultOrganization(), "group-without-permission");
loginAsAdmin();
String result = newRequest()
@Test
public void return_anyone_group_when_search_query_and_no_param_permission() throws Exception {
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid"));
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-with-permission");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group-with-permission");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
loginAsAdmin();
@Test
public void search_groups_on_views() throws Exception {
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key"));
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "project-group-name");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, view);
loginAsAdmin();
@Before
public void setUp() {
- aGroup = db.users().insertGroup(defaultOrganizationProvider.getDto(), "sonar-administrators");
+ aGroup = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
}
@Override
GroupDto group2 = db.users().insertGroup(newGroupDto());
GroupDto group3 = db.users().insertGroup(newGroupDto());
- db.users().insertProjectPermissionOnAnyone(defaultOrganizationProvider.getDto(), UserRole.ADMIN, jdk7);
+ db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group3, UserRole.ADMIN, jdk7);
@Before
public void setUp() {
template = insertTemplate();
- group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-name");
+ group = db.users().insertGroup(db.getDefaultOrganization(), "group-name");
}
@Test
public void setUp() {
user1 = db.users().insertUser("user-login-1");
user2 = db.users().insertUser("user-login-2");
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
group1 = db.users().insertGroup(defaultOrg, "group-name-1");
group2 = db.users().insertGroup(defaultOrg, "group-name-2");
public void setUp() {
user1 = db.users().insertUser("user-login-1");
user2 = db.users().insertUser("user-login-2");
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
group1 = db.users().insertGroup(defaultOrg, "group-name-1");
group2 = db.users().insertGroup(defaultOrg, "group-name-2");
public void setUp() {
loginAsAdminOnDefaultOrganization();
- group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-name");
+ group = db.users().insertGroup(db.getDefaultOrganization(), "group-name");
template = insertTemplate();
addGroupToTemplate(template, group.getId(), PERMISSION);
}
public void return_all_permissions_of_matching_groups() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
- GroupDto group1 = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-1-name");
+ GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group1.getId()));
- GroupDto group2 = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-2-name");
+ GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
- GroupDto group3 = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-3-name");
+ GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name");
// Anyone
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
public void search_by_permission() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
- GroupDto group1 = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-1-name");
+ GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
- GroupDto group2 = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-2-name");
+ GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
- GroupDto group3 = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group-3-name");
+ GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name");
// Anyone
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
@Test
public void search_by_template_name() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3-name");
@Test
public void search_with_pagination() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
@Test
public void search_with_text_query() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
@Test
public void search_with_text_query_return_all_groups_even_when_no_permission_set() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
db.users().insertGroup(defaultOrg, "group-1-name");
db.users().insertGroup(defaultOrg, "group-2-name");
@Test
public void search_with_text_query_return_anyone_group_even_when_no_permission_set() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group.getId()));
commit();
loginAsAdminOnDefaultOrganization();
}
private GroupDto insertGroupOnDefaultOrganization(String name, String description) {
- return db.users().insertGroup(newGroupDto().setName(name).setDescription(description).setOrganizationUuid(defaultOrganizationProvider.get().getUuid()));
+ return db.users().insertGroup(newGroupDto().setName(name).setDescription(description).setOrganizationUuid(db.getDefaultOrganization().getUuid()));
}
private void addGroupToTemplate(PermissionTemplateGroupDto permissionTemplateGroup) {
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.permission.template.PermissionTemplateGroupDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.platform.PersistentSettings;
import static org.assertj.core.api.Assertions.assertThat;
public LogTester logTester = new LogTester();
private PersistentSettings settings = mock(PersistentSettings.class);
- private DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private RegisterPermissionTemplates underTest = new RegisterPermissionTemplates(db.getDbClient(), settings, defaultOrganizationProvider);
@Test
import org.sonar.server.exceptions.Message;
import org.sonar.server.exceptions.ServerException;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.index.UserIndexDefinition;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.util.Validation;
@Before
public void setUp() {
userIndexer = new UserIndexer(dbClient, es.client());
- DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
underTest = new UserUpdater(newUserNotifier, settings, dbClient,
userIndexer, system2, defaultOrganizationProvider);
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.ExternalIdentity;
import org.sonar.server.user.NewUser;
private UserUpdater userUpdater;
private DbSession session;
private SecurityRealmFactory realmFactory = mock(SecurityRealmFactory.class);
- private DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(dbTester);
+ private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
@Before
public void setUp() {
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
defaultGroupInDefaultOrg = db.users().insertGroup(db.getDefaultOrganization(), DEFAULT_GROUP_NAME);
userIndexer = new UserIndexer(db.getDbClient(), esTester.client());
index = new UserIndex(esTester.client());
- DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
tester = new WsTester(new UsersWs(new CreateAction(db.getDbClient(),
new UserUpdater(mock(NewUserNotifier.class), settings, db.getDbClient(), userIndexer, system2, defaultOrganizationProvider),
i18n, userSessionRule, new UserJsonWriter(userSessionRule))));
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
userIndexer = new UserIndexer(dbClient, esTester.client());
index = new UserIndex(esTester.client());
- DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
ws = new WsTester(new UsersWs(new DeactivateAction(
new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2, defaultOrganizationProvider), userSessionRule,
new UserJsonWriter(userSessionRule), dbClient)));
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
private DbSession session = dbTester.getSession();
private WsTester tester;
private UserIndexer userIndexer;
- private DefaultOrganizationProvider defaultOrganizationProvider = DefaultOrganizationProviderRule.create(dbTester);
+ private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
@Before
public void setUp() {
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private WsTester ws;
@Before
@Test
public void add_user_to_another_group() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
GroupDto admins = db.users().insertGroup(defaultOrg, "admins");
GroupDto users = db.users().insertGroup(defaultOrg, "users");
UserDto user = db.users().insertUser("my-admin");
@Test
public void fail_if_user_does_not_exist() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "admins");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "admins");
expectedException.expect(NotFoundException.class);
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.ServerException;
import org.sonar.server.organization.DefaultOrganization;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private WsTester ws;
@Before
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
public DbTester db = DbTester.create(System2.INSTANCE);
private ComponentDbTester componentTester = new ComponentDbTester(db);
- private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private GroupDto defaultGroup;
private WsTester ws;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private WsTester ws;
@Before
@Test
public void does_nothing_if_user_is_not_in_group() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "admins");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "admins");
UserDto user = db.users().insertUser("my-admin");
loginAsAdmin();
@Test
public void remove_user_by_group_id() throws Exception {
- GroupDto users = db.users().insertGroup(defaultOrganizationProvider.getDto(), "users");
+ GroupDto users = db.users().insertGroup(db.getDefaultOrganization(), "users");
UserDto user = db.users().insertUser("my-admin");
db.users().insertMember(users, user);
@Test
public void remove_user_by_group_name_in_default_organization() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "group_name");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group_name");
UserDto user = db.users().insertUser("user_login");
db.users().insertMember(group, user);
@Test
public void remove_user_only_from_one_group() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
GroupDto users = db.users().insertGroup(defaultOrg, "user");
GroupDto admins = db.users().insertGroup(defaultOrg, "admins");
UserDto user = db.users().insertUser("user");
@Test
public void fail_if_unknown_user() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "admins");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "admins");
expectedException.expect(NotFoundException.class);
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
}
private GroupWsSupport newGroupWsSupport() {
- return new GroupWsSupport(db.getDbClient(), DefaultOrganizationProviderRule.create(db));
+ return new GroupWsSupport(db.getDbClient(), TestDefaultOrganizationProvider.from(db));
}
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.ServerException;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.platform.PersistentSettings;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private PersistentSettings settings = mock(PersistentSettings.class);
private WsTester ws = new WsTester(
new UserGroupsWs(new UpdateAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider), settings, defaultOrganizationProvider)));
@Test
public void update_default_group_name_also_update_default_group_property() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), DEFAULT_GROUP_NAME_VALUE);
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), DEFAULT_GROUP_NAME_VALUE);
loginAsAdminOnDefaultOrganization();
newRequest()
@Test
public void update_default_group_name_does_not_update_default_group_setting_when_null() throws Exception {
when(settings.getString(DEFAULT_GROUP_NAME_KEY)).thenReturn(null);
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), DEFAULT_GROUP_NAME_VALUE);
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), DEFAULT_GROUP_NAME_VALUE);
loginAsAdminOnDefaultOrganization();
newRequest()
public void do_not_update_default_group_of_default_organization_if_updating_group_on_non_default_organization() throws Exception {
OrganizationDto org = db.organizations().insert();
when(settings.getString(DEFAULT_GROUP_NAME_KEY)).thenReturn(DEFAULT_GROUP_NAME_VALUE);
- GroupDto groupInDefaultOrg = db.users().insertGroup(defaultOrganizationProvider.getDto(), DEFAULT_GROUP_NAME_VALUE);
+ GroupDto groupInDefaultOrg = db.users().insertGroup(db.getDefaultOrganization(), DEFAULT_GROUP_NAME_VALUE);
GroupDto group = db.users().insertGroup(org, DEFAULT_GROUP_NAME_VALUE);
loginAsAdmin(org);
@Test
public void fail_to_update_if_name_already_exists() throws Exception {
- OrganizationDto defaultOrg = defaultOrganizationProvider.getDto();
+ OrganizationDto defaultOrg = db.getDefaultOrganization();
GroupDto groupToBeRenamed = db.users().insertGroup(defaultOrg, "a name");
String newName = "new-name";
db.users().insertGroup(defaultOrg, newName);
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProviderRule;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
import org.sonar.server.ws.WsTester.TestRequest;
public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
+ private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private WsTester wsTester;
@Before
@Test
public void filter_members_by_name() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "a group");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "a group");
UserDto adaLovelace = db.users().insertUser(newUserDto().setLogin("ada").setName("Ada Lovelace"));
UserDto graceHopper = db.users().insertUser(newUserDto().setLogin("grace").setName("Grace Hopper"));
db.users().insertMember(group, adaLovelace);
@Test
public void selected_users() throws Exception {
- GroupDto group = db.users().insertGroup(defaultOrganizationProvider.getDto(), "a group");
+ GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "a group");
UserDto user1 = db.users().insertUser(newUserDto().setLogin("ada").setName("Ada Lovelace"));
db.users().insertUser(newUserDto().setLogin("grace").setName("Grace Hopper"));
db.users().insertMember(group, user1);