Package org.apache.clerezza.triaxrs

Examples of org.apache.clerezza.triaxrs.JaxRsHandler


  }

  @Test
  public void testQueryParam() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
   
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    expect(requestURI.getPath()).andReturn("/foo").anyTimes();
    expect(requestURI.getQuery()).andReturn("key=value").anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertEquals("value", handleGetParamValue);

  }
View Full Code Here


  }

  @Test
  public void testQueryParamWithSpace() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);

    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    expect(requestURI.getPath()).andReturn("/foo").anyTimes();
    expect(requestURI.getQuery()).andReturn("key=foo+bar").anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertEquals("foo bar", handleGetParamValue);

  }
View Full Code Here

  }

  @Test
  public void testMultiValueQueryParam() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource2.class);

    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    expect(requestURI.getPath()).andReturn("/foo").anyTimes();
    expect(requestURI.getQuery())
        .andReturn("key1=value1&key1=value2&key2=value3&key2=value4")
        .anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertEquals("value1", handleGetParamValue1.get(0));
    assertEquals("value2", handleGetParamValue1.get(1));
    assertEquals(2, handleGetParamValue1.size());
    assertEquals("value3", handleGetParamValue2.get(0).getValue());
    assertEquals("value4", handleGetParamValue2.get(1).getValue());
View Full Code Here

  }

  @Test
  public void testHttpHeadersAndHeaderParam() 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] = "en-uk-cockney";
    request.setHeader(HeaderName.ACCEPT_LANGUAGE, headervalues);
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    Response response = new ResponseImpl();
    handler.handle(request, response);

    assertTrue(mylocale != null);
    assertEquals("en_UK_cockney", mylocale.toString());
    assertTrue(mylocale2 != null);
    assertEquals("en_UK_cockney", mylocale2.toString());
View Full Code Here

  @Test
  public void testIllegalArgumentHandling() throws Exception {
    mylocale = null;
    mylocale2 = null;

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);

    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/");
    String[] headervalues = new String[1];
    // set a RFC 1766 language tag that can't be converted to a Locale
    headervalues[0] = "i-klingon";
    request.setHeader(HeaderName.ACCEPT_LANGUAGE, headervalues);
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    Response response = new ResponseImpl();
    handler.handle(request, response);

    assertEquals(mylocale, null);
    assertEquals(mylocale2, null);
  }
View Full Code Here

  }

  @Test
  public void testResponseCode() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(new MyResource());
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    responseMock.setResponseStatus(ResponseStatus.CREATED);
    expect(requestMock.getMethod()).andReturn(Method.PUT).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    expect(requestURI.getPath()).andReturn("/");
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    verify(responseMock);

  }
View Full Code Here

  }

  @Test
  public void testPathParam() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    String value1 = "foo";
    String value2 = "bar";
    expect(requestURI.getPath()).andReturn("/prefix/"+value1+"/fix/"+value2).anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertEquals(value1, handlePathParamValue1);
    assertEquals(value2, handlePathParamValue2);
  }
View Full Code Here

  }
 
  @Test
  public void testPathParamDecoding() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    String value1 = "f#o";
    String value2 = "b/a/r";
    expect(requestURI.getPath()).andReturn("/prefix/"+URLEncoder.encode(value1,"utf-8")+"/fix/"+URLEncoder.encode(value2, "utf-8")).anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertEquals(value1, handlePathParamValue1);
    assertEquals(value2, handlePathParamValue2);

  }
View Full Code Here

  }

  @Test
  public void testIntInjection() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
   
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    int idValue = 65765;
    expect(requestURI.getPath()).andReturn("/").anyTimes();
    expect(requestURI.getQuery()).andReturn("id="+idValue).anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    Assert.assertEquals(idValue, idValueReceived);
  }
View Full Code Here

  }

  @Test
  public void acceptHeaderBasedMethodSelection() throws Exception {

    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
   
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    String[] acceptHeaders = {"test/string2"};
    expect(requestMock.getHeaderNames()).andReturn(
        Collections.singleton(HeaderName.ACCEPT)).anyTimes();
    expect(requestMock.getHeaderValues(HeaderName.ACCEPT))
    .andReturn(acceptHeaders).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    expect(requestURI.getPath()).andReturn("/");
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertEquals(1,methodInvoked);

  }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.triaxrs.JaxRsHandler

Copyright © 2018 www.massapicom. 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.