Search in sources :

Example 6 with CommandContext

use of org.apache.dubbo.qos.command.CommandContext in project dubbo by alibaba.

the class HttpCommandDecoderTest method decodeGet.

@Test
public void decodeGet() throws Exception {
    HttpRequest request = mock(HttpRequest.class);
    when(request.getUri()).thenReturn("localhost:80/test");
    when(request.getMethod()).thenReturn(HttpMethod.GET);
    CommandContext context = HttpCommandDecoder.decode(request);
    assertThat(context.getCommandName(), equalTo("test"));
    assertThat(context.isHttp(), is(true));
    when(request.getUri()).thenReturn("localhost:80/test?a=b&c=d");
    context = HttpCommandDecoder.decode(request);
    assertThat(context.getArgs(), arrayContaining("b", "d"));
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) CommandContext(org.apache.dubbo.qos.command.CommandContext) Test(org.junit.jupiter.api.Test)

Example 7 with CommandContext

use of org.apache.dubbo.qos.command.CommandContext in project dubbo by alibaba.

the class HttpCommandDecoderTest method decodePost.

@Test
public void decodePost() throws Exception {
    FullHttpRequest request = mock(FullHttpRequest.class);
    when(request.getUri()).thenReturn("localhost:80/test");
    when(request.getMethod()).thenReturn(HttpMethod.POST);
    when(request.headers()).thenReturn(HttpHeaders.EMPTY_HEADERS);
    ByteBuf buf = Unpooled.copiedBuffer("a=b&c=d", StandardCharsets.UTF_8);
    when(request.content()).thenReturn(buf);
    CommandContext context = HttpCommandDecoder.decode(request);
    assertThat(context.getCommandName(), equalTo("test"));
    assertThat(context.isHttp(), is(true));
    assertThat(context.getArgs(), arrayContaining("b", "d"));
}
Also used : FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) CommandContext(org.apache.dubbo.qos.command.CommandContext) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

CommandContext (org.apache.dubbo.qos.command.CommandContext)7 Test (org.junit.jupiter.api.Test)3 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 NoSuchCommandException (org.apache.dubbo.qos.command.NoSuchCommandException)2 ByteBuf (io.netty.buffer.ByteBuf)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 Attribute (io.netty.handler.codec.http.multipart.Attribute)1 HttpPostRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)1 InterfaceHttpData (io.netty.handler.codec.http.multipart.InterfaceHttpData)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1