use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.
the class RequestProtocolItemTest method getFormattedElement.
@Test
public void getFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext context = Mockito.mock(RoutingContext.class);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
param.setContextData(context);
Mockito.when(context.request()).thenReturn(request);
Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_1);
String result = new RequestProtocolItem().getFormattedItem(param);
assertEquals("HTTP/1.1", result);
Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_0);
result = new RequestProtocolItem().getFormattedItem(param);
assertEquals("HTTP/1.0", result);
Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_2);
result = new RequestProtocolItem().getFormattedItem(param);
assertEquals("HTTP/2.0", result);
}
use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.
the class ResponseHeaderItemTest method getFormattedElement.
@Test
public void getFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext mockContext = Mockito.mock(RoutingContext.class);
HttpServerResponse mockResponse = Mockito.mock(HttpServerResponse.class);
VertxHttpHeaders headers = new VertxHttpHeaders();
String headerValue = "headerValue";
param.setContextData(mockContext);
headers.add(VAR_NAME, headerValue);
Mockito.when(mockContext.response()).thenReturn(mockResponse);
Mockito.when(mockResponse.headers()).thenReturn(headers);
String result = ELEMENT.getFormattedItem(param);
assertEquals(headerValue, result);
assertEquals(ELEMENT.getVarName(), VAR_NAME);
}
use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItemTest method testGetFormattedElement.
@Test
public void testGetFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Map<String, Object> data = new HashMap<>();
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Invocation invocation = Mockito.mock(Invocation.class);
String traceIdTest = "traceIdTest";
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(traceIdTest);
Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
Mockito.when(routingContext.data()).thenReturn(data);
data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
param.setContextData(routingContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is(traceIdTest));
}
use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItemTest method testGetFormattedElementOnTraceIdNotFound.
@Test
public void testGetFormattedElementOnTraceIdNotFound() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Map<String, Object> data = new HashMap<>();
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn("");
Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
Mockito.when(routingContext.data()).thenReturn(data);
data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
param.setContextData(routingContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is("-"));
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(null);
result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is("-"));
}
use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.
the class UrlPathItemTest method getFormattedElement.
@Test
public void getFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext context = Mockito.mock(RoutingContext.class);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
String uri = "/uri/test";
param.setContextData(context);
Mockito.when(context.request()).thenReturn(request);
Mockito.when(request.path()).thenReturn(uri);
String result = new UrlPathItem().getFormattedItem(param);
Assert.assertEquals(uri, result);
}
Aggregations