Package org.apache.clerezza.triaxrs.mock

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


  @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);
View Full Code Here


  @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);
View Full Code Here

  @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);
View Full Code Here

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

    Request requestMock = EasyMock.createNiceMock(Request.class);
    ResponseImpl responseImpl = new ResponseImpl();

    String stringMessage = "Hello"
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
    expect(requestURI.getPath()).andReturn("/").anyTimes();
    expect(requestURI.getQuery()).andReturn("value=" + stringMessage)
        .anyTimes();
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    handler.handle(requestMock, responseImpl);
    responseImpl.consumeBody();
    Assert.assertArrayEquals(stringMessage.getBytes(), responseImpl.getBodyBytes());

    reset(requestURI);
    responseImpl = new ResponseImpl();
    // now do the same with a decimal value
    String decimalString = "446544";

    expect(requestURI.getPath()).andReturn("/").anyTimes();
    expect(requestURI.getQuery()).andReturn("value=" + decimalString)
        .anyTimes();
    replay(requestURI);
    handler.handle(requestMock, responseImpl);
    responseImpl.consumeBody();
    Assert.assertArrayEquals(("int:" + decimalString).getBytes(), responseImpl.getBodyBytes());
  }
View Full Code Here

  @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 = "";
    for(String st : allowHeader){
      allow += st;
View Full Code Here

  @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 = "";
    for(String st : allowHeader){
      allow += st;
View Full Code Here

  @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 = "";
    for(String st : allowHeader){
      allow += st;
View Full Code Here

    expect(requestURI.getPath()).andReturn("/");
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);

    ResponseImpl responseImpl = new ResponseImpl();
    handler.handle(requestMock, responseImpl);
    responseImpl.consumeBody();
   
    assertNotNull(responseImpl.getStatus());
    assertNotNull(responseImpl.getHeaders());
    assertArrayEquals(errMsgBar.getBytes(), responseImpl.getBodyBytes());
  }
View Full Code Here

      @Override
      public ReadableByteChannel read() throws IOException {
        return Channels.newChannel(new ByteArrayInputStream("body".getBytes()));
      }
    });
    ResponseImpl responseImpl = new ResponseImpl();
    handler.handle(request, responseImpl);
    assertTrue(exceptionMapperUsed);
  }
View Full Code Here

    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());
    assertEquals(BODY, new String(responseImpl.getBodyBytes()));

    String[] contentLength = responseImpl.getHeaders().get(HeaderName.CONTENT_LENGTH);
    assertTrue(contentLength.length == 1);
    assertEquals(new Long(BODY.length()), new Long(contentLength[0]));
  }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.triaxrs.mock.ResponseImpl

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.