XacmlRest { public static void dumpRequest(HttpServletRequest request) { if (!logger.isDebugEnabled()) { return; } if ("GET".equals(request.getMethod()) && "hb".equals(request.getParameter("type"))) { PolicyLogger.debug("GET type=hb : heartbeat received"); return; } dumpRequestHeadersAttributesContextPath(request); dumpRequestBody(request); } private  XacmlRest(); static void xacmlInit(ServletConfig config); static void loadXacmlProperties(Properties policyProperties, Properties pipProperties); static void dumpRequest(HttpServletRequest request);  }
@Test public void testDumpRequest() throws IOException { XacmlRest.xacmlInit(servletConfig); Logger.getRootLogger().setLevel(Level.INFO); XacmlRest.dumpRequest(httpServletRequest); Logger.getRootLogger().setLevel(Level.DEBUG); Mockito.when(httpServletRequest.getMethod()).thenReturn("GET"); XacmlRest.dumpRequest(httpServletRequest); Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb"); XacmlRest.dumpRequest(httpServletRequest); Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); List<String> headerNameList = new ArrayList<String>() { private static final long serialVersionUID = 1L; { add("Name0"); add("Name1"); } }; List<String> header0List = new ArrayList<String>() { private static final long serialVersionUID = 1L; { add("Name0H0"); add("Name0H1"); add("Name0H2"); } }; List<String> header1List = new ArrayList<String>() { private static final long serialVersionUID = 1L; { add("Name1H0"); add("Name1H1"); add("Name1H2"); } }; Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headerNameList)); Mockito.when(httpServletRequest.getHeaders("Name0")).thenReturn(Collections.enumeration(header0List)); Mockito.when(httpServletRequest.getHeaders("Name1")).thenReturn(Collections.enumeration(header1List)); XacmlRest.dumpRequest(httpServletRequest); List<String> attributeList = new ArrayList<String>() { private static final long serialVersionUID = 1L; { add("Attribute0"); add("Attribute1"); } }; Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(attributeList)); Mockito.when(httpServletRequest.getAttribute("Attribute0")).thenReturn("AttributeValue0"); Mockito.when(httpServletRequest.getAttribute("Attribute1")).thenReturn("AttributeValue1"); XacmlRest.dumpRequest(httpServletRequest); Mockito.when(httpServletRequest.getInputStream()).thenReturn(servletInputStream); XacmlRest.dumpRequest(httpServletRequest); Mockito.when(httpServletRequest.getInputStream()).thenThrow(new IOException()); XacmlRest.dumpRequest(httpServletRequest); Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); XacmlRest.dumpRequest(httpServletRequest); Map<String, String[]> parameterMap = new LinkedHashMap<>(); String[] mapValue0 = { "MapValue0" }; String[] mapValue1 = { "MapValue0" }; String[] mapValue2 = {}; parameterMap.put("Key0", mapValue0); parameterMap.put("Key1", mapValue1); parameterMap.put("Key2", mapValue2); Mockito.when(httpServletRequest.getMethod()).thenReturn("DELETE"); Mockito.when(httpServletRequest.getParameterMap()).thenReturn(parameterMap); XacmlRest.dumpRequest(httpServletRequest); Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); }