@Test public void executeTest() throws Exception { mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(), anyString(),anyString())).thenReturn( true); when(PacmanUtils.formatUrl(anyObject(),anyString())).thenReturn("host"); when(PacmanUtils.getUnownedAdGroup(anyString(), anyString())).thenReturn( true); assertThat(unownedAdGroupsRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); when(PacmanUtils.getUnownedAdGroup(anyString(), anyString())).thenReturn( false); assertThat(unownedAdGroupsRule.execute(CommonTestUtils.getMapString("r_123"),CommonTestUtils.getMapString("r_123")), is(notNullValue())); when(PacmanUtils.getUnownedAdGroup(anyString(),anyString())).thenThrow(new Exception()); assertThatThrownBy( () -> unownedAdGroupsRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(RuleExecutionFailedExeption.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> unownedAdGroupsRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); }
@Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========UnownedAdGroupsRule started========="); Annotation annotation = null; String resourceId = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String adGroupEsURL = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_ADGROUP_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ adGroupEsURL = formattedUrl; } MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(severity, category, adGroupEsURL)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isUnownedAdGroup = false; try { isUnownedAdGroup = PacmanUtils.getUnownedAdGroup(resourceId, adGroupEsURL); } catch (Exception e) { logger.error("unable to determine" , e); throw new RuleExecutionFailedExeption("unable to determine" + e); } if (isUnownedAdGroup) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Unowned Ad group found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "AD group doesn't manged by any group or it has svc_adds_unowned value!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========UnownedAdGroupsRule ended with annotation : {}=========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========UnownedAdGroupsRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }
UnownedAdGroupsRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========UnownedAdGroupsRule started========="); Annotation annotation = null; String resourceId = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String adGroupEsURL = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_ADGROUP_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ adGroupEsURL = formattedUrl; } MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(severity, category, adGroupEsURL)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isUnownedAdGroup = false; try { isUnownedAdGroup = PacmanUtils.getUnownedAdGroup(resourceId, adGroupEsURL); } catch (Exception e) { logger.error("unable to determine" , e); throw new RuleExecutionFailedExeption("unable to determine" + e); } if (isUnownedAdGroup) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Unowned Ad group found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "AD group doesn't manged by any group or it has svc_adds_unowned value!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========UnownedAdGroupsRule ended with annotation : {}=========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========UnownedAdGroupsRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); } }
UnownedAdGroupsRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========UnownedAdGroupsRule started========="); Annotation annotation = null; String resourceId = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String adGroupEsURL = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_ADGROUP_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ adGroupEsURL = formattedUrl; } MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(severity, category, adGroupEsURL)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isUnownedAdGroup = false; try { isUnownedAdGroup = PacmanUtils.getUnownedAdGroup(resourceId, adGroupEsURL); } catch (Exception e) { logger.error("unable to determine" , e); throw new RuleExecutionFailedExeption("unable to determine" + e); } if (isUnownedAdGroup) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Unowned Ad group found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "AD group doesn't manged by any group or it has svc_adds_unowned value!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========UnownedAdGroupsRule ended with annotation : {}=========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========UnownedAdGroupsRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  }
UnownedAdGroupsRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========UnownedAdGroupsRule started========="); Annotation annotation = null; String resourceId = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String adGroupEsURL = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_ADGROUP_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ adGroupEsURL = formattedUrl; } MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(severity, category, adGroupEsURL)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isUnownedAdGroup = false; try { isUnownedAdGroup = PacmanUtils.getUnownedAdGroup(resourceId, adGroupEsURL); } catch (Exception e) { logger.error("unable to determine" , e); throw new RuleExecutionFailedExeption("unable to determine" + e); } if (isUnownedAdGroup) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Unowned Ad group found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "AD group doesn't manged by any group or it has svc_adds_unowned value!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========UnownedAdGroupsRule ended with annotation : {}=========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========UnownedAdGroupsRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  @Override RuleResult execute(Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); @Override String getHelpText(); }
UnownedAdGroupsRule extends BaseRule { @Override public RuleResult execute(Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========UnownedAdGroupsRule started========="); Annotation annotation = null; String resourceId = null; String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); String adGroupEsURL = null; String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_ADGROUP_URL); if(!StringUtils.isNullOrEmpty(formattedUrl)){ adGroupEsURL = formattedUrl; } MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(severity, category, adGroupEsURL)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } if (resourceAttributes != null) { resourceId = StringUtils.trim(resourceAttributes .get(PacmanSdkConstants.RESOURCE_ID)); Boolean isUnownedAdGroup = false; try { isUnownedAdGroup = PacmanUtils.getUnownedAdGroup(resourceId, adGroupEsURL); } catch (Exception e) { logger.error("unable to determine" , e); throw new RuleExecutionFailedExeption("unable to determine" + e); } if (isUnownedAdGroup) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Unowned Ad group found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "AD group doesn't manged by any group or it has svc_adds_unowned value!!"); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug( "========UnownedAdGroupsRule ended with annotation : {}=========", annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } } logger.debug("========UnownedAdGroupsRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  @Override RuleResult execute(Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); @Override String getHelpText();  }