@Test public void updateRuleTest() throws Exception { Optional<Rule> rule = getRuleDetailsResponse(); when(ruleRepository.findById(anyString())).thenReturn(rule); MultipartFile firstFile = getMockMultipartFile(); Map<String, Object> ruleParamDetails = Maps.newHashMap(); List<Map<String, Object>> params = Lists.newArrayList(); Map<String, Object> param = Maps.newHashMap(); param.put("name", "name123"); param.put("value", "name123"); param.put("encrypt", true); params.add(param); param = Maps.newHashMap(); param.put("name", "name123"); param.put("value", "name123"); param.put("encrypt", false); param.put("isValueNew", true); params.add(param); ruleParamDetails.put("environmentVariables", params); ruleParamDetails.put("params", params); RuleProperty ruleProperty = buildRuleProperty(); when(config.getRule()).thenReturn(ruleProperty); when(ruleRepository.findByRuleId(anyString())).thenReturn(rule.get()); when(ruleRepository.save(rule.get())).thenReturn(rule.get()); when(mapper.readValue(anyString(), any(TypeReference.class))).thenReturn(ruleParamDetails); when(mapper.writeValueAsString(any())).thenReturn("[]"); assertThat(ruleService.updateRule(firstFile, getCreateUpdateRuleDetailsRequest(), "userId123"), is(String.format(AdminConstants.RULE_CREATION_SUCCESS))); }
@Override public String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId) throws PacManException { checkRuleTypeNotServerlessOrManaged(updateRuleDetails, fileToUpload); return updateRuleInstance(fileToUpload, updateRuleDetails, userId); }
RuleServiceImpl implements RuleService { @Override public String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId) throws PacManException { checkRuleTypeNotServerlessOrManaged(updateRuleDetails, fileToUpload); return updateRuleInstance(fileToUpload, updateRuleDetails, userId); } }
RuleServiceImpl implements RuleService { @Override public String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId) throws PacManException { checkRuleTypeNotServerlessOrManaged(updateRuleDetails, fileToUpload); return updateRuleInstance(fileToUpload, updateRuleDetails, userId); }  }
RuleServiceImpl implements RuleService { @Override public String updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId) throws PacManException { checkRuleTypeNotServerlessOrManaged(updateRuleDetails, fileToUpload); return updateRuleInstance(fileToUpload, updateRuleDetails, userId); }  @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 updateRule(MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails, String userId) throws PacManException { checkRuleTypeNotServerlessOrManaged(updateRuleDetails, fileToUpload); return updateRuleInstance(fileToUpload, updateRuleDetails, userId); }  @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();  }