Search in sources :

Example 21 with AccessLogParam

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

the class RequestHeaderItemTest method getFormattedElement.

@Test
public void getFormattedElement() {
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    param.setContextData(mockContext);
    HttpServerRequest mockRequest = Mockito.mock(HttpServerRequest.class);
    VertxHttpHeaders headers = new VertxHttpHeaders();
    String testValue = "testValue";
    headers.add(VAR_NAME, testValue);
    Mockito.when(mockContext.request()).thenReturn(mockRequest);
    Mockito.when(mockRequest.headers()).thenReturn(headers);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals(testValue, result);
    assertEquals(ELEMENT.getVarName(), VAR_NAME);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerRequest(io.vertx.core.http.HttpServerRequest) VertxHttpHeaders(io.vertx.core.http.impl.headers.VertxHttpHeaders) Test(org.junit.Test)

Example 22 with AccessLogParam

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

the class RequestHeaderItemTest method getFormattedElementIfNotFound.

@Test
public void getFormattedElementIfNotFound() {
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    param.setContextData(mockContext);
    HttpServerRequest mockRequest = Mockito.mock(HttpServerRequest.class);
    VertxHttpHeaders headers = new VertxHttpHeaders();
    String testValue = "testValue";
    headers.add("anotherHeader", testValue);
    Mockito.when(mockContext.request()).thenReturn(mockRequest);
    Mockito.when(mockRequest.headers()).thenReturn(headers);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals("-", result);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) HttpServerRequest(io.vertx.core.http.HttpServerRequest) VertxHttpHeaders(io.vertx.core.http.impl.headers.VertxHttpHeaders) Test(org.junit.Test)

Example 23 with AccessLogParam

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

the class CookieItemTest method getFormattedElementOnCookieSetIsNull.

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

Example 24 with AccessLogParam

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

the class ResponseHeaderItemTest method getFormattedElementOnHeadersIsNull.

@Test
public void getFormattedElementOnHeadersIsNull() {
    AccessLogParam<RoutingContext> param = new AccessLogParam<>();
    RoutingContext mockContext = Mockito.mock(RoutingContext.class);
    HttpServerResponse mockResponse = Mockito.mock(HttpServerResponse.class);
    param.setContextData(mockContext);
    Mockito.when(mockContext.response()).thenReturn(mockResponse);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals("-", 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 25 with AccessLogParam

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

the class ResponseHeaderItemTest method getFormattedElementOnNotFound.

@Test
public void getFormattedElementOnNotFound() {
    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("anotherHeader", headerValue);
    Mockito.when(mockContext.response()).thenReturn(mockResponse);
    Mockito.when(mockResponse.headers()).thenReturn(headers);
    String result = ELEMENT.getFormattedItem(param);
    assertEquals("-", result);
}
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)

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