use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class HttpClientDoExecuteInterceptorTest method getResponse.
@Test
public void getResponse() {
Context context = EaseAgent.getContext();
HttpGet httpGet = new HttpGet();
ProtocolVersion protocolVersion = new ProtocolVersion("testProtocol", 10, 1);
BasicHttpResponse basicHttpResponse = new BasicHttpResponse(protocolVersion, 200, "");
basicHttpResponse.setHeader("aa", "bb");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
HttpClientDoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClientDoExecuteInterceptor();
HttpResponse httpResponse = httpClientDoExecuteInterceptor.getResponse(methodInfo, context);
assertEquals(200, httpResponse.statusCode());
}
use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class OkHttpTracingInterceptorTest method getResponse.
@Test
public void getResponse() {
Call call = OkHttpTestUtils.buildCall();
Response.Builder builder = OkHttpTestUtils.responseBuilder(call);
Response response = builder.build();
MethodInfo.MethodInfoBuilder methodInfoBuilder = MethodInfo.builder().invoker(call).retValue(response);
MethodInfo methodInfo = methodInfoBuilder.build();
OkHttpTracingInterceptor okHttpTracingInterceptor = new OkHttpTracingInterceptor();
EaseAgent.getContext().put(OkHttpTracingInterceptor.METHOD_KEY, call.request().method());
HttpResponse httpResponse = okHttpTracingInterceptor.getResponse(methodInfo, EaseAgent.getContext());
assertEquals("GET", httpResponse.method());
assertNull(httpResponse.route());
assertNull(httpResponse.maybeError());
assertEquals(200, httpResponse.statusCode());
RuntimeException runtimeException = new RuntimeException("test error");
methodInfoBuilder.throwable(runtimeException);
httpResponse = okHttpTracingInterceptor.getResponse(methodInfoBuilder.build(), EaseAgent.getContext());
assertEquals(runtimeException, httpResponse.maybeError());
}
Aggregations