Examples of RequestImpl


Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void tesPost1() throws Exception {
    JaxRsHandler handler = HandlerCreator.getHandler(MyRootResource.class);
    RequestURIImpl uri = new RequestURIImpl();
    RequestImpl request = new RequestImpl();
    ResponseImpl response = new ResponseImpl();

    String queryParam = "post1";
    final String bodyString = "body";
    uri.setPath("foo");
    uri.setQuery("name="+queryParam);
    request.setRequestURI(uri);
    String[] headervalues = new String[1];
    headervalues[0]="text/plain";
    request.setHeader(HeaderName.CONTENT_TYPE, headervalues);
    MessageBody messageBody = new MessageBody2Read() {

      @Override
      public ReadableByteChannel read() throws IOException {
        return Channels.newChannel(new ByteArrayInputStream(bodyString.getBytes()));
      }
    };

    request.setMessageBody(messageBody);

    request.setMethod(Method.POST);

    handler.handle(request, response);

    Assert.assertEquals(queryParam, value);
    Assert.assertEquals(bodyString, body);
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void testPost2() throws Exception {
    JaxRsHandler handler = HandlerCreator.getHandler(MyRootResource.class);
    RequestURIImpl uri = new RequestURIImpl();
    RequestImpl request = new RequestImpl();
    ResponseImpl response = new ResponseImpl();

    uri.setPath("foo");
    request.setRequestURI(uri);
    request.setMethod(Method.POST);

    handler.handle(request, response);

    Assert.assertEquals("post2", value);
    Assert.assertNull(body);
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void tesPost3() throws Exception {
    JaxRsHandler handler = HandlerCreator.getHandler(MyRootResource.class);
    RequestURIImpl uri = new RequestURIImpl();
    RequestImpl request = new RequestImpl();
    ResponseImpl response = new ResponseImpl();

    String queryParam = "post1";
    uri.setPath("foo");
    uri.setQuery("name="+queryParam);
    request.setRequestURI(uri);

    request.setMethod(Method.POST);

    handler.handle(request, response);

    Assert.assertEquals("post2", value);
    Assert.assertEquals(null, body);
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void testResponseToOptionsRequest() throws Exception {
    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class, MyResource2.class);
    RequestURIImpl uri = new RequestURIImpl();
    RequestImpl request = new RequestImpl();
    ResponseImpl response = new ResponseImpl();
    uri.setPath("/");
    request.setRequestURI(uri);
    request.setMethod(Method.OPTIONS);
    handler.handle(request, response);
    Map<HeaderName,String[]> headers = response.getHeaders();
    String[] allowHeader = headers.get(HeaderName.ALLOW);
    Assert.assertNotNull(allowHeader);
    String allow = "";
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void testResponseToOptionsRequestOnSubresource() throws Exception {
    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
    RequestURIImpl uri = new RequestURIImpl();
    RequestImpl request = new RequestImpl();
    ResponseImpl response = new ResponseImpl();
    uri.setPath("/sub");
    request.setRequestURI(uri);
    request.setMethod(Method.OPTIONS);
    handler.handle(request, response);
    Map<HeaderName,String[]> headers = response.getHeaders();
    String[] allowHeader = headers.get(HeaderName.ALLOW);
    Assert.assertNotNull(allowHeader);
    String allow = "";
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void testResponseToOptionsRequestWithNoResource() throws Exception {
    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class, MyResource2.class);
    RequestURIImpl uri = new RequestURIImpl();
    RequestImpl request = new RequestImpl();
    ResponseImpl response = new ResponseImpl();

    uri.setType(RequestURI.Type.NO_RESOURCE);
    request.setRequestURI(uri);
    request.setMethod(Method.OPTIONS);
    handler.handle(request, response);
    Map<HeaderName,String[]> headers = response.getHeaders();
    String[] allowHeader = headers.get(HeaderName.ALLOW);
    Assert.assertNotNull(allowHeader);
    String allow = "";
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  public void testMappingForMessageBodyReader() throws Exception {
    exceptionMapperUsed = false;
    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class,
        MyExceptionMapper.class, MyMessageBodyReader.class,
        MyMessageBodyWriter.class);
    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/reader");
    request.setRequestURI(uri);
    request.setMethod(Method.POST);
    String[] type = {TEST_BLA_TYPE};
    request.setHeader(HeaderName.CONTENT_TYPE, type);
    request.setMessageBody(new MessageBody2Read() {

      @Override
      public ReadableByteChannel read() throws IOException {
        return Channels.newChannel(new ByteArrayInputStream("body".getBytes()));
      }
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  public void testMappingForMessageBodyWriter() throws Exception {
    exceptionMapperUsed = false;
    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class,
        MyExceptionMapper.class, MyMessageBodyReader.class,
        MyMessageBodyWriter.class);
    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/writer");
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    ResponseImpl responseImpl = new ResponseImpl();
    handler.handle(request, responseImpl);
    responseImpl.consumeBody();
    assertTrue(exceptionMapperUsed);
    assertEquals(ResponseStatus.SUCCESS, responseImpl.getStatus());
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

    }
  }
  @Test
  public void testFormParamInjectionIntoMethod() throws Exception {   
    JaxRsHandler handler = HandlerCreator.getHandler(TestResourceForDefaultValue.class);
    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/test-resource/setForm");
    String[] values = new String[1];
    values[0] = "application/x-www-form-urlencoded";
    request.setHeader(HeaderName.CONTENT_TYPE, values);
    request.setMessageBody(new MessageBody2Write() {

              @Override
              public void writeTo(WritableByteChannel cout)
                  throws IOException {
                
                OutputStream out = Channels.newOutputStream(cout);
                String str = new String("value=foo+bar");
                out.write(str.getBytes());
              }
            });   
    request.setRequestURI(uri);
    request.setMethod(Method.POST);   
    Response response = new ResponseImpl();
    handler.handle(request, response);
    assertEquals("foo bar", TestResourceForDefaultValue.value);
 
View Full Code Here

Examples of org.apache.clerezza.triaxrs.mock.RequestImpl

  @Test
  public void testOptions() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
   
    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/");
    String[] headervalues = new String[1];
    headervalues[0] = "testheadervalue";
    String headerName = "tEstHeaDER";
    request.setHeader(HeaderName.get(headerName), headervalues);
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    Response response = new ResponseImpl();
    handler.handle(request, response);

    assertTrue(methodInvokedForGet);
    assertEquals(headervalues[0], headervalue);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.