@Test public void exists() { OrganizationDto organization = db.organizations().insert(); QProfileDto profile = db.qualityProfiles().insert(organization); QProfileDto anotherProfile = db.qualityProfiles().insert(organization); UserDto user = db.users().insertUser(); UserDto anotherUser = db.users().insertUser(); db.qualityProfiles().addUserPermission(profile, user); assertThat(underTest.exists(db.getSession(), profile, user)).isTrue(); assertThat(underTest.exists(db.getSession(), profile, anotherUser)).isFalse(); assertThat(underTest.exists(db.getSession(), anotherProfile, user)).isFalse(); assertThat(underTest.exists(db.getSession(), anotherProfile, anotherUser)).isFalse(); }
@Test public void countActiveRulesByQuery_filter_by_organization() { db.qualityProfiles().activateRule(profile1, rule1); OrganizationDto anotherOrganization = db.organizations().insert(); QProfileDto profileOnAnotherOrganization = db.qualityProfiles().insert(anotherOrganization); db.qualityProfiles().activateRule(profileOnAnotherOrganization, rule1); assertThat(underTest.countActiveRulesByQuery(dbSession, ActiveRuleCountQuery.builder().setOrganization(organization).setProfiles(asList(profile1, profileOnAnotherOrganization)).build())) .containsOnly(entry(profile1.getKee(), 1L)); }
@Test public void exists() { OrganizationDto organization = db.organizations().insert(); QProfileDto profile = db.qualityProfiles().insert(organization); QProfileDto anotherProfile = db.qualityProfiles().insert(organization); GroupDto group = db.users().insertGroup(organization); GroupDto anotherGroup = db.users().insertGroup(organization); db.qualityProfiles().addGroupPermission(profile, group); assertThat(underTest.exists(db.getSession(), profile, group)).isTrue(); assertThat(underTest.exists(db.getSession(), profile, anotherGroup)).isFalse(); assertThat(underTest.exists(db.getSession(), anotherProfile, group)).isFalse(); assertThat(underTest.exists(db.getSession(), anotherProfile, anotherGroup)).isFalse(); assertThat(underTest.exists(db.getSession(), profile, asList(group, anotherGroup))).isTrue(); assertThat(underTest.exists(db.getSession(), profile, singletonList(anotherGroup))).isFalse(); assertThat(underTest.exists(db.getSession(), profile, emptyList())).isFalse(); }
private QProfileDto createProfile(OrganizationDto organization, boolean isDefault) { QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO_LANGUAGE)); if (isDefault) { db.qualityProfiles().setAsDefault(profile); } return profile; }
@Test public void deleteProjectAssociationsByProfileUuids_does_nothing_if_empty_uuids() { QProfileDto profile = db.qualityProfiles().insert(organization); ComponentDto project = db.components().insertPrivateProject(); db.qualityProfiles().associateWithProject(project, profile); underTest.deleteProjectAssociationsByProfileUuids(dbSession, Collections.emptyList()); assertThat(db.countRowsOfTable(dbSession, "project_qprofiles")).isEqualTo(1); }
@Test public void statistics_on_projects() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); QProfileDto profileOnXoo1 = db.qualityProfiles().insert(db.getDefaultOrganization(), q -> q.setLanguage(XOO1.getKey())); QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(db.getDefaultOrganization(), q -> q.setLanguage(XOO1.getKey())); db.qualityProfiles().associateWithProject(project1, profileOnXoo1); db.qualityProfiles().associateWithProject(project2, profileOnXoo1); db.qualityProfiles().setAsDefault(defaultProfileOnXoo1); SearchWsResponse result = call(ws.newRequest()); assertThat(result.getProfilesList()) .extracting(QualityProfile::hasProjectCount, QualityProfile::getProjectCount) .containsExactlyInAnyOrder(tuple(true, 2L), tuple(false, 0L)); }
@Test public void renameAndCommit_updates_name_of_specified_profiles() { OrganizationDto org1 = db.organizations().insert(); OrganizationDto org2 = db.organizations().insert(); QProfileDto fooInOrg1 = db.qualityProfiles().insert(org1, p -> p.setName("foo")); QProfileDto fooInOrg2 = db.qualityProfiles().insert(org2, p -> p.setName("foo")); QProfileDto bar = db.qualityProfiles().insert(org1, p -> p.setName("bar")); underTest.renameRulesProfilesAndCommit(dbSession, asList(fooInOrg1.getRulesProfileUuid(), fooInOrg2.getRulesProfileUuid()), "foo (copy)"); assertThat(underTest.selectOrFailByUuid(dbSession, fooInOrg1.getKee()).getName()).isEqualTo("foo (copy)"); assertThat(underTest.selectOrFailByUuid(dbSession, fooInOrg2.getKee()).getName()).isEqualTo("foo (copy)"); assertThat(underTest.selectOrFailByUuid(dbSession, bar.getKee()).getName()).isEqualTo("bar"); }
@Test public void delete_removes_qprofile_edit_permissions() { OrganizationDto organization = db.organizations().insert(); QProfileDto profile = db.qualityProfiles().insert(organization); UserDto user = db.users().insertUser(); db.qualityProfiles().addUserPermission(profile, user); GroupDto group = db.users().insertGroup(organization); db.qualityProfiles().addGroupPermission(profile, group); underTest.delete(dbSession, asList(profile)); assertThat(db.countRowsOfTable(dbSession, "qprofile_edit_users")).isZero(); assertThat(db.countRowsOfTable(dbSession, "qprofile_edit_groups")).isZero(); }
public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule) { return activateRule(profile, rule, ar -> { }); }
@Test public void as_qprofile_editor() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(LANGUAGE_1)); db.qualityProfiles().associateWithProject(project, profile); UserDto user = db.users().insertUser(); db.qualityProfiles().addUserPermission(profile, user); userSession.logIn(user); call(project, profile); assertProjectIsNotAssociatedToProfile(project, profile); }
@Test public void delete_removes_custom_profile_from_project_associations() { OrganizationDto org = db.organizations().insert(); QProfileDto profile = createCustomProfile(org); ComponentDto project = db.components().insertPrivateProject(org); db.qualityProfiles().associateWithProject(project, profile); underTest.delete(dbSession, asList(profile)); assertThatCustomProfileDoesNotExist(profile); }
@Test public void delete_removes_custom_profile_marked_as_default() { OrganizationDto org = db.organizations().insert(); QProfileDto profile = createCustomProfile(org); db.qualityProfiles().setAsDefault(profile); underTest.delete(dbSession, asList(profile)); assertThatCustomProfileDoesNotExist(profile); }
@Test public void isDefault_returns_true_if_profile_is_marked_as_default() { OrganizationDto org = dbTester.organizations().insert(); QProfileDto profile1 = dbTester.qualityProfiles().insert(org); QProfileDto profile2 = dbTester.qualityProfiles().insert(org); dbTester.qualityProfiles().setAsDefault(profile1); assertThat(underTest.isDefault(dbSession, org.getUuid(), profile1.getKee())).isTrue(); assertThat(underTest.isDefault(dbSession, org.getUuid(), profile2.getKee())).isFalse(); assertThat(underTest.isDefault(dbSession, org.getUuid(), "does_not_exist")).isFalse(); }
@Test public void test_deleteProjectAssociationsByProfileUuids() { QProfileDto profile1 = db.qualityProfiles().insert(organization); QProfileDto profile2 = db.qualityProfiles().insert(organization); ComponentDto project1 = db.components().insertPrivateProject(organization); ComponentDto project2 = db.components().insertPrivateProject(organization); ComponentDto project3 = db.components().insertPrivateProject(organization); db.qualityProfiles().associateWithProject(project1, profile1); db.qualityProfiles().associateWithProject(project2, profile1); db.qualityProfiles().associateWithProject(project3, profile2); underTest.deleteProjectAssociationsByProfileUuids(dbSession, asList(profile1.getKee(), "does_not_exist")); List<Map<String, Object>> rows = db.select(dbSession, "select project_uuid as \"projectUuid\", profile_key as \"profileKey\" from project_qprofiles"); assertThat(rows).hasSize(1); assertThat(rows.get(0).get("projectUuid")).isEqualTo(project3.uuid()); assertThat(rows.get(0).get("profileKey")).isEqualTo(profile2.getKee()); }
@Test public void filter_on_project_key() { ComponentDto project = db.components().insertPrivateProject(); QProfileDto profileOnXoo1 = db.qualityProfiles().insert(db.getDefaultOrganization(), q -> q.setLanguage(XOO1.getKey())); QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(db.getDefaultOrganization(), q -> q.setLanguage(XOO1.getKey())); QProfileDto defaultProfileOnXoo2 = db.qualityProfiles().insert(db.getDefaultOrganization(), q -> q.setLanguage(XOO2.getKey())); db.qualityProfiles().associateWithProject(project, profileOnXoo1); db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2); SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT_KEY, project.getDbKey())); assertThat(result.getProfilesList()) .extracting(QualityProfile::getKey) .containsExactlyInAnyOrder(profileOnXoo1.getKee(), defaultProfileOnXoo2.getKee()) .doesNotContain(defaultProfileOnXoo1.getKee()); }
@Test public void renameAndCommit_does_nothing_if_empty_keys() { OrganizationDto org = db.organizations().insert(); QProfileDto profile = db.qualityProfiles().insert(org, p -> p.setName("foo")); underTest.renameRulesProfilesAndCommit(dbSession, Collections.emptyList(), "foo (copy)"); assertThat(underTest.selectOrFailByUuid(dbSession, profile.getKee()).getName()).isEqualTo("foo"); }
@Test public void qp_editors_can_remove_group() { OrganizationDto organization = db.organizations().insert(); QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO)); GroupDto group = db.users().insertGroup(organization); db.qualityProfiles().addGroupPermission(profile, group); UserDto userAllowedToEditProfile = db.users().insertUser(); db.qualityProfiles().addUserPermission(profile, userAllowedToEditProfile); userSession.logIn(userAllowedToEditProfile); ws.newRequest() .setParam(PARAM_QUALITY_PROFILE, profile.getName()) .setParam(PARAM_LANGUAGE, XOO) .setParam(PARAM_GROUP, group.getName()) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isFalse(); }
private ActiveRuleDto activate(QProfileDto profile, RuleDefinitionDto rule) { return db.qualityProfiles().activateRule(profile, rule); }
@Test public void delete_builtin_profile_associated_to_project() { RulesProfileDto builtInProfile = createBuiltInProfile(); OrganizationDto org = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(org); QProfileDto profile = associateBuiltInProfileToOrganization(builtInProfile, org); db.qualityProfiles().associateWithProject(project, profile); assertThat(db.getDbClient().qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage())).isNotNull(); underTest.delete(dbSession, asList(profile)); verifyNoCallsActiveRuleIndexerDelete(); // remove only from org_qprofiles and project_qprofiles assertThat(db.getDbClient().qualityProfileDao().selectOrderedByOrganizationUuid(dbSession, org)).isEmpty(); assertThat(db.getDbClient().qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage())).isNull(); assertThatRulesProfileExists(builtInProfile); }
@Test public void delete_builtin_profile_marked_as_default_on_organization() { RulesProfileDto builtInProfile = createBuiltInProfile(); OrganizationDto org = db.organizations().insert(); QProfileDto profile = associateBuiltInProfileToOrganization(builtInProfile, org); db.qualityProfiles().setAsDefault(profile); underTest.delete(dbSession, asList(profile)); verifyNoCallsActiveRuleIndexerDelete(); // remove only from org_qprofiles and default_qprofiles assertThat(db.getDbClient().qualityProfileDao().selectOrderedByOrganizationUuid(dbSession, org)).isEmpty(); assertThat(db.getDbClient().qualityProfileDao().selectDefaultProfile(dbSession, org, profile.getLanguage())).isNull(); assertThatRulesProfileExists(builtInProfile); }