/** * Constructor that lets you choose whether downstream calls will be surrounded with a subspan. The default * {@link HttpTagAndSpanNamingStrategy} and {@link HttpTagAndSpanNamingAdapter} will be used * ({@link ZipkinHttpTagStrategy} and {@link SpringHttpClientTagAdapter}). * * @param surroundCallsWithSubspan pass in true to have downstream calls surrounded with a new span, false to only * propagate the current span's info downstream (no subspan). */ public WingtipsClientHttpRequestInterceptor(boolean surroundCallsWithSubspan) { this( surroundCallsWithSubspan, ZipkinHttpTagStrategy.<HttpRequest, ClientHttpResponse>getDefaultInstance(), SpringHttpClientTagAdapter.getDefaultInstance() ); }
@Before public void beforeMethod() { implSpy = spy(new SpringHttpClientTagAdapter()); requestMock = mock(HttpRequest.class); responseMock = mock(ClientHttpResponse.class); }
@Test public void getRequestUrl_returns_null_when_passed_null() { // expect assertThat(implSpy.getRequestUrl(null)).isNull(); }
@Test public void getResponseHttpStatus_returns_null_when_passed_null() { // expect assertThat(implSpy.getResponseHttpStatus(null)).isNull(); }
@Test public void getHeaderSingleValue_returns_null_when_passed_null_request() { // expect assertThat(implSpy.getHeaderSingleValue(null, "foo")).isNull(); }
@Test public void getRequestUriPathTemplate_returns_null() { // expect assertThat(implSpy.getRequestUriPathTemplate(requestMock, responseMock)).isNull(); }
@Test public void getRequestHttpMethod_returns_null_when_passed_null() { // expect assertThat(implSpy.getRequestHttpMethod(null)).isNull(); }
@Test public void getRequestPath_returns_null_when_passed_null() { // expect assertThat(implSpy.getRequestPath(null)).isNull(); }
@Test public void getHeaderMultipleValue_returns_null_when_passed_null_request() { // expect assertThat(implSpy.getHeaderMultipleValue(null, "foo")).isNull(); }
@DataProvider(value = { "true | spring.asyncresttemplate", "false | spring.resttemplate" }, splitBy = "\\|") @Test public void getSpanHandlerTagValue_works_as_expected_when_request_is_not_an_HttpRequestWrapper( boolean requestIsAsyncClientHttpRequest, String expectedResult ) { // given HttpRequest request = (requestIsAsyncClientHttpRequest) ? mock(AsyncClientHttpRequest.class) : mock(HttpRequest.class); // when String result = implSpy.getSpanHandlerTagValue(request, responseMock); // then assertThat(result).isEqualTo(expectedResult); }
/** * Constructor that lets you choose whether downstream calls will be surrounded with a subspan. The default * {@link HttpTagAndSpanNamingStrategy} and {@link HttpTagAndSpanNamingAdapter} will be used * ({@link ZipkinHttpTagStrategy} and {@link SpringHttpClientTagAdapter}). * * @param surroundCallsWithSubspan pass in true to have downstream calls surrounded with a new span, false to only * propagate the current span's info downstream (no subspan). */ public WingtipsAsyncClientHttpRequestInterceptor(boolean surroundCallsWithSubspan) { this( surroundCallsWithSubspan, ZipkinHttpTagStrategy.<HttpRequest, ClientHttpResponse>getDefaultInstance(), SpringHttpClientTagAdapter.getDefaultInstance() ); }
@Test public void getRequestUrl_returns_request_URI_toString() { // given URI expectedFullUri = URI.create("/foo/bar/" + UUID.randomUUID().toString() + "?stuff=things"); doReturn(expectedFullUri).when(requestMock).getURI(); // when String result = implSpy.getRequestUrl(requestMock); // then assertThat(result).isEqualTo(expectedFullUri.toString()); }
@Test public void getResponseHttpStatus_returns_null_when_response_getRawStatusCode_throws_IOException( ) throws IOException { // given doThrow(new IOException("intentional exception")).when(responseMock).getRawStatusCode(); // when Integer result = implSpy.getResponseHttpStatus(responseMock); // then assertThat(result).isNull(); verify(responseMock).getRawStatusCode(); }
@Test public void getHeaderSingleValue_returns_result_of_calling_request_headers_getFirst() { // given String expectedHeaderValue = UUID.randomUUID().toString(); String headerKey = UUID.randomUUID().toString(); HttpHeaders headersMock = mock(HttpHeaders.class); doReturn(headersMock).when(requestMock).getHeaders(); doReturn(expectedHeaderValue).when(headersMock).getFirst(headerKey); // when String result = implSpy.getHeaderSingleValue(requestMock, headerKey); // then assertThat(result).isEqualTo(expectedHeaderValue); verify(headersMock).getFirst(headerKey); }
/** * Constructor that lets you choose whether downstream calls will be surrounded with a subspan. The default * {@link HttpTagAndSpanNamingStrategy} and {@link HttpTagAndSpanNamingAdapter} will be used * ({@link ZipkinHttpTagStrategy} and {@link SpringHttpClientTagAdapter}). * * @param surroundCallsWithSubspan pass in true to have downstream calls surrounded with a new span, false to only * propagate the current span's info downstream (no subspan). */ public WingtipsClientHttpRequestInterceptor(boolean surroundCallsWithSubspan) { this( surroundCallsWithSubspan, ZipkinHttpTagStrategy.<HttpRequest, ClientHttpResponse>getDefaultInstance(), SpringHttpClientTagAdapter.getDefaultInstance() ); }
/** * Constructor that lets you choose whether downstream calls will be surrounded with a subspan. The default * {@link HttpTagAndSpanNamingStrategy} and {@link HttpTagAndSpanNamingAdapter} will be used * ({@link ZipkinHttpTagStrategy} and {@link SpringHttpClientTagAdapter}). * * @param surroundCallsWithSubspan pass in true to have downstream calls surrounded with a new span, false to only * propagate the current span's info downstream (no subspan). */ public WingtipsAsyncClientHttpRequestInterceptor(boolean surroundCallsWithSubspan) { this( surroundCallsWithSubspan, ZipkinHttpTagStrategy.<HttpRequest, ClientHttpResponse>getDefaultInstance(), SpringHttpClientTagAdapter.getDefaultInstance() ); }
@Test public void getDefaultInstance_returns_DEFAULT_INSTANCE() { // expect assertThat(SpringHttpClientTagAdapter.getDefaultInstance()) .isSameAs(SpringHttpClientTagAdapter.DEFAULT_INSTANCE); }
@Test public void default_constructor_creates_instance_with_subspan_option_on() { // when WingtipsAsyncClientHttpRequestInterceptor interceptor = new WingtipsAsyncClientHttpRequestInterceptor(); // then assertThat(interceptor.surroundCallsWithSubspan).isTrue(); assertThat(interceptor.tagAndNamingStrategy).isSameAs(ZipkinHttpTagStrategy.getDefaultInstance()); assertThat(interceptor.tagAndNamingAdapter).isSameAs(SpringHttpClientTagAdapter.getDefaultInstance()); }
@Test public void default_constructor_creates_instance_with_subspan_option_on() { // when WingtipsClientHttpRequestInterceptor interceptor = new WingtipsClientHttpRequestInterceptor(); // then assertThat(interceptor.surroundCallsWithSubspan).isTrue(); assertThat(interceptor.tagAndNamingStrategy).isSameAs(ZipkinHttpTagStrategy.getDefaultInstance()); assertThat(interceptor.tagAndNamingAdapter).isSameAs(SpringHttpClientTagAdapter.getDefaultInstance()); }
@DataProvider(value = { "true", "false" }) @Test public void single_arg_constructor_creates_instance_with_subspan_option_set_to_desired_value( boolean subspanOptionOn ) { // when WingtipsClientHttpRequestInterceptor interceptor = new WingtipsClientHttpRequestInterceptor(subspanOptionOn); // then assertThat(interceptor.surroundCallsWithSubspan).isEqualTo(subspanOptionOn); assertThat(interceptor.tagAndNamingStrategy).isSameAs(ZipkinHttpTagStrategy.getDefaultInstance()); assertThat(interceptor.tagAndNamingAdapter).isSameAs(SpringHttpClientTagAdapter.getDefaultInstance()); }