Search in sources :

Example 26 with AccessLogParam

use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.

the class ResponseHeaderItemTest method getFormattedElementOnResponseIsNull.

@Test
public void getFormattedElementOnResponseIsNull() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    param.setContextData(mockContext);
    Mockito.when(mockContext.response()).thenReturn(null);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals("-", result);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) Test(org.junit.Test)

Example 27 with AccessLogParam

use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.

the class ResponseSizeItemTest method getFormattedElementOnResponseIsNull.

@Test
public void getFormattedElementOnResponseIsNull() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    param.setContextData(mockContext);
    Mockito.when(mockContext.response()).thenReturn(null);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals("0", result);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) Test(org.junit.Test)

Example 28 with AccessLogParam

use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.

the class ResponseSizeItemTest method getFormattedElementOnBytesWrittenIsZero.

@Test
public void getFormattedElementOnBytesWrittenIsZero() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    HttpServerResponse mockResponse = Mockito.mock(HttpServerResponse.class);
    long bytesWritten = 0L;
    param.setContextData(mockContext);
    Mockito.when(mockContext.response()).thenReturn(mockResponse);
    Mockito.when(mockResponse.bytesWritten()).thenReturn(bytesWritten);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals("0", result);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Example 29 with AccessLogParam

use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.

the class ResponseSizeItemTest method getFormattedElement.

@Test
public void getFormattedElement() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    HttpServerResponse mockResponse = Mockito.mock(HttpServerResponse.class);
    long bytesWritten = 16L;
    param.setContextData(mockContext);
    Mockito.when(mockContext.response()).thenReturn(mockResponse);
    Mockito.when(mockResponse.bytesWritten()).thenReturn(bytesWritten);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals(String.valueOf(bytesWritten), result);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Example 30 with AccessLogParam

use of org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam in project incubator-servicecomb-java-chassis by apache.

the class StatusItemTest method getFormattedElement.

@Test
public void getFormattedElement() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext context = Mockito.mock(RoutingContext.class);
    HttpServerResponse response = Mockito.mock(HttpServerResponse.class);
    int statusCode = 200;
    param.setContextData(context);
    Mockito.when(context.response()).thenReturn(response);
    Mockito.when(response.getStatusCode()).thenReturn(statusCode);
    String result = STATUS_ELEMENT.getFormattedItem(param);
    assertEquals("200", result);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerResponse(io.vertx.core.http.HttpServerResponse) 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