public static ActiveRuleParamDto createFor(RuleParamDto param) { Preconditions.checkArgument(param.getId() != null, "Parameter is not persisted"); return new ActiveRuleParamDto() .setKey(param.getName()) .setRulesParameterId(param.getId()); }
@Test public void groupByKey() { assertThat(ActiveRuleParamDto.groupByKey(Collections.emptyList())).isEmpty(); Collection<ActiveRuleParamDto> dtos = Arrays.asList( new ActiveRuleParamDto().setKey("foo"), new ActiveRuleParamDto().setKey("bar") ); Map<String, ActiveRuleParamDto> group = ActiveRuleParamDto.groupByKey(dtos); assertThat(group.keySet()).containsOnly("foo", "bar"); } }
.setActiveRuleId(activeRuleDto.getId()) .setRulesParameterId(ruleParam1.getId()) .setKey(ruleParam1.getName()) .setValue(ruleParam1.getDefaultValue())); dbSession.commit();
@Test public void show_rule_with_activation() { OrganizationDto organization = db.organizations().insert(); RuleDefinitionDto rule = db.rules().insert(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*")); RuleMetadataDto ruleMetadata = db.rules().insertOrUpdateMetadata(rule, organization, m -> m.setNoteData(null).setNoteUserUuid(null)); QProfileDto qProfile = db.qualityProfiles().insert(organization); ActiveRuleDto activeRule = db.qualityProfiles().activateRule(qProfile, rule); db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, new ActiveRuleParamDto() .setRulesParameterId(ruleParam.getId()) .setKey(ruleParam.getName()) .setValue(".*?")); db.commit(); ShowResponse result = ws.newRequest() .setParam(PARAM_KEY, rule.getKey().toString()) .setParam(PARAM_ACTIVES, "true") .setParam(PARAM_ORGANIZATION, organization.getKey()) .executeProtobuf(ShowResponse.class); List<Rules.Active> actives = result.getActivesList(); assertThat(actives).extracting(Rules.Active::getQProfile).containsExactly(qProfile.getKee()); assertThat(actives).extracting(Rules.Active::getSeverity).containsExactly(activeRule.getSeverityString()); assertThat(actives).extracting(Rules.Active::getInherit).containsExactly("NONE"); assertThat(actives.get(0).getParamsList()) .extracting(Rules.Active.Param::getKey, Rules.Active.Param::getValue) .containsExactlyInAnyOrder(tuple(ruleParam.getName(), ".*?")); }
private QProfileDto createCustomProfile(OrganizationDto org) { QProfileDto profile = db.qualityProfiles().insert(org, p -> p.setLanguage("xoo").setIsBuiltIn(false)); ActiveRuleDto activeRuleDto = db.qualityProfiles().activateRule(profile, rule); ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto() .setRulesParameterId(ruleParam.getId()) .setKey("foo") .setValue("bar"); db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, activeRuleParam); db.getDbClient().qProfileChangeDao().insert(dbSession, new QProfileChangeDto() .setChangeType(ActiveRuleChange.Type.ACTIVATED.name()) .setRulesProfileUuid(profile.getRulesProfileUuid())); db.commit(); return profile; }
private RulesProfileDto createBuiltInProfile() { RulesProfileDto rulesProfileDto = new RulesProfileDto() .setIsBuiltIn(true) .setKee(Uuids.createFast()) .setLanguage("xoo") .setName("Sonar way"); db.getDbClient().qualityProfileDao().insert(dbSession, rulesProfileDto); ActiveRuleDto activeRuleDto = new ActiveRuleDto() .setProfileId(rulesProfileDto.getId()) .setRuleId(rule.getId()) .setSeverity(Severity.BLOCKER); db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto); ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto() .setRulesParameterId(ruleParam.getId()) .setKey("foo") .setValue("bar"); db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, activeRuleParam); db.getDbClient().qProfileChangeDao().insert(dbSession, new QProfileChangeDto() .setChangeType(ActiveRuleChange.Type.ACTIVATED.name()) .setRulesProfileUuid(rulesProfileDto.getKee())); db.commit(); return rulesProfileDto; }
public static ActiveRuleParamDto createFor(RuleParamDto param) { Preconditions.checkArgument(param.getId() != null, "Parameter is not persisted"); return new ActiveRuleParamDto() .setKey(param.getName()) .setRulesParameterId(param.getId()); }