use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class OrganizationCreationImplTest method create_creates_default_template_for_new_organization.
@Test
public void create_creates_default_template_for_new_organization() throws OrganizationCreation.KeyConflictException {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
underTest.create(dbSession, SOME_USER_ID, FULL_POPULATED_NEW_ORGANIZATION);
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, FULL_POPULATED_NEW_ORGANIZATION.getKey()).get();
GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
assertThat(defaultTemplate.getName()).isEqualTo("Default template");
assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization " + FULL_POPULATED_NEW_ORGANIZATION.getName());
DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organization.getUuid()).get();
assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
assertThat(defaultTemplates.getViewUuid()).isNull();
assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, defaultTemplate.getId())).extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), tuple(ANYONE_GROUP_ID, UserRole.USER), tuple(ANYONE_GROUP_ID, UserRole.CODEVIEWER));
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class OrganizationCreationImplTest method createForUser_does_not_create_any_group.
@Test
public void createForUser_does_not_create_any_group() throws OrganizationCreation.KeyConflictException {
UserDto user = dbTester.users().insertUser(dto -> dto.setLogin(A_LOGIN).setName(A_NAME));
when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN);
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
enableCreatePersonalOrg(true);
underTest.createForUser(dbSession, user);
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, SLUG_OF_A_LOGIN).get();
assertThat(dbClient.groupDao().selectByOrganizationUuid(dbSession, organization.getUuid())).isEmpty();
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class OrganizationCreationImplTest method createForUser_creates_guarded_organization_with_key_name_and_description_generated_from_user_login_and_name_and_associated_to_user.
@Test
public void createForUser_creates_guarded_organization_with_key_name_and_description_generated_from_user_login_and_name_and_associated_to_user() {
UserDto user = dbTester.users().insertUser(A_LOGIN);
when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN);
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
enableCreatePersonalOrg(true);
underTest.createForUser(dbSession, user);
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, SLUG_OF_A_LOGIN).get();
assertThat(organization.getUuid()).isEqualTo(SOME_UUID);
assertThat(organization.getKey()).isEqualTo(SLUG_OF_A_LOGIN);
assertThat(organization.getName()).isEqualTo(user.getName());
assertThat(organization.getDescription()).isEqualTo(user.getName() + "'s personal organization");
assertThat(organization.getUrl()).isNull();
assertThat(organization.getAvatarUrl()).isNull();
assertThat(organization.isGuarded()).isTrue();
assertThat(organization.getUserId()).isEqualTo(user.getId());
assertThat(organization.getCreatedAt()).isEqualTo(SOME_DATE);
assertThat(organization.getUpdatedAt()).isEqualTo(SOME_DATE);
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class OrganizationCreationImplTest method create_does_not_require_description_url_and_avatar_to_be_non_null.
@Test
public void create_does_not_require_description_url_and_avatar_to_be_non_null() throws OrganizationCreation.KeyConflictException {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
underTest.create(dbSession, SOME_USER_ID, newOrganizationBuilder().setKey("key").setName("name").build());
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "key").get();
assertThat(organization.getKey()).isEqualTo("key");
assertThat(organization.getName()).isEqualTo("name");
assertThat(organization.getDescription()).isNull();
assertThat(organization.getUrl()).isNull();
assertThat(organization.getAvatarUrl()).isNull();
assertThat(organization.isGuarded()).isFalse();
assertThat(organization.getUserId()).isNull();
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class CreateActionTest method insertOrganization.
private OrganizationDto insertOrganization(String key) {
OrganizationDto dto = new OrganizationDto().setUuid(key + "_uuid").setKey(key).setName(key + "_name").setCreatedAt((long) key.hashCode()).setUpdatedAt((long) key.hashCode());
dbClient.organizationDao().insert(dbTester.getSession(), dto);
dbTester.commit();
return dto;
}
Aggregations