Add (failing) tests for methods that were not instrumented
MODIFY
dd-java-agent/instrumentation/apache-httpclient-4/src/test/groovy/ApacheHttpClientTest.groovy
dd-java-agent/instrumentation/apache-httpclient-4/src/test/groovy/ApacheHttpClientTest.groovy
import datadog.trace.agent.test.base.HttpClientTest
import datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientDecorator
+import org.apache.http.HttpHost
+import org.apache.http.HttpRequest
+import org.apache.http.HttpResponse
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.message.BasicHeader
+import org.apache.http.message.BasicHttpRequest
+import org.apache.http.protocol.BasicHttpContext
import spock.lang.Shared
-class ApacheHttpClientTest extends HttpClientTest<ApacheHttpClientDecorator> {
-
+abstract class ApacheHttpClientTest<T extends HttpRequest> extends HttpClientTest<ApacheHttpClientDecorator> {
@Shared
def client = new DefaultHttpClient()
+ @Override
+ ApacheHttpClientDecorator decorator() {
+ return ApacheHttpClientDecorator.DECORATE
+ }
+
@Override
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
- def request = new HttpUriRequest(method, uri)
+ def request = createRequest(method, uri)
headers.entrySet().each {
request.addHeader(new BasicHeader(it.key, it.value))
}
- def response = client.execute(request)
+ def response = executeRequest(request, uri)
callback?.call()
response.entity?.content?.close() // Make sure the connection is closed.
return response.statusLine.statusCode
}
+ abstract T createRequest(String method, URI uri)
+
+ abstract HttpResponse executeRequest(T request, URI uri)
+}
+
+class ApacheClientHostRequest extends ApacheHttpClientTest<BasicHttpRequest> {
@Override
- ApacheHttpClientDecorator decorator() {
- return ApacheHttpClientDecorator.DECORATE
+ BasicHttpRequest createRequest(String method, URI uri) {
+ return new BasicHttpRequest(method, uri.getPath())
+ }
+
+ @Override
+ HttpResponse executeRequest(BasicHttpRequest request, URI uri) {
+ return client.execute(new HttpHost(uri.getHost(), uri.getPort()), request)
+ }
+}
+
+class ApacheClientHostRequestContext extends ApacheHttpClientTest<BasicHttpRequest> {
+ @Override
+ BasicHttpRequest createRequest(String method, URI uri) {
+ return new BasicHttpRequest(method, uri.getPath())
+ }
+
+ @Override
+ HttpResponse executeRequest(BasicHttpRequest request, URI uri) {
+ return client.execute(new HttpHost(uri.getHost(), uri.getPort()), request, new BasicHttpContext())
+ }
+}
+
+class ApacheClientHostRequestResponseHandler extends ApacheHttpClientTest<BasicHttpRequest> {
+ @Override
+ BasicHttpRequest createRequest(String method, URI uri) {
+ return new BasicHttpRequest(method, uri.getPath())
+ }
+
+ @Override
+ HttpResponse executeRequest(BasicHttpRequest request, URI uri) {
+ return client.execute(new HttpHost(uri.getHost(), uri.getPort()), request, { response -> response })
+ }
+}
+
+class ApacheClientHostRequestResponseHandlerContext extends ApacheHttpClientTest<BasicHttpRequest> {
+ @Override
+ BasicHttpRequest createRequest(String method, URI uri) {
+ return new BasicHttpRequest(method, uri.getPath())
+ }
+
+ @Override
+ HttpResponse executeRequest(BasicHttpRequest request, URI uri) {
+ return client.execute(new HttpHost(uri.getHost(), uri.getPort()), request, { response -> response }, new BasicHttpContext())
+ }
+}
+
+class ApacheClientUriRequest extends ApacheHttpClientTest<HttpUriRequest> {
+ @Override
+ HttpUriRequest createRequest(String method, URI uri) {
+ return new HttpUriRequest(method, uri)
+ }
+
+ @Override
+ HttpResponse executeRequest(HttpUriRequest request, URI uri) {
+ return client.execute(request)
+ }
+}
+
+class ApacheClientUriRequestContext extends ApacheHttpClientTest<HttpUriRequest> {
+ @Override
+ HttpUriRequest createRequest(String method, URI uri) {
+ return new HttpUriRequest(method, uri)
+ }
+
+ @Override
+ HttpResponse executeRequest(HttpUriRequest request, URI uri) {
+ return client.execute(request, new BasicHttpContext())
+ }
+}
+
+class ApacheClientUriRequestResponseHandler extends ApacheHttpClientTest<HttpUriRequest> {
+ @Override
+ HttpUriRequest createRequest(String method, URI uri) {
+ return new HttpUriRequest(method, uri)
+ }
+
+ @Override
+ HttpResponse executeRequest(HttpUriRequest request, URI uri) {
+ return client.execute(request, { response -> response })
+ }
+}
+
+class ApacheClientUriRequestResponseHandlerContext extends ApacheHttpClientTest<HttpUriRequest> {
+ @Override
+ HttpUriRequest createRequest(String method, URI uri) {
+ return new HttpUriRequest(method, uri)
+ }
+
+ @Override
+ HttpResponse executeRequest(HttpUriRequest request, URI uri) {
+ return client.execute(request, { response -> response })
}
}

Add (failing) tests for methods that were not instrumented