Search in sources :

Example 6 with AccessLogParam

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);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Test(org.junit.Test)

Example 7 with AccessLogParam

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);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerResponse(io.vertx.core.http.HttpServerResponse) VertxHttpHeaders(io.vertx.core.http.impl.headers.VertxHttpHeaders) Test(org.junit.Test)

Example 8 with AccessLogParam

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));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Test(org.junit.Test)

Example 9 with AccessLogParam

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("-"));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Test(org.junit.Test)

Example 10 with AccessLogParam

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);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Test(org.junit.Test)

Aggregations

RoutingContext (io.vertx.ext.web.RoutingContext)51 AccessLogParam (org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam)51 Test (org.junit.Test)51 HttpServerRequest (io.vertx.core.http.HttpServerRequest)26 SocketAddress (io.vertx.core.net.SocketAddress)7 HttpServerResponse (io.vertx.core.http.HttpServerResponse)6 VertxHttpHeaders (io.vertx.core.http.impl.headers.VertxHttpHeaders)4 Cookie (io.vertx.ext.web.Cookie)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 CookieImpl (io.vertx.ext.web.impl.CookieImpl)2 RestProducerInvocation (org.apache.servicecomb.common.rest.RestProducerInvocation)2 Invocation (org.apache.servicecomb.core.Invocation)2