@Test public void testDecisionGuardParameterHandling() throws Exception { PolicyParameters parameters = createParametersObject(); parameters.setPolicyClass(PolicyClass.Decision); PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper(); assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters)) .isInstanceOf(NullPointerException.class); Map<AttributeType, Map<String, String>> attributes = new LinkedHashMap<>(); parameters.setAttributes(attributes); assertThatThrownBy(() -> wrapper.populateRequestParameters(parameters)) .isInstanceOf(NullPointerException.class); parameters.setRuleProvider(RuleProvider.GUARD_BL_YAML); PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters)); assertEquals("GUARD_BL_YAML", adapter.getRuleProvider()); parameters.setRuleProvider(RuleProvider.GUARD_MIN_MAX); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("GUARD_MIN_MAX", adapter.getRuleProvider()); parameters.setRuleProvider(RuleProvider.GUARD_YAML); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("GUARD_YAML", adapter.getRuleProvider()); Map<String, String> matchingMap = new LinkedHashMap<>(); matchingMap.put("actor", "Actor"); matchingMap.put("recipe", "Recipe"); matchingMap.put("guardActiveStart", "GuardActiveStart"); matchingMap.put("guardActiveEnd", "GuardActiveEnd"); matchingMap.put("limit", "Limit"); matchingMap.put("timeWindow", "Window"); matchingMap.put("timeUnits", "Units"); attributes.put(AttributeType.MATCHING, matchingMap); parameters.setAttributes(attributes); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("Actor", adapter.getYamlparams().getActor()); assertEquals("Recipe", adapter.getYamlparams().getRecipe()); assertEquals("GuardActiveStart", adapter.getYamlparams().getGuardActiveStart()); assertEquals("GuardActiveEnd", adapter.getYamlparams().getGuardActiveEnd()); assertEquals("Limit", adapter.getYamlparams().getLimit()); assertEquals("Window", adapter.getYamlparams().getTimeWindow()); assertEquals("Units", adapter.getYamlparams().getTimeUnits()); parameters.setRuleProvider(RuleProvider.GUARD_MIN_MAX); matchingMap.put("min", "TheMin"); matchingMap.put("max", "TheMax"); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("TheMin", adapter.getYamlparams().getMin()); assertEquals("TheMax", adapter.getYamlparams().getMax()); parameters.setRuleProvider(RuleProvider.GUARD_BL_YAML); adapter = wrapper.populateRequestParameters((parameters)); assertTrue(adapter.getYamlparams().getBlackList().isEmpty()); matchingMap.put("blackList", "Bad0,Bad1"); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("Bad0", adapter.getYamlparams().getBlackList().get(0)); assertEquals("Bad1", adapter.getYamlparams().getBlackList().get(1)); parameters.setRuleProvider(RuleProvider.AAF); adapter = wrapper.populateRequestParameters((parameters)); assertNull(adapter.getYamlparams()); }
public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; } }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  PolicyRestAdapter populateRequestParameters(HttpServletRequest request); PolicyRestAdapter populateRequestParameters(PolicyParameters parameters); }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  PolicyRestAdapter populateRequestParameters(HttpServletRequest request); PolicyRestAdapter populateRequestParameters(PolicyParameters parameters);  }