@Test public void getBody() throws Exception { byte[] content = "Hello World".getBytes("UTF-8"); mockRequest.setContent(content); byte[] result = FileCopyUtils.copyToByteArray(request.getBody()); assertArrayEquals("Invalid content returned", content, result); }
@Test public void getURI() throws Exception { URI uri = new URI("http://example.com/path?query"); mockRequest.setServerName(uri.getHost()); mockRequest.setServerPort(uri.getPort()); mockRequest.setRequestURI(uri.getPath()); mockRequest.setQueryString(uri.getQuery()); assertEquals("Invalid uri", uri, request.getURI()); }
@Test public void getHeaders() throws Exception { String headerName = "MyHeader"; String headerValue1 = "value1"; mockRequest.addHeader(headerName, headerValue1); String headerValue2 = "value2"; mockRequest.addHeader(headerName, headerValue2); HttpHeaders headers = request.getHeaders(); assertNotNull("No HttpHeaders returned", headers); assertTrue("Invalid headers returned", headers.containsKey(headerName)); List<String> headerValues = headers.get(headerName); assertEquals("Invalid header values returned", 2, headerValues.size()); assertTrue("Invalid header values returned", headerValues.contains(headerValue1)); assertTrue("Invalid header values returned", headerValues.contains(headerValue2)); }
@Test public void getMethod() throws Exception { mockRequest.setMethod("POST"); assertEquals("Invalid method", HttpMethod.POST, request.getMethod()); }