HttpRequestTransformer { public WilmaHttpRequest transformRequest(final BrowserMobHttpRequest browserMobHttpRequest) throws ApplicationException { WilmaHttpRequest result = requestFactory.createNewWilmaHttpRequest(); HttpRequestBase requestBase = browserMobHttpRequest.getMethod(); result.setRequestLine(requestBase.getRequestLine().toString()); for (Header header : requestBase.getAllHeaders()) { result.addHeader(header.getName(), header.getValue()); } InputStream clonedInputStream = browserMobHttpRequest.getPlayGround(); result.setInputStream(clonedInputStream); result.setBody(inputStreamConverter.getStringFromStream(clonedInputStream)); result.setUri(requestBase.getURI()); result.setResponseVolatile(browserMobHttpRequest.getResponseVolatile()); MessagePropertyDTO properties = configurationAccess.getProperties(); String instancePrefix = properties.getInstancePrefix(); if (instancePrefix != null) { instancePrefix += "_"; } else { instancePrefix = ""; } result.setWilmaMessageId(instancePrefix + browserMobHttpRequest.getWilmaMessageId()); String ipAddress = browserMobHttpRequest.getProxyRequest().getRemoteAddr(); result.setRemoteAddr(ipAddress); return result; }  WilmaHttpRequest transformRequest(final BrowserMobHttpRequest browserMobHttpRequest);  }
@Test public void testTransformRequestShouldAddHeaders() throws ApplicationException { setMocksForHeader(); setMocksForMessageConfiguration(); WilmaHttpRequest actual = underTest.transformRequest(browserMobHttpRequest); verify(wilmaHttpRequest).addHeader(Mockito.anyString(), Mockito.anyString()); assertEquals(actual.getRequestLine(), wilmaHttpRequest.getRequestLine()); assertEquals(actual.getHeader("header"), wilmaHttpRequest.getHeader("header")); }
@Test public void testTransformRequestShouldSetWilmaMessageId() throws ApplicationException { setMocksForHeader(); setMocksForMessageConfiguration(); given(browserMobHttpRequest.getWilmaMessageId()).willReturn(PREFIX); WilmaHttpRequest actual = underTest.transformRequest(browserMobHttpRequest); verify(wilmaHttpRequest).setWilmaMessageId(PREFIX + "_" + PREFIX); }
@Test public void testTransformRequestShouldSetBody() throws ApplicationException { setMocksForHeader(); setMocksForMessageConfiguration(); String body = setMocksForBody(); WilmaHttpRequest actual = underTest.transformRequest(browserMobHttpRequest); verify(wilmaHttpRequest).setBody(body); assertEquals(actual.getBody(), wilmaHttpRequest.getBody()); }
@Test public void testTransformRequestShouldSetInputStream() throws ApplicationException { setMocksForHeader(); setMocksForMessageConfiguration(); setMocksForBody(); given(wilmaHttpRequest.getInputStream()).willReturn(clonedInputStream); WilmaHttpRequest actual = underTest.transformRequest(browserMobHttpRequest); verify(wilmaHttpRequest).setInputStream(clonedInputStream); assertEquals(actual.getInputStream(), clonedInputStream); }