@Test public void testPushPolicy() throws ServletException, PAPException { PolicyVersion versionData = new PolicyVersion(); versionData.setPolicyName("com" + File.separator + "Config_Test"); versionData.setActiveVersion(1); versionData.setHigherVersion(1); List<Object> data = new ArrayList<>(); data.add(versionData); when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com" + File.separator + "Config_Test")) .thenReturn(data); pap = new XACMLPapServlet(); pap.init(servletConfig); callPushPolicy(); when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com" + File.separator + "Config_Test")) .thenReturn(null); callPushPolicy(); }
@RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) public void pushPolicy(HttpServletRequest request, HttpServletResponse response) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { JsonNode root = mapper.readTree(request.getInputStream()); String policyScope = root.get("policyScope").asText(); String filePrefix = root.get("filePrefix").asText(); String policyName = root.get(policyNames).asText(); String pdpGroup = root.get("pdpGroup").asText(); String requestID = request.getHeader("X-ECOMP-RequestID"); if (requestID == null) { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if (policyVersionObject != null) { PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); String policyID = policyVersionName.replace(File.separator, "."); policyVersionName += "." + policyVersion.getActiveVersion() + ".xml"; addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response); } else { String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownPolicy"); response.addHeader(operation, "push"); response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (NullPointerException | IOException e) { LOGGER.error(e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.addHeader(errorMsg, "unknown"); response.addHeader(operation, "push"); } }
PushPolicyController { @RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) public void pushPolicy(HttpServletRequest request, HttpServletResponse response) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { JsonNode root = mapper.readTree(request.getInputStream()); String policyScope = root.get("policyScope").asText(); String filePrefix = root.get("filePrefix").asText(); String policyName = root.get(policyNames).asText(); String pdpGroup = root.get("pdpGroup").asText(); String requestID = request.getHeader("X-ECOMP-RequestID"); if (requestID == null) { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if (policyVersionObject != null) { PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); String policyID = policyVersionName.replace(File.separator, "."); policyVersionName += "." + policyVersion.getActiveVersion() + ".xml"; addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response); } else { String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownPolicy"); response.addHeader(operation, "push"); response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (NullPointerException | IOException e) { LOGGER.error(e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.addHeader(errorMsg, "unknown"); response.addHeader(operation, "push"); } } }
PushPolicyController { @RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) public void pushPolicy(HttpServletRequest request, HttpServletResponse response) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { JsonNode root = mapper.readTree(request.getInputStream()); String policyScope = root.get("policyScope").asText(); String filePrefix = root.get("filePrefix").asText(); String policyName = root.get(policyNames).asText(); String pdpGroup = root.get("pdpGroup").asText(); String requestID = request.getHeader("X-ECOMP-RequestID"); if (requestID == null) { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if (policyVersionObject != null) { PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); String policyID = policyVersionName.replace(File.separator, "."); policyVersionName += "." + policyVersion.getActiveVersion() + ".xml"; addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response); } else { String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownPolicy"); response.addHeader(operation, "push"); response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (NullPointerException | IOException e) { LOGGER.error(e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.addHeader(errorMsg, "unknown"); response.addHeader(operation, "push"); } } @Autowired  PushPolicyController(CommonClassDao commonClassDao);  PushPolicyController(); }
PushPolicyController { @RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) public void pushPolicy(HttpServletRequest request, HttpServletResponse response) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { JsonNode root = mapper.readTree(request.getInputStream()); String policyScope = root.get("policyScope").asText(); String filePrefix = root.get("filePrefix").asText(); String policyName = root.get(policyNames).asText(); String pdpGroup = root.get("pdpGroup").asText(); String requestID = request.getHeader("X-ECOMP-RequestID"); if (requestID == null) { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if (policyVersionObject != null) { PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); String policyID = policyVersionName.replace(File.separator, "."); policyVersionName += "." + policyVersion.getActiveVersion() + ".xml"; addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response); } else { String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownPolicy"); response.addHeader(operation, "push"); response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (NullPointerException | IOException e) { LOGGER.error(e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.addHeader(errorMsg, "unknown"); response.addHeader(operation, "push"); } } @Autowired  PushPolicyController(CommonClassDao commonClassDao);  PushPolicyController(); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) void pushPolicy(HttpServletRequest request, HttpServletResponse response); }
PushPolicyController { @RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) public void pushPolicy(HttpServletRequest request, HttpServletResponse response) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { JsonNode root = mapper.readTree(request.getInputStream()); String policyScope = root.get("policyScope").asText(); String filePrefix = root.get("filePrefix").asText(); String policyName = root.get(policyNames).asText(); String pdpGroup = root.get("pdpGroup").asText(); String requestID = request.getHeader("X-ECOMP-RequestID"); if (requestID == null) { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if (policyVersionObject != null) { PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); String policyID = policyVersionName.replace(File.separator, "."); policyVersionName += "." + policyVersion.getActiveVersion() + ".xml"; addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response); } else { String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownPolicy"); response.addHeader(operation, "push"); response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (NullPointerException | IOException e) { LOGGER.error(e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.addHeader(errorMsg, "unknown"); response.addHeader(operation, "push"); } } @Autowired  PushPolicyController(CommonClassDao commonClassDao);  PushPolicyController(); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping(value = "/pushPolicy", method = RequestMethod.POST) void pushPolicy(HttpServletRequest request, HttpServletResponse response);  }