Package org.apache.clerezza.triaxrs

Examples of org.apache.clerezza.triaxrs.JaxRsHandler


  }
 
  @Test
  public void acceptHeaderBasedMethodSelectionWithQ() 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/string3;q=.7","test/string2;q=.9","*/*;q=.1"};
    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


  }
 
  @Test
  public void acceptHeaderBasedMethodSelectionWithQ2() 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/string3","test/string2;q=.9","*/*;q=.1"};
    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(2,methodInvoked);

  }
View Full Code Here

  }
 
  @Test
  public void acceptHeaderBasedMethodSelectionWithQ3() 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 = {"foo/bar"};
    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(3,methodInvoked);

  }
View Full Code Here

  }
  @Test
  public void acceptHeaderBasedMethodSelectionWithQ4() 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/string6","test/string2;q=.9","*/*;q=.1"};
    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(4,methodInvoked);

  }
View Full Code Here

  }

  @Test
  public void testOptions() 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("/");
    expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
    replay(requestMock);
    replay(requestURI);
    replay(responseMock);
    handler.handle(requestMock, responseMock);
    assertTrue(methodInvokedForGet);

  }
View Full Code Here

 
  @Test
  public void testJAFProviderBodyReader() throws Exception {
    setup();
   
    JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
   
    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/");
    String[] headervalues = new String[1];
    headervalues[0] = "application/testobj";
    request.setHeader(HeaderName.CONTENT_TYPE, headervalues);

    JafSerializableObj testObj = new JafSerializableObj("foo", "bar");
   
    // Serialize testObj
    final ByteArrayOutputStream bous = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(bous);
    out.writeObject(testObj);
    out.close();
    MessageBody body = new MessageBody2Read() {

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

    };
   
    request.setMessageBody(body);
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    Response response = new ResponseImpl();
    handler.handle(request, response);
    assertTrue(MyResource.myTestobj != null);
    assertEquals("foo", MyResource.myTestobj.getField1());
    assertEquals("bar", MyResource.myTestobj.getField2());
  }
View Full Code Here

  }

  @Test
  public void testJAFProviderBodyWriter() 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] = "application/testobj";
    request.setHeader(HeaderName.ACCEPT, headervalues);
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    ResponseImpl response = new ResponseImpl();
    handler.handle(request, response);
    response.consumeBody();
   
        JafSerializableObj testobj = null;
       
        //deserialize object
View Full Code Here

 
  @Test
  public void testResponseObject() throws Exception {

    Object[] components = {new MultiFormatWriter(), new MyResource()};
    JaxRsHandler handler = HandlerCreator.getHandler("", components);
    Request requestMock = EasyMock.createNiceMock(Request.class);
    ResponseImpl responseImpl = new ResponseImpl();

    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    String[] acceptHeaders = {"test/string2;q=.8", "test/string1;q=.7"};
    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);
    handler.handle(requestMock, responseImpl);
    responseImpl.consumeBody();
    assertTrue(writerCalled);
    Assert.assertArrayEquals(entity.getBytes(), responseImpl.getBodyBytes());

    String[] contentType = responseImpl.getHeaders().get(HeaderName.CONTENT_TYPE);
View Full Code Here

 
  @Test
  public void testNoMatchingAcceptAndProduce() throws Exception {
    writerCalled = false;
    Object[] components = {new MultiFormatWriter(), new MyResource2()};
    JaxRsHandler handler = HandlerCreator.getHandler("", components);

    RequestImpl request = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/");
    String[] headervalues = new String[1];
    headervalues[0] = "test/string3";
    request.setHeader(HeaderName.ACCEPT, headervalues);
    request.setRequestURI(uri);
    request.setMethod(Method.GET);
    ResponseImpl response = new ResponseImpl();
    handler.handle(request, response);

    assertTrue(!writerCalled);
  }
View Full Code Here

  @Test
  public void testWrongContentTypeInResponse() throws Exception {

    Object[] components = {new MultiFormatWriterWithWrongProduces(), new MyResource()};
    JaxRsHandler handler = HandlerCreator.getHandler("", components);
    Request requestMock = EasyMock.createNiceMock(Request.class);
    Response responseMock = EasyMock.createNiceMock(Response.class);

    makeThreadSafe(responseMock, true);

    //triaxrs has default writer for String, so the following isn't true:
    //responseMock.setResponseStatus(ResponseStatus.NOT_ACCEPTABLE);
    expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
    String[] acceptHeaders = {"test/string2;q=.8", "test/string4;q=.7"};
    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);
    assertTrue(!writerCalled);
    verify(responseMock);
  }
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.