@SuppressWarnings("unchecked") @Test public void enableDisableRuleCreatePolicyForLambdaExceptionTest() throws Exception { String action = "enable"; Optional<Rule> rule = getRuleDetailsResponse(); mockStatic(RuleState.class); when(ruleRepository.findById(anyString())).thenReturn(rule); when(putRuleRequest.withName(anyString()).withDescription(anyString()).withState(anyString())).thenReturn(putRuleRequest); when(amazonClient.getAWSLambdaClient(anyString())).thenThrow(Exception.class); RuleProperty ruleProperty = buildRuleProperty(); when(config.getRule()).thenReturn(ruleProperty); when(ruleRepository.save(rule.get())).thenReturn(rule.get()); assertThatThrownBy(() -> ruleService.enableDisableRule("ruleId123", action, "userId123")).isInstanceOf(PacManException.class); }
@Override public String enableDisableRule(final String ruleId, final String action, final String userId) throws PacManException { if(ruleRepository.existsById(ruleId)) { Rule existingRule = ruleRepository.findById(ruleId).get(); if(action.equalsIgnoreCase("enable")) { return enableCloudWatchRule(existingRule, userId, RuleState.ENABLED); } else { return disableCloudWatchRule(existingRule, userId, RuleState.DISABLED); } } else { throw new PacManException(String.format(AdminConstants.RULE_ID_NOT_EXITS, ruleId)); } }
RuleServiceImpl implements RuleService { @Override public String enableDisableRule(final String ruleId, final String action, final String userId) throws PacManException { if(ruleRepository.existsById(ruleId)) { Rule existingRule = ruleRepository.findById(ruleId).get(); if(action.equalsIgnoreCase("enable")) { return enableCloudWatchRule(existingRule, userId, RuleState.ENABLED); } else { return disableCloudWatchRule(existingRule, userId, RuleState.DISABLED); } } else { throw new PacManException(String.format(AdminConstants.RULE_ID_NOT_EXITS, ruleId)); } } }
RuleServiceImpl implements RuleService { @Override public String enableDisableRule(final String ruleId, final String action, final String userId) throws PacManException { if(ruleRepository.existsById(ruleId)) { Rule existingRule = ruleRepository.findById(ruleId).get(); if(action.equalsIgnoreCase("enable")) { return enableCloudWatchRule(existingRule, userId, RuleState.ENABLED); } else { return disableCloudWatchRule(existingRule, userId, RuleState.DISABLED); } } else { throw new PacManException(String.format(AdminConstants.RULE_ID_NOT_EXITS, ruleId)); } }  }
RuleServiceImpl implements RuleService { @Override public String enableDisableRule(final String ruleId, final String action, final String userId) throws PacManException { if(ruleRepository.existsById(ruleId)) { Rule existingRule = ruleRepository.findById(ruleId).get(); if(action.equalsIgnoreCase("enable")) { return enableCloudWatchRule(existingRule, userId, RuleState.ENABLED); } else { return disableCloudWatchRule(existingRule, userId, RuleState.DISABLED); } } else { throw new PacManException(String.format(AdminConstants.RULE_ID_NOT_EXITS, ruleId)); } }  @Override List<Rule> getAllRulesByTargetType(String targetType); @Override List<RuleProjection> getAllRulesByTargetTypeName(String targetType); @Override List<RuleProjection> getAllRulesByTargetTypeAndNotInRuleIdList(final String targetType, final List<String> ruleIdList); @Override List<RuleProjection> getAllRulesByTargetTypeAndRuleIdList(final String targetType, final List<String> ruleIdList); @Override Rule getByRuleId(String ruleId); @Override Page<Rule> getRules(final String searchTerm, final int page, final int size); @Override Collection<String> getAllAlexaKeywords(); @Override Collection<String> getAllRuleIds(); @Override String createRule(final MultipartFile fileToUpload, final CreateUpdateRuleDetails ruleDetails, final String userId); @Override String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId); @Override String invokeRule(String ruleId, List<Map<String, Object>> ruleOptionalParams); @Override String enableDisableRule(final String ruleId, final String action, final String userId); @Override Map<String, Object> invokeAllRules(List<String> ruleIds); boolean isRuleIdExits(String ruleId); @Override List<RuleCategory> getAllRuleCategories(); }
RuleServiceImpl implements RuleService { @Override public String enableDisableRule(final String ruleId, final String action, final String userId) throws PacManException { if(ruleRepository.existsById(ruleId)) { Rule existingRule = ruleRepository.findById(ruleId).get(); if(action.equalsIgnoreCase("enable")) { return enableCloudWatchRule(existingRule, userId, RuleState.ENABLED); } else { return disableCloudWatchRule(existingRule, userId, RuleState.DISABLED); } } else { throw new PacManException(String.format(AdminConstants.RULE_ID_NOT_EXITS, ruleId)); } }  @Override List<Rule> getAllRulesByTargetType(String targetType); @Override List<RuleProjection> getAllRulesByTargetTypeName(String targetType); @Override List<RuleProjection> getAllRulesByTargetTypeAndNotInRuleIdList(final String targetType, final List<String> ruleIdList); @Override List<RuleProjection> getAllRulesByTargetTypeAndRuleIdList(final String targetType, final List<String> ruleIdList); @Override Rule getByRuleId(String ruleId); @Override Page<Rule> getRules(final String searchTerm, final int page, final int size); @Override Collection<String> getAllAlexaKeywords(); @Override Collection<String> getAllRuleIds(); @Override String createRule(final MultipartFile fileToUpload, final CreateUpdateRuleDetails ruleDetails, final String userId); @Override String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId); @Override String invokeRule(String ruleId, List<Map<String, Object>> ruleOptionalParams); @Override String enableDisableRule(final String ruleId, final String action, final String userId); @Override Map<String, Object> invokeAllRules(List<String> ruleIds); boolean isRuleIdExits(String ruleId); @Override List<RuleCategory> getAllRuleCategories();  }