.setCardinality(Cardinality.SINGLE)
.setStatus(Rule.STATUS_READY)
.setLanguage(templateRule.getLanguage())
+ .setDefaultSubCharacteristicId(templateRule.getDefaultSubCharacteristicId())
+ .setDefaultRemediationFunction(templateRule.getDefaultRemediationFunction())
+ .setDefaultRemediationCoefficient(templateRule.getDefaultRemediationCoefficient())
+ .setDefaultRemediationOffset(templateRule.getDefaultRemediationOffset())
.setCreatedAt(new Date(system.now()))
.setUpdatedAt(new Date(system.now()));
ruleDao.insert(rule, session);
}
// New sub characteristic is not equals to existing one -> update it
+ // TODO check characteristic is not equals to default one, if so do nothing
if (!subCharacteristic.getId().equals(ruleDto.getSubCharacteristicId())) {
ruleDto.setSubCharacteristicId(subCharacteristic.getId());
updated = true;
}
// New remediation function is not equals to existing one -> update it
+ // TODO check remediaiton function is not equals to default one, if so do nothing
if (!isSameRemediationFunction(ruleChange.debtRemediationFunction(), ruleChange.debtRemediationCoefficient(), ruleChange.debtRemediationOffset(), ruleDto)) {
DefaultDebtRemediationFunction debtRemediationFunction = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.valueOf(ruleChange.debtRemediationFunction()),
ruleChange.debtRemediationCoefficient(), ruleChange.debtRemediationOffset());
@Test
public void create_custom_rule() throws Exception {
- RuleDto templateRule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle").setConfigKey("Xpath");
+ RuleDto templateRule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle").setConfigKey("Xpath")
+ .setDefaultSubCharacteristicId(20).setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationCoefficient("2h").setDefaultRemediationOffset("15min");
when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10")));
when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM)));
assertThat(ruleArgument.getValue().getRuleKey()).startsWith("AvoidCycle");
assertThat(ruleArgument.getValue().getStatus()).isEqualTo("READY");
assertThat(ruleArgument.getValue().getCardinality()).isEqualTo(Cardinality.SINGLE);
+ assertThat(ruleArgument.getValue().getDefaultSubCharacteristicId()).isEqualTo(20);
+ assertThat(ruleArgument.getValue().getDefaultRemediationFunction()).isEqualTo("LINEAR_OFFSET");
+ assertThat(ruleArgument.getValue().getDefaultRemediationCoefficient()).isEqualTo("2h");
+ assertThat(ruleArgument.getValue().getDefaultRemediationOffset()).isEqualTo("15min");
ArgumentCaptor<RuleParamDto> ruleParamArgument = ArgumentCaptor.forClass(RuleParamDto.class);
verify(ruleDao).insert(ruleParamArgument.capture(), eq(session));