@Test public void testExtractHeadersAllCommonHeaders() throws Exception { final RequestType request1 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request1.setHeaders( createHeaders( new NVPair("foo", "bah"), new NVPair("User-Agent", "blah"), new NVPair("Accept", "x"))); request1.addNewResponse(); final RequestType request2 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request2.setHeaders( createHeaders( new NVPair("foo", "bah"), new NVPair("User-Agent", "blah"), new NVPair("Accept", "x"))); request2.addNewResponse(); m_httpRecording.dispose(); verify(m_resultProcessor).process(m_recordingCaptor.capture()); final HTTPRecordingType recording = m_recordingCaptor.getValue().getHttpRecording(); assertEquals(1, recording.getCommonHeadersArray().length); final RequestType request = recording.getPageArray(0).getRequestArray(0); final HeadersType headers = request.getHeaders(); assertEquals("headers0", headers.getExtends()); assertEquals(1, headers.sizeOfHeaderArray()); }
private HeadersType createHeaders(final NVPair... nvPairs) { final HeadersType result = HeadersType.Factory.newInstance(); for (final NVPair nvPair : nvPairs) { final HeaderType header = result.addNewHeader(); header.setName(nvPair.getName()); header.setValue(nvPair.getValue()); } return result; }
@Test public void testAddRequestWithHeaders() throws Exception { final RequestType request1 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request1.setHeaders( createHeaders( new NVPair("foo", "bah"), new NVPair("User-Agent", "blah"), new NVPair("Accept", "x"))); request1.addNewResponse(); final RequestType request2 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request2.setHeaders( createHeaders( new NVPair("fu", "bar"), new NVPair("User-Agent", "blah"), new NVPair("Accept", "y"))); request2.addNewResponse(); final RequestType request3 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request3.setHeaders( createHeaders( new NVPair("fu", "bar"), new NVPair("User-Agent", "blah"), new NVPair("Accept", "y"))); request3.addNewResponse(); final RequestType request4 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request4.setHeaders(createHeaders(new NVPair("User-Agent", "blah"), new NVPair("Accept", "z"))); final BasicAuthorizationHeaderType basicAuthorizationHeaderType = request4.getHeaders().addNewAuthorization().addNewBasic(); basicAuthorizationHeaderType.setUserid("phil"); basicAuthorizationHeaderType.setPassword("abracaduh"); request4.addNewResponse(); // The next two requests trigger the case where there is // common header set that matches the default headers. final RequestType request5 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request5.setHeaders(createHeaders(new NVPair("User-Agent", "blah"))); request5.addNewResponse(); final RequestType request6 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request6.setHeaders(createHeaders(new NVPair("User-Agent", "blah"))); request6.addNewResponse(); // Request with no response. final RequestType request7 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request7.setHeaders(createHeaders(new NVPair("User-Agent", "blah"), new NVPair("Accept", "z"))); final RequestType request8 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request8.setHeaders( createHeaders(new NVPair("User-Agent", "blah"), new NVPair("Accept", "zz"))); request8.addNewResponse(); final RequestType request9 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/path"); request9.setHeaders( createHeaders(new NVPair("User-Agent", "blah"), new NVPair("Accept", "zz"))); request9.addNewResponse(); m_httpRecording.dispose(); verify(m_resultProcessor).process(m_recordingCaptor.capture()); final HTTPRecordingType recording = m_recordingCaptor.getValue().getHttpRecording(); // Default, plus 2 sets. assertEquals(3, recording.getCommonHeadersArray().length); final CommonHeadersType defaultHeaders = recording.getCommonHeadersArray(0); assertEquals(0, defaultHeaders.getAuthorizationArray().length); assertEquals(1, defaultHeaders.getHeaderArray().length); assertEquals("User-Agent", defaultHeaders.getHeaderArray(0).getName()); final CommonHeadersType commonHeaders1 = recording.getCommonHeadersArray(1); assertEquals(defaultHeaders.getHeadersId(), commonHeaders1.getExtends()); assertEquals(1, commonHeaders1.getHeaderArray().length); assertEquals(0, commonHeaders1.getAuthorizationArray().length); assertEquals( "defaultHeaders", recording.getPageArray(0).getRequestArray(0).getHeaders().getExtends()); final CommonHeadersType commonHeaders2 = recording.getCommonHeadersArray(2); assertEquals(defaultHeaders.getHeadersId(), commonHeaders2.getExtends()); assertEquals(1, commonHeaders2.getHeaderArray().length); assertEquals("zz", commonHeaders2.getHeaderArray(0).getValue()); assertEquals(0, commonHeaders2.getAuthorizationArray().length); final HeadersType headers = recording.getPageArray(3).getRequestArray(0).getHeaders(); assertEquals(1, headers.getHeaderArray().length); assertEquals(1, headers.getAuthorizationArray().length); assertEquals("phil", headers.getAuthorizationArray(0).getBasic().getUserid()); }