Example usage for io.netty.handler.codec.http HttpVersion text

List of usage examples for io.netty.handler.codec.http HttpVersion text

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpVersion text.

Prototype

String text

To view the source code for io.netty.handler.codec.http HttpVersion text.

Click Source Link

Usage

From source file:org.apache.olingo.netty.server.core.NettyServiceDispatcherTest.java

License:Apache License

@Test
public void testMetadata() throws Exception {
    DefaultFullHttpRequest nettyRequest = Mockito.mock(DefaultFullHttpRequest.class);
    io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class);
    when(httpMethod.name()).thenReturn("GET");
    when(nettyRequest.method()).thenReturn(httpMethod);
    HttpVersion httpVersion = mock(HttpVersion.class);
    when(httpVersion.text()).thenReturn("HTTP/1.0");
    when(nettyRequest.protocolVersion()).thenReturn(httpVersion);
    when(nettyRequest.uri()).thenReturn("/trippin/$metadata");
    HttpHeaders headers = mock(HttpHeaders.class);
    when(nettyRequest.headers()).thenReturn(headers);
    when(nettyRequest.content()).thenReturn(Unpooled.buffer());

    DefaultFullHttpResponse nettyResponse = mock(DefaultFullHttpResponse.class);
    when(nettyResponse.status()).thenReturn(HttpResponseStatus.OK);
    when(nettyResponse.headers()).thenReturn(headers);
    when(nettyResponse.content()).thenReturn(Unpooled.buffer());

    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put("contextPath", "/trippin");
    ODataNettyHandler handler = odata.createNettyHandler(metadata);
    handler.processNettyRequest(nettyRequest, nettyResponse, requestParams);
    assertNotNull(new String(nettyResponse.content().array()));
    assertEquals(200, nettyResponse.status().code());
    assertEquals("OK", nettyResponse.status().reasonPhrase());
}

From source file:org.apache.olingo.netty.server.core.ODataNettyHandlerImplTest.java

License:Apache License

@Test
public void testNettyReqResp_GetMethod() {
    MetadataProcessor processor = mock(MetadataProcessor.class);
    final ODataNetty odata = ODataNetty.newInstance();
    final ServiceMetadata metadata = odata.createServiceMetadata(new EdmTechProvider(),
            Collections.<EdmxReference>emptyList());

    ODataNettyHandler handler = odata.createNettyHandler(metadata);

    handler.register(processor);/*from   w w w . j a va  2  s .  c  om*/
    DefaultFullHttpRequest nettyRequest = mock(DefaultFullHttpRequest.class);
    io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class);
    when(httpMethod.name()).thenReturn("GET");
    when(nettyRequest.method()).thenReturn(httpMethod);
    HttpVersion httpVersion = mock(HttpVersion.class);
    when(httpVersion.text()).thenReturn("HTTP/1.0");
    when(nettyRequest.protocolVersion()).thenReturn(httpVersion);
    when(nettyRequest.uri()).thenReturn("/odata.svc/$metadata");
    HttpHeaders headers = mock(HttpHeaders.class);
    headers.add("Accept", "application/atom+xml");
    Set<String> set = new HashSet<String>();
    set.add("Accept");
    when(headers.names()).thenReturn(set);
    when(nettyRequest.headers()).thenReturn(headers);
    when(nettyRequest.content()).thenReturn(Unpooled.buffer());

    DefaultFullHttpResponse nettyResponse = mock(DefaultFullHttpResponse.class);
    when(nettyResponse.status()).thenReturn(HttpResponseStatus.OK);
    when(nettyResponse.headers()).thenReturn(headers);

    when(nettyResponse.content()).thenReturn(Unpooled.buffer());

    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put("contextPath", "/odata.svc");
    handler.processNettyRequest(nettyRequest, nettyResponse, requestParams);

    nettyResponse.status();
    assertEquals(HttpStatusCode.OK.getStatusCode(), HttpResponseStatus.OK.code());
}

From source file:org.apache.olingo.netty.server.core.ODataNettyHandlerImplTest.java

License:Apache License

@Test
public void testNettyReqResp_POSTMethod() {
    EntityProcessor processor = mock(EntityProcessor.class);
    final ODataNetty odata = ODataNetty.newInstance();
    final ServiceMetadata metadata = odata.createServiceMetadata(new EdmTechProvider(),
            Collections.<EdmxReference>emptyList());

    ODataNettyHandler handler = odata.createNettyHandler(metadata);

    handler.register(processor);//from  ww  w. j a  v a  2 s.  c o m
    HttpRequest nettyRequest = mock(DefaultFullHttpRequest.class);
    io.netty.handler.codec.http.HttpMethod httpMethod = mock(io.netty.handler.codec.http.HttpMethod.class);
    when(httpMethod.name()).thenReturn("POST");
    when(nettyRequest.method()).thenReturn(httpMethod);
    HttpVersion httpVersion = mock(HttpVersion.class);
    when(httpVersion.text()).thenReturn("HTTP/1.0");
    when(nettyRequest.protocolVersion()).thenReturn(httpVersion);
    when(nettyRequest.uri()).thenReturn("/odata.svc/ESAllPrim");
    HttpHeaders headers = mock(HttpHeaders.class);
    headers.set("Content-Type", "application/json");
    Set<String> set = new HashSet<String>();
    set.add("Content-Type");
    when(headers.names()).thenReturn(set);
    List<String> headerValues = new ArrayList<String>();
    headerValues.add("application/json");
    when(headers.getAll("Content-Type")).thenReturn(headerValues);
    when(nettyRequest.headers()).thenReturn(headers);
    String content = "{\"@odata.context\": \"$metadata#ESAllPrim/$entity\"," + "\"PropertyInt16\": 32767,"
            + "\"PropertyString\": \"First Resource &&&- positive values\"," + "\"PropertyBoolean\": true,"
            + "\"PropertyByte\": 255," + "\"PropertySByte\": 127," + "\"PropertyInt32\": 2147483647,"
            + "\"PropertyInt64\": 9223372036854775807," + "\"PropertySingle\": 17900000,"
            + "\"PropertyDouble\": -179000," + "\"PropertyDecimal\": 34,"
            + "\"PropertyBinary\": \"ASNFZ4mrze8=\"," + "\"PropertyDate\": \"2012-12-03\","
            + "\"PropertyDateTimeOffset\": \"2012-12-03T07:16:23Z\"," + "\"PropertyDuration\": \"PT6S\","
            + "\"PropertyGuid\": \"01234567-89ab-cdef-0123-456789abcdef\","
            + "\"PropertyTimeOfDay\": \"03:26:05\"}";
    byte[] arr = new byte[content.length()];
    arr = content.getBytes();

    when(((DefaultFullHttpRequest) nettyRequest).content()).thenReturn(Unpooled.copiedBuffer(arr));

    HttpResponse nettyResponse = mock(DefaultFullHttpResponse.class);
    when(nettyResponse.status()).thenReturn(HttpResponseStatus.CREATED);
    when(nettyResponse.headers()).thenReturn(headers);

    when(((DefaultFullHttpResponse) nettyResponse).content()).thenReturn(Unpooled.buffer());

    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put("contextPath", "/odata.svc");
    handler.processNettyRequest(nettyRequest, nettyResponse, requestParams);

    nettyResponse.status();
    assertEquals(HttpStatusCode.CREATED.getStatusCode(), HttpResponseStatus.CREATED.code());
}