HttpResponseTransformer { public WilmaHttpResponse transformResponse(final BrowserMobHttpResponse response) { boolean isResponseVolatile = response.isResponseVolatile(); WilmaHttpResponse result = responseFactory.createNewWilmaHttpResponse(isResponseVolatile); if (response.getRawResponse() != null) { for (Header header : response.getRawResponse().getAllHeaders()) { result.addHeader(header.getName(), header.getValue()); } } for (Header header : response.getRequestHeaders()) { result.addRequestHeader(header.getName(), header.getValue()); } result.setRequestLine(response.getMethod().getRequestLine().toString()); result.setProxyRequestLine(response.getProxyRequestURI().toString()); String body = response.getBody(); int status = response.getStatus(); result.setBody(body); result.setContentType(response.getContentType()); result.setStatusCode(status); String instancePrefix = prepareInstancePrefix(); result.setWilmaMessageId(instancePrefix + response.getEntry().getWilmaEntryId()); String ipAddress = response.getEntry().getServerIPAddress(); result.setRemoteAddr(ipAddress); return result; }  WilmaHttpResponse transformResponse(final BrowserMobHttpResponse response);  }
@Test public void testTransformShouldSetRequestHeader() { setMocksForMessageContent(); setMocksForMessageConfiguration(); underTest.transformResponse(browserMobHttpResponse); verify(response).addRequestHeader("reqName", "reqValue"); }
@Test public void testTransformShouldSetResponseHeader() { setMocksForMessageContent(); setMocksForMessageConfiguration(); underTest.transformResponse(browserMobHttpResponse); verify(response).addHeader("respName", "respValue"); }
@Test public void testTransformShouldSetResponseWilmaMessageId() { setMocksForMessageContent(); setMocksForMessageConfiguration(); given(browserMobHttpResponse.getEntry().getWilmaEntryId()).willReturn(PREFIX); underTest.transformResponse(browserMobHttpResponse); verify(response).setWilmaMessageId(PREFIX + "_" + PREFIX); }
@Test public void testTransformShouldNotSetResponseHeaderWhenRawResponseIsNull() { setMocksForMessageContent(); given(browserMobHttpResponse.getRawResponse()).willReturn(null); setMocksForMessageConfiguration(); underTest.transformResponse(browserMobHttpResponse); verify(response, never()).addHeader("respName", "respValue"); }
@Test public void testTransformShouldSetBody() { setMocksForMessageContent(); setMocksForMessageConfiguration(); underTest.transformResponse(browserMobHttpResponse); verify(response).setBody(RESPONSE_BODY); }
@Test public void testTransformShouldSetContentType() { setMocksForMessageContent(); setMocksForMessageConfiguration(); given(browserMobHttpResponse.getContentType()).willReturn(CONTENT_TYPE); underTest.transformResponse(browserMobHttpResponse); verify(response).setContentType(CONTENT_TYPE); }
@Test public void testTransformShouldSetStatusCode() { setMocksForMessageContent(); setMocksForMessageConfiguration(); underTest.transformResponse(browserMobHttpResponse); verify(response).setStatusCode(200); }
@Test public void testTransformShouldSetRequestLineAndProxyRequestLine() { setMocksForMessageContent(); setMocksForMessageConfiguration(); given(browserMobHttpResponse.getMethod().getRequestLine().toString()).willReturn(REQUEST_LINE); given(browserMobHttpResponse.getProxyRequestURI().toString()).willReturn(REQUEST_PROXY_LINE); underTest.transformResponse(browserMobHttpResponse); verify(response).setRequestLine(REQUEST_LINE); verify(response).setProxyRequestLine(REQUEST_PROXY_LINE); }