@Test public void getBodyTest() throws IOException { TeeHttpServletRequest tee = new TeeHttpServletRequest(request); // Map content types to whether they should be logged as text or base64 encoded Map<String, Boolean> types = new HashMap<String, Boolean>(); types.put(MediaType.APPLICATION_JSON, true); types.put(MediaType.APPLICATION_ATOM_XML, true); types.put(MediaType.TEXT_PLAIN, true); types.put(MediaType.TEXT_HTML, true); types.put(MediaType.TEXT_XML, true); types.put(MediaType.APPLICATION_FORM_URLENCODED, true); types.put(MediaType.APPLICATION_OCTET_STREAM, false); types.put("multipart/form-data", false); types.put("application/zip", false); for (String type : types.keySet()) { when(request.getContentType()).thenReturn(type); if (types.get(type)) { assertEquals(type + " failed!", "this is my body", tee.getBody()); } else { assertEquals(type + " failed!", Util.toBase64("this is my body".getBytes()), tee.getBody()); } } }
@Test public void testCtor() throws IOException { TeeHttpServletRequest tee = new TeeHttpServletRequest(request); assertNotNull(tee); assertNotNull(tee.getInputStream()); assertEquals("this is my body", readData(tee.getInputStream())); assertEquals("this is my body", readData(tee.getReader())); }