JWSHttpServletRequestWrapper extends SecurityContextHolderAwareRequestWrapper { @Override public ServletInputStream getInputStream() throws IOException { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes()); ServletInputStream inputStream = new ServletInputStream() { @Override public int read() throws IOException { return byteArrayInputStream.read(); } }; return inputStream; } JWSHttpServletRequestWrapper(final HttpServletRequest request, final String rolePrefix); @Override ServletInputStream getInputStream();  }
@Test public void testWrapperException() throws Exception{ when(request.getInputStream()).thenThrow(IOException.class); JWSHttpServletRequestWrapper jwsHttpServletRequestWrapper = new JWSHttpServletRequestWrapper(request, null); InputStream is = jwsHttpServletRequestWrapper.getInputStream(); Assert.assertTrue("Empty stream",is.read()<0); }
@Test public void testWrapperObtainContent() throws Exception{ ServletInputStream sis = new DelegatingServletInputStream(new ByteArrayInputStream( TEST_CONTENT.getBytes())); when(request.getInputStream()).thenReturn(sis); JWSHttpServletRequestWrapper jwsHttpServletRequestWrapper = new JWSHttpServletRequestWrapper(request, null); InputStream is = jwsHttpServletRequestWrapper.getInputStream(); String obtainedContent = obtainContent(is); Assert.assertNotNull("content should be not be null",obtainedContent); Assert.assertEquals("content should be the same",TEST_CONTENT,obtainedContent); }