/** * Create a key. Parameters are NOT null. */ public static ActiveRuleKey of(QProfileDto profile, RuleKey ruleKey) { return new ActiveRuleKey(profile.getRulesProfileUuid(), ruleKey); }
private QProfileChangeDto insertChange(QProfileDto profile, String type, @Nullable String login, @Nullable String data) { return insertChange(profile.getRulesProfileUuid(), type, login, data); }
private void assertThatCustomProfileDoesNotExist(QProfileDto profile) { assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0); // TODO active_rule_parameters }
@Test public void of() { RuleKey ruleKey = RuleKey.of("xoo", "R1"); QProfileDto profile = newQualityProfileDto(); ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey); assertThat(key.getRuleProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); assertThat(key.getRuleKey()).isSameAs(ruleKey); assertThat(key.toString()).isEqualTo(profile.getRulesProfileUuid() + ":xoo:R1"); }
@Test public void rule_key_can_contain_colons() { RuleKey ruleKey = RuleKey.of("squid", "Key:With:Some::Colons"); QProfileDto profile = newQualityProfileDto(); ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey); assertThat(key.getRuleProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); assertThat(key.getRuleKey()).isSameAs(ruleKey); assertThat(key.toString()).isEqualTo(profile.getRulesProfileUuid() + ":squid:Key:With:Some::Colons"); }
private void assertThatCustomProfileExists(QProfileDto profile) { assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isGreaterThan(0); //assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isGreaterThan(0); //assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isGreaterThan(0); assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(1); assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isGreaterThan(0); assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isGreaterThan(0); // TODO active_rule_parameters }
@Test public void toDto() { QProfileDto profile = newQualityProfileDto(); ActiveRuleKey key = ActiveRuleKey.of(profile, RuleKey.of("P1", "R1")); int ruleId = new Random().nextInt(963); ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDefinitionDto().setId(ruleId)); QProfileChangeDto result = underTest.toDto(A_USER_UUID); assertThat(result.getChangeType()).isEqualTo(ACTIVATED.name()); assertThat(result.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); assertThat(result.getUserUuid()).isEqualTo(A_USER_UUID); assertThat(result.getDataAsMap().get("ruleId")).isEqualTo(String.valueOf(ruleId)); } }
private void verify(ActiveRuleDoc doc1, QProfileDto profile, ActiveRuleDto activeRule) { assertThat(doc1) .matches(doc -> doc.getId().equals("" + activeRule.getId())) .matches(doc -> doc.getRuleProfileUuid().equals(profile.getRulesProfileUuid())) .matches(doc -> doc.getSeverity().equals(activeRule.getSeverityString())); }
private QProfileChangeDto insertChange(QProfileDto profile, ActiveRuleChange.Type type, @Nullable UserDto user, @Nullable Map<String, Object> data) { return insertChange(c -> c.setRulesProfileUuid(profile.getRulesProfileUuid()) .setUserUuid(user == null ? null : user.getUuid()) .setChangeType(type.name()) .setData(data)); }
private QProfileDto verifyProfileInDb(OrganizationDto organization, BuiltInQProfile builtIn) { QProfileDto profileOnOrg1 = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(dbSession, organization, builtIn.getName(), builtIn.getLanguage()); assertThat(profileOnOrg1.getLanguage()).isEqualTo(builtIn.getLanguage()); assertThat(profileOnOrg1.getName()).isEqualTo(builtIn.getName()); assertThat(profileOnOrg1.getOrganizationUuid()).isEqualTo(organization.getUuid()); assertThat(profileOnOrg1.getParentKee()).isNull(); assertThat(profileOnOrg1.getLastUsed()).isNull(); assertThat(profileOnOrg1.getUserUpdatedAt()).isNull(); assertThat(profileOnOrg1.getRulesUpdatedAt()).isNotEmpty(); assertThat(profileOnOrg1.getKee()).isNotEqualTo(profileOnOrg1.getRulesProfileUuid()); assertThat(profileOnOrg1.getId()).isNotNull(); return profileOnOrg1; }
@Test public void deleteByRuleProfileUuids_deletes_rows_from_table() { underTest.insert(dbSession, newRow(profile1, rule1)); underTest.insert(dbSession, newRow(profile1, rule2)); underTest.insert(dbSession, newRow(profile2, rule1)); underTest.deleteByRuleProfileUuids(dbSession, asList(profile1.getRulesProfileUuid())); assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1); assertThat(underTest.selectByKey(dbSession, ActiveRuleKey.of(profile2, rule1.getKey()))).isPresent(); }
@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"); }
public static OrgQProfileDto from(QProfileDto qProfileDto) { return new OrgQProfileDto() .setUuid(qProfileDto.getKee()) .setOrganizationUuid(qProfileDto.getOrganizationUuid()) .setRulesProfileUuid(qProfileDto.getRulesProfileUuid()) .setParentUuid(qProfileDto.getParentKee()) .setLastUsed(qProfileDto.getLastUsed()) .setUserUpdatedAt(qProfileDto.getUserUpdatedAt()); } }
@Test public void deleteByProfileKeys_does_nothing_if_row_with_specified_key_does_not_exist() { QProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization()); insertChange(profile1.getRulesProfileUuid(), "ACTIVATED", null, null); underTest.deleteByRulesProfileUuids(dbSession, asList("does not exist")); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isEqualTo(1); }
public static RulesProfileDto from(QProfileDto qProfileDto) { return new RulesProfileDto() .setKee(qProfileDto.getRulesProfileUuid()) .setLanguage(qProfileDto.getLanguage()) .setName(qProfileDto.getName()) .setIsBuiltIn(qProfileDto.isBuiltIn()) .setId(qProfileDto.getId()) .setRulesUpdatedAt(qProfileDto.getRulesUpdatedAt()); } }
@Test public void scrollByRuleProfileForIndexing() { ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1); ActiveRuleDto ar2 = db.qualityProfiles().activateRule(profile2, rule1); ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2); Accumulator accumulator = new Accumulator(); underTest.scrollByRuleProfileForIndexing(dbSession, profile2.getRulesProfileUuid(), accumulator); assertThat(accumulator.list) .extracting(IndexedActiveRuleDto::getId, IndexedActiveRuleDto::getRepository, IndexedActiveRuleDto::getKey, IndexedActiveRuleDto::getRuleProfileUuid, IndexedActiveRuleDto::getSeverity) .containsExactlyInAnyOrder( tuple((long) ar2.getId(), ar2.getRuleKey().repository(), ar2.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar2.getSeverity()), tuple((long) ar3.getId(), ar3.getRuleKey().repository(), ar3.getRuleKey().rule(), profile2.getRulesProfileUuid(), ar3.getSeverity())); }
@Test public void commitDeletionOfProfiles() { ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1); ActiveRuleDto ar2 = db.qualityProfiles().activateRule(profile2, rule1); ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2); indexAll(); db.getDbClient().qualityProfileDao().deleteRulesProfilesByUuids(db.getSession(), singletonList(profile2.getRulesProfileUuid())); underTest.commitDeletionOfProfiles(db.getSession(), singletonList(profile2)); verifyOnlyIndexed(ar1); }
@Test public void deleteByRulesProfileUuids() { QProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization()); QProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization()); insertChange(profile1, "ACTIVATED", null, null); insertChange(profile1, "ACTIVATED", null, null); insertChange(profile2, "ACTIVATED", null, null); underTest.deleteByRulesProfileUuids(dbSession, asList(profile1.getRulesProfileUuid())); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isEqualTo(0); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile2.getKee()))).isEqualTo(1); }
@Test public void selectByRuleProfileUuid() { db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setIsBuiltIn(false)); db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setIsBuiltIn(true)); QProfileDto qprofile1 = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setIsBuiltIn(true)); dbSession.commit(); assertThat(underTest.selectByRuleProfileUuid(dbSession, db.getDefaultOrganization().getUuid(), qprofile1.getRulesProfileUuid())) .extracting(QProfileDto::getName) .containsOnly(qprofile1.getName()); assertThat(underTest.selectByRuleProfileUuid(dbSession, "A", qprofile1.getRulesProfileUuid())) .isNull(); assertThat(underTest.selectByRuleProfileUuid(dbSession, db.getDefaultOrganization().getUuid(), "A")) .isNull(); }
@Test public void selectUuidsOfCustomRulesProfiles_returns_the_custom_profiles_with_specified_name() { OrganizationDto org1 = db.organizations().insert(); OrganizationDto org2 = db.organizations().insert(); OrganizationDto org3 = db.organizations().insert(); QProfileDto outdatedProfile1 = db.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo")); QProfileDto outdatedProfile2 = db.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo")); QProfileDto builtInProfile = db.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo")); QProfileDto differentLanguage = db.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo")); QProfileDto differentName = db.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar")); Collection<String> keys = underTest.selectUuidsOfCustomRulesProfiles(dbSession, "java", "foo"); assertThat(keys).containsExactlyInAnyOrder(outdatedProfile1.getRulesProfileUuid(), outdatedProfile2.getRulesProfileUuid()); }