@Test public void testUpdateResponseShouldUpdateBodyPart() throws URISyntaxException, IOException { given(browserMobHttpResponse.getRawResponse()).willReturn(httpResponse); given(wilmaHttpResponse.getNewBody()).willReturn("NEW BODY".getBytes()); given(wilmaHttpResponse.isVolatile()).willReturn(true); underTest.updateResponse(browserMobHttpResponse, wilmaHttpResponse); verify(browserMobHttpResponse).setAnswer((byte[]) anyObject()); verify(httpResponse).setEntity((HttpEntity) anyObject()); }
public void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse) { if (!wilmaResponse.isVolatile()) { return; } Map<String, HttpHeaderChange> headerChangeMap = wilmaResponse.getHeaderChanges(); if (headerChangeMap != null && !headerChangeMap.isEmpty()) { for (Map.Entry<String, HttpHeaderChange> headerChangeEntry : headerChangeMap.entrySet()) { String headerKey = headerChangeEntry.getKey(); HttpHeaderChange headerChange = headerChangeEntry.getValue(); Header header = browserMobHttpResponse.getRawResponse().getFirstHeader(headerKey); if (headerChange instanceof HttpHeaderToBeUpdated) { if (header != null) { ((HttpHeaderToBeUpdated) headerChange).setOriginalValue(header.getValue()); } browserMobHttpResponse.getRawResponse().addHeader(headerKey, ((HttpHeaderToBeUpdated) headerChange).getNewValue()); headerChange.setApplied(); } else { if (header != null) { browserMobHttpResponse.getRawResponse().removeHeader(header); headerChange.setApplied(); } } } } byte[] newBody = wilmaResponse.getNewBody(); if (newBody != null) { try { browserMobHttpResponse.setAnswer(newBody); browserMobHttpResponse.getRawResponse().setEntity(new ByteArrayEntity(wilmaResponse.getNewBody())); } catch (IOException e) { logger.warn("Message ont-the-fly update was failed for message: " + wilmaResponse.getWilmaMessageId(), e); } } }
BrowserMobResponseUpdater { public void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse) { if (!wilmaResponse.isVolatile()) { return; } Map<String, HttpHeaderChange> headerChangeMap = wilmaResponse.getHeaderChanges(); if (headerChangeMap != null && !headerChangeMap.isEmpty()) { for (Map.Entry<String, HttpHeaderChange> headerChangeEntry : headerChangeMap.entrySet()) { String headerKey = headerChangeEntry.getKey(); HttpHeaderChange headerChange = headerChangeEntry.getValue(); Header header = browserMobHttpResponse.getRawResponse().getFirstHeader(headerKey); if (headerChange instanceof HttpHeaderToBeUpdated) { if (header != null) { ((HttpHeaderToBeUpdated) headerChange).setOriginalValue(header.getValue()); } browserMobHttpResponse.getRawResponse().addHeader(headerKey, ((HttpHeaderToBeUpdated) headerChange).getNewValue()); headerChange.setApplied(); } else { if (header != null) { browserMobHttpResponse.getRawResponse().removeHeader(header); headerChange.setApplied(); } } } } byte[] newBody = wilmaResponse.getNewBody(); if (newBody != null) { try { browserMobHttpResponse.setAnswer(newBody); browserMobHttpResponse.getRawResponse().setEntity(new ByteArrayEntity(wilmaResponse.getNewBody())); } catch (IOException e) { logger.warn("Message ont-the-fly update was failed for message: " + wilmaResponse.getWilmaMessageId(), e); } } } }
BrowserMobResponseUpdater { public void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse) { if (!wilmaResponse.isVolatile()) { return; } Map<String, HttpHeaderChange> headerChangeMap = wilmaResponse.getHeaderChanges(); if (headerChangeMap != null && !headerChangeMap.isEmpty()) { for (Map.Entry<String, HttpHeaderChange> headerChangeEntry : headerChangeMap.entrySet()) { String headerKey = headerChangeEntry.getKey(); HttpHeaderChange headerChange = headerChangeEntry.getValue(); Header header = browserMobHttpResponse.getRawResponse().getFirstHeader(headerKey); if (headerChange instanceof HttpHeaderToBeUpdated) { if (header != null) { ((HttpHeaderToBeUpdated) headerChange).setOriginalValue(header.getValue()); } browserMobHttpResponse.getRawResponse().addHeader(headerKey, ((HttpHeaderToBeUpdated) headerChange).getNewValue()); headerChange.setApplied(); } else { if (header != null) { browserMobHttpResponse.getRawResponse().removeHeader(header); headerChange.setApplied(); } } } } byte[] newBody = wilmaResponse.getNewBody(); if (newBody != null) { try { browserMobHttpResponse.setAnswer(newBody); browserMobHttpResponse.getRawResponse().setEntity(new ByteArrayEntity(wilmaResponse.getNewBody())); } catch (IOException e) { logger.warn("Message ont-the-fly update was failed for message: " + wilmaResponse.getWilmaMessageId(), e); } } }  }
BrowserMobResponseUpdater { public void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse) { if (!wilmaResponse.isVolatile()) { return; } Map<String, HttpHeaderChange> headerChangeMap = wilmaResponse.getHeaderChanges(); if (headerChangeMap != null && !headerChangeMap.isEmpty()) { for (Map.Entry<String, HttpHeaderChange> headerChangeEntry : headerChangeMap.entrySet()) { String headerKey = headerChangeEntry.getKey(); HttpHeaderChange headerChange = headerChangeEntry.getValue(); Header header = browserMobHttpResponse.getRawResponse().getFirstHeader(headerKey); if (headerChange instanceof HttpHeaderToBeUpdated) { if (header != null) { ((HttpHeaderToBeUpdated) headerChange).setOriginalValue(header.getValue()); } browserMobHttpResponse.getRawResponse().addHeader(headerKey, ((HttpHeaderToBeUpdated) headerChange).getNewValue()); headerChange.setApplied(); } else { if (header != null) { browserMobHttpResponse.getRawResponse().removeHeader(header); headerChange.setApplied(); } } } } byte[] newBody = wilmaResponse.getNewBody(); if (newBody != null) { try { browserMobHttpResponse.setAnswer(newBody); browserMobHttpResponse.getRawResponse().setEntity(new ByteArrayEntity(wilmaResponse.getNewBody())); } catch (IOException e) { logger.warn("Message ont-the-fly update was failed for message: " + wilmaResponse.getWilmaMessageId(), e); } } }  void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse); }
BrowserMobResponseUpdater { public void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse) { if (!wilmaResponse.isVolatile()) { return; } Map<String, HttpHeaderChange> headerChangeMap = wilmaResponse.getHeaderChanges(); if (headerChangeMap != null && !headerChangeMap.isEmpty()) { for (Map.Entry<String, HttpHeaderChange> headerChangeEntry : headerChangeMap.entrySet()) { String headerKey = headerChangeEntry.getKey(); HttpHeaderChange headerChange = headerChangeEntry.getValue(); Header header = browserMobHttpResponse.getRawResponse().getFirstHeader(headerKey); if (headerChange instanceof HttpHeaderToBeUpdated) { if (header != null) { ((HttpHeaderToBeUpdated) headerChange).setOriginalValue(header.getValue()); } browserMobHttpResponse.getRawResponse().addHeader(headerKey, ((HttpHeaderToBeUpdated) headerChange).getNewValue()); headerChange.setApplied(); } else { if (header != null) { browserMobHttpResponse.getRawResponse().removeHeader(header); headerChange.setApplied(); } } } } byte[] newBody = wilmaResponse.getNewBody(); if (newBody != null) { try { browserMobHttpResponse.setAnswer(newBody); browserMobHttpResponse.getRawResponse().setEntity(new ByteArrayEntity(wilmaResponse.getNewBody())); } catch (IOException e) { logger.warn("Message ont-the-fly update was failed for message: " + wilmaResponse.getWilmaMessageId(), e); } } }  void updateResponse(final BrowserMobHttpResponse browserMobHttpResponse, final WilmaHttpResponse wilmaResponse);  }