@Test public void update_target_profile() { // source with x1 activated RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "7"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); // create target with both x1 and x2 activated db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2()); activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.CRITICAL); activation.setParameter("max", "20"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P2_KEY); activation = new RuleActivation(RuleTesting.XOO_X2); activation.setSeverity(Severity.CRITICAL); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P2_KEY); dbSession.commit(); dbSession.clearCache(); // copy -> reset x1 and deactivate x2 copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName()); verifyOneActiveRule( QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, null, ImmutableMap.of("max", "7")); }
void setParent( DbSession dbSession, QualityProfileKey key, @Nullable QualityProfileKey parentKey) { QualityProfileDto profile = db.qualityProfileDao().getNonNullByKey(dbSession, key); if (parentKey == null) { // unset if parent is defined, else nothing to do removeParent(dbSession, profile); } else if (profile.getParentKey() == null || !profile.getParentKey().equals(parentKey)) { QualityProfileDto parentProfile = db.qualityProfileDao().getNonNullByKey(dbSession, parentKey); if (isDescendant(dbSession, profile, parentProfile)) { throw new BadRequestException( String.format( "Descendant profile '%s' can not be selected as parent of '%s'", parentKey, key)); } removeParent(dbSession, profile); // set new parent profile.setParent(parentKey.name()); db.qualityProfileDao().update(dbSession, profile); for (ActiveRuleDto parentActiveRule : db.activeRuleDao().findByProfileKey(dbSession, parentKey)) { RuleActivation activation = new RuleActivation(ActiveRuleKey.of(key, parentActiveRule.getKey().ruleKey())); activate(dbSession, activation); } } }
@Test public void create_target_profile_with_same_parent_than_source() { // two profiles : parent and its child db.qualityProfileDao() .insert(dbSession, QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY)); // parent and child with x1 activated RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "7"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); // copy child -> profile2 is created with parent P1 copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName()); verifyOneActiveRule( QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); QualityProfileDto profile2Dto = db.qualityProfileDao().selectByKey(dbSession, QProfileTesting.XOO_P2_KEY); assertThat(profile2Dto.getParentKee()).isEqualTo(QProfileTesting.XOO_P1_KEY); }
@Test public void create_target_profile() { // source RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "7"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); // target does not exist copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P2_NAME.getName()); verifyOneActiveRule( QProfileTesting.XOO_P2_NAME, Severity.BLOCKER, null, ImmutableMap.of("max", "7")); }
@Test public void fail_to_copy_on_self() { RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "7"); ruleActivator.activate(dbSession, activation, QProfileTesting.XOO_P1_KEY); dbSession.commit(); dbSession.clearCache(); try { copier.copyToName(QProfileTesting.XOO_P1_KEY, QProfileTesting.XOO_P1_NAME.getName()); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Source and target profiles are equal: P1"); } }