boolean isSame(ActiveRuleChange change) { ActiveRule.Inheritance inheritance = change.getInheritance(); if (inheritance != null && !inheritance.name().equals(activeRule.getInheritance())) { return false; } String severity = change.getSeverity(); if (severity != null && !severity.equals(activeRule.getSeverityString())) { return false; } for (Map.Entry<String, String> changeParam : change.getParameters().entrySet()) { ActiveRuleParamDto param = activeRuleParams.get(changeParam.getKey()); if (param != null && !StringUtils.equals(changeParam.getValue(), param.getValue())) { return false; } } return true; }
public QProfileChangeDto toDto() { QProfileChangeDto dto = new QProfileChangeDto(); dto.setChangeType(type.name()); dto.setProfileKey(getKey().qProfile()); Map<String, String> data = new HashMap<>(); data.put("key", getKey().toString()); data.put("ruleKey", getKey().ruleKey().toString()); parameters .entrySet() .stream() .filter(param -> !param.getKey().isEmpty()) .forEach(param -> data.put("param_" + param.getKey(), param.getValue())); if (StringUtils.isNotEmpty(severity)) { data.put("severity", severity); } if (inheritance != null) { data.put("inheritance", inheritance.name()); } dto.setData(data); return dto; }
private void verifyOneActiveRule( String profileKey, String expectedSeverity, @Nullable String expectedInheritance, Map<String, String> expectedParams) { List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(profileKey)); assertThat(activeRules).hasSize(1); ActiveRule activeRule = activeRules.get(0); assertThat(activeRule.severity()).isEqualTo(expectedSeverity); assertThat(activeRule.inheritance()) .isEqualTo( expectedInheritance == null ? ActiveRule.Inheritance.NONE : ActiveRule.Inheritance.valueOf(expectedInheritance)); // verify parameters assertThat(activeRule.params()).hasSize(expectedParams.size()); for (Map.Entry<String, String> entry : expectedParams.entrySet()) { String value = activeRule.params().get(entry.getKey()); assertThat(value).isEqualTo(entry.getValue()); } }