GlobalHttpHeadersRequestFilter extends AbstractRequestFilter { @Override public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request) { if (headersToAdd == null || !isCacheHeaders() ) { synchronized (this) { if (headersToAdd == null || !isCacheHeaders()) initHeadersToAdd(); } } if (!headersToAdd.isEmpty()) { addHeadersToRequest(context, request); } }  @Override void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request); @Override void afterAbstractHttpResponse(SubmitContext context, AbstractHttpRequestInterface<?> request); static void addGlobalHeader(String name, String value); static void removeGlobalHeader(String name, String value); static final String REPLACE_HEADERS_SYSTEM_PROPERTY; static final String CACHE_HEADERS_SYSTEM_PROPERTY; static final String HEADER_SYSTEM_PROPERTY_PREFIX; }
@Test public void addsNothingByDefault() { StringToStringsMap requestHeaders = new StringToStringsMap(); SubmitContext context = mockContext(); AbstractHttpRequest<?> request = mockRequest(requestHeaders); globalHttpHeadersRequestFilter.filterAbstractHttpRequest(context, request); Mockito.verifyZeroInteractions(request); }
@Test @Ignore public void addHeaderWithPropertyExpansion() { System.setProperty(GlobalHttpHeadersRequestFilter.HEADER_SYSTEM_PROPERTY_PREFIX + "User-Agent", "Testing Replace.${currentStepIndex}.${currentStepRunIndex}"); AbstractTestCaseRunner runner = Mockito.mock(AbstractTestCaseRunner.class); Mockito.when(runner.getResultCount()).thenReturn(4); WsdlTestRunContext context = mockContext(); Mockito.when(context.getTestRunner()).thenReturn(runner); Mockito.when(context.getCurrentStepIndex()).thenReturn(3); AbstractHttpRequest<?> request = mockRequest(new StringToStringsMap()); globalHttpHeadersRequestFilter.filterAbstractHttpRequest(context, request); ArgumentCaptor<StringToStringsMap> headers = ArgumentCaptor.forClass(StringToStringsMap.class); Mockito.verify(request).setRequestHeaders(headers.capture()); Assert.assertEquals("Testing Replace.3.4", headers.getAllValues().get(0).get("User-Agent").get(0)); System.clearProperty(GlobalHttpHeadersRequestFilter.HEADER_SYSTEM_PROPERTY_PREFIX + "User-Agent"); }