@Test public void testGetCharsetNoContentType() throws URISyntaxException { Multimap<String, String> headers = LinkedHashMultimap.create(); RecordedHttpRequest recordedHttpRequest = new RecordedHttpRequest("GET", new URI("google.com"), headers, null); Assert.assertEquals(recordedHttpRequest.getCharset(), Charsets.UTF_8.toString()); }
@Test public void testGetCharset() throws URISyntaxException { Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put(HttpHeaders.CONTENT_TYPE, "text/html; charset=iso-8859-9"); RecordedHttpRequest recordedHttpRequest = new RecordedHttpRequest("GET", new URI("google.com"), headers, null); Assert.assertEquals(recordedHttpRequest.getCharset(), Charset.forName("iso-8859-9").toString()); }
@Override public boolean test(RecordedHttpRequest incomingRequest, RecordedHttpRequest expectedRequest) { String charSet1 = incomingRequest.getCharset(); String charSet2 = expectedRequest.getCharset(); RecordedHttpBody incomingBody = incomingRequest.getHttpBody(); if (incomingBody == null) { incomingBody = new RecordedByteHttpBody(new byte[0]); } RecordedHttpBody expectedBody = expectedRequest.getHttpBody(); if (expectedBody == null) { expectedBody = new RecordedByteHttpBody(new byte[0]); } try { return Arrays.equals(incomingBody.getContent(charSet1), expectedBody.getContent(charSet2)); } catch (IOException e) { //TODO: PLACEHOLDER, error handling will be in separate RB. throw new RuntimeException("Failed to convert to byte arrays", e); } }
@Override public boolean test(RecordedHttpRequest incomingRequest, RecordedHttpRequest expectedRequest) { String charSet1 = incomingRequest.getCharset(); String charSet2 = expectedRequest.getCharset(); RecordedHttpBody incomingBody = incomingRequest.getHttpBody(); if (incomingBody == null) {
private Map<String, String> getPostParametersFromRequest(RecordedHttpRequest request) throws UnsupportedEncodingException { RecordedHttpBody body = request.getHttpBody(); if (body instanceof RecordedEncodedHttpBody) { body = ((RecordedEncodedHttpBody) body).getDecodedBody(); } assert (body instanceof RecordedStringHttpBody); String content = ((RecordedStringHttpBody) body).getContent(); return HttpUtilities.stringToUrlParams(content, request.getCharset()); }