PDPServices { public Collection<PDPResponse> generateRequest(String reqStr, UUID requestId, boolean unique, boolean decide) throws PolicyException { this.unique = unique; this.decide = decide; Collection<PDPResponse> results = null; Response response = null; try { Request request = null; if (DECISION_RAW_XACML_JSON_TYPE.equals(requestFormat)) { request = JSONRequest.load(reqStr); LOGGER.info("--- Generating Request: ---" + requestId + "\n" + JSONRequest.toString(request)); } else { request = DOMRequest.load(reqStr); LOGGER.info("--- Generating Request: ---" + requestId + "\n" + reqStr); } response = callPdp(request, requestId); if (response == null) { response = callPdp(request, requestId); } } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e); PDPResponse pdpResponse = new PDPResponse(); results = new HashSet<>(); pdpResponse.setPolicyConfigMessage("Unable to Call PDP. Error with the URL"); pdpResponse.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_NOT_FOUND); pdpResponse.setPolicyResponseStatus(PolicyResponseStatus.NO_ACTION_REQUIRED); results.add(pdpResponse); throw new PolicyException(e); } if (response != null) { results = checkResponse(response); if (policyList != null) { for (String policy : policyList) { XACMLPdpServlet.monitor.policyCountAdd(policy, 1); } } } else { LOGGER.info("No Response Received from PDP"); PDPResponse pdpResponse = new PDPResponse(); results = new HashSet<>(); pdpResponse.setPolicyConfigMessage("No Response Received"); pdpResponse.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_NOT_FOUND); pdpResponse.setPolicyResponseStatus(PolicyResponseStatus.NO_ACTION_REQUIRED); results.add(pdpResponse); } return results; }  Collection<PDPResponse> generateRequest(String reqStr, UUID requestId, boolean unique, boolean decide); Response callPdp(Request request, UUID requestIdParam); String getRequestType(); void setRequestType(String requestType); String getRequestFormat(); void setRequestFormat(String requestMode); static final String RAINYDAY_TYPE; static final String DECISION_MS_NAMING_TYPE; static final String DECISION_RAW_XACML; static final String DECISION_RAW_XACML_TYPE; static final String DECISION_RAW_XACML_XML_TYPE; static final String DECISION_RAW_XACML_JSON_TYPE; }
@Test public void testGenerateRequest_1() throws Exception { DecisionRequestParameters pep = new DecisionRequestParameters(); Map<String, String> eventAttributes = new HashMap<>(); eventAttributes.put("TEST", "test"); pep.setOnapName("te123"); pep.setDecisionAttributes(eventAttributes); PDPServices fixture = new PDPServices(); String jsonString = getModel(pep).toString(); UUID requestID = UUID.randomUUID(); Collection<PDPResponse> result = fixture.generateRequest(jsonString, requestID, false, true); assertNotNull(result); }
@Test(expected = org.onap.policy.api.PolicyException.class) public void testGenerateRequest_2() throws Exception { PDPServices fixture = new PDPServices(); fixture.generateRequest("", UUID.randomUUID(), true, true); String jsonString = ""; UUID requestID = UUID.randomUUID(); boolean unique = true; boolean decide = true; Collection<PDPResponse> result = fixture.generateRequest(jsonString, requestID, unique, decide); assertNotNull(result); }