Skip to content

Commit

Permalink
Add missing UT
Browse files Browse the repository at this point in the history
  • Loading branch information
julienlancelot committed Mar 23, 2016
1 parent d9bfbf8 commit 8e04802
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 60 deletions.
Expand Up @@ -116,15 +116,6 @@ public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(final DbSession dbSe
return DatabaseUtils.executeLargeInputs(activeRuleIds, new ParamIdToDto(mapper(dbSession))); return DatabaseUtils.executeLargeInputs(activeRuleIds, new ParamIdToDto(mapper(dbSession)));
} }


/**
* Warning ! This method is executing 2 queries : one to get the active rule from the key, and another one to get parameters
*/
private List<ActiveRuleParamDto> selectParamsByActiveRuleKey(DbSession session, ActiveRuleKey key) {
Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL);
ActiveRuleDto activeRule = selectOrFailByKey(session, key);
return mapper(session).selectParamsByActiveRuleId(activeRule.getId());
}

@CheckForNull @CheckForNull
public ActiveRuleParamDto selectParamByKeyAndName(ActiveRuleKey key, String name, DbSession session) { public ActiveRuleParamDto selectParamByKeyAndName(ActiveRuleKey key, String name, DbSession session) {
Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL); Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL);
Expand All @@ -150,17 +141,6 @@ public ActiveRuleParamDto insertParam(DbSession session, ActiveRuleDto activeRul
return activeRuleParam; return activeRuleParam;
} }


public void deleteParamByKeyAndName(DbSession session, ActiveRuleKey key, String param) {
// TODO SQL rewrite to delete by key
Optional<ActiveRuleDto> activeRule = selectByKey(session, key);
if (activeRule.isPresent()) {
ActiveRuleParamDto activeRuleParam = mapper(session).selectParamByActiveRuleAndKey(activeRule.get().getId(), param);
if (activeRuleParam != null) {
mapper(session).deleteParameter(activeRuleParam.getId());
}
}
}

public void updateParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { public void updateParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) {
Preconditions.checkNotNull(activeRule.getId(), ACTIVE_RULE_IS_NOT_PERSISTED); Preconditions.checkNotNull(activeRule.getId(), ACTIVE_RULE_IS_NOT_PERSISTED);
Preconditions.checkNotNull(activeRuleParam.getId(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED); Preconditions.checkNotNull(activeRuleParam.getId(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED);
Expand All @@ -173,10 +153,21 @@ public void deleteParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleP
mapper(session).deleteParameter(activeRuleParam.getId()); mapper(session).deleteParameter(activeRuleParam.getId());
} }


public void deleteParamByKeyAndName(DbSession session, ActiveRuleKey key, String param) {
// TODO SQL rewrite to delete by key
Optional<ActiveRuleDto> activeRule = selectByKey(session, key);
if (activeRule.isPresent()) {
ActiveRuleParamDto activeRuleParam = mapper(session).selectParamByActiveRuleAndKey(activeRule.get().getId(), param);
if (activeRuleParam != null) {
mapper(session).deleteParameter(activeRuleParam.getId());
}
}
}

public void deleteParamsByRuleParam(DbSession dbSession, RuleDto rule, String paramKey) { public void deleteParamsByRuleParam(DbSession dbSession, RuleDto rule, String paramKey) {
List<ActiveRuleDto> activeRules = selectByRule(dbSession, rule); List<ActiveRuleDto> activeRules = selectByRule(dbSession, rule);
for (ActiveRuleDto activeRule : activeRules) { for (ActiveRuleDto activeRule : activeRules) {
for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleKey(dbSession, activeRule.getKey())) { for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
if (activeParam.getKey().equals(paramKey)) { if (activeParam.getKey().equals(paramKey)) {
deleteParam(dbSession, activeRule, activeParam); deleteParam(dbSession, activeRule, activeParam);
} }
Expand Down
Expand Up @@ -28,8 +28,6 @@


<update id="update" parameterType="ActiveRule"> <update id="update" parameterType="ActiveRule">
UPDATE active_rules SET UPDATE active_rules SET
profile_id=#{profileId},
rule_id=#{ruleId},
failure_level=#{severity}, failure_level=#{severity},
inheritance=#{inheritance}, inheritance=#{inheritance},
updated_at=#{updatedAt} updated_at=#{updatedAt}
Expand Down Expand Up @@ -118,9 +116,6 @@


<update id="updateParameter" parameterType="ActiveRuleParam"> <update id="updateParameter" parameterType="ActiveRuleParam">
UPDATE active_rule_parameters SET UPDATE active_rule_parameters SET
active_rule_id=#{activeRuleId},
rules_parameter_id=#{rulesParameterId},
rules_parameter_key=#{key},
value=#{value} value=#{value}
WHERE id=#{id} WHERE id=#{id}
</update> </update>
Expand Down

0 comments on commit 8e04802

Please sign in to comment.