Package org.apache.clerezza.triaxrs.mock

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


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

  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

  }
 
  private void setup(String path) throws Exception{
    transformer = transformerFac.newTransformer();
    //new request and response
    request = new RequestImpl();
    response = new ResponseImpl();
   
    uri.setPath(path);
    String[] headervalues = new String[2];
    //headervalues[0] = "text/html";
View Full Code Here

    @Test
    public void testGetMethodPathNotFound() throws Exception {
       
      JaxRsHandler handler = HandlerCreator.getHandler(TestResource.class,
        TestResourceWithTemplateInMethod.class);
        RequestImpl request = new RequestImpl();
        RequestURIImpl uri = new RequestURIImpl();
        uri.setPath("/test-resource/blabla");
        request.setRequestURI(uri);
        request.setMethod(Method.GET);
       
        ResponseImpl response = new ResponseImpl();
       

        handler.handle(request, response);
View Full Code Here

    @Test
    public void testWithParameterNotFound() throws Exception {
       
      JaxRsHandler handler = HandlerCreator.getHandler(TestResource.class,
        TestResourceWithTemplateInMethod.class);
        RequestImpl request = new RequestImpl();
        RequestURIImpl uri = new RequestURIImpl();
        uri.setPath("/test-resource/postToMe");
        request.setRequestURI(uri);
        request.setMethod(Method.DELETE);
        ResponseImpl response = new ResponseImpl();
       
         boolean expThrown = false;
       
        try{
View Full Code Here

  public void testConcurrency() throws Exception {
    Object[] components = { new MyMessageBodyWriter(), new MyResource() };
    JaxRsHandler handler = HandlerCreator.getHandler("", components);

    // Request of thread 1
    RequestImpl requestMock = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/");
    String queryString = "key=thread1";
    uri.setQuery(queryString);
    requestMock.setRequestURI(uri);
    requestMock.setMethod(Method.GET);

    // Request of thread 2
    RequestImpl requestMock2 = new RequestImpl();
    RequestURIImpl uri2 = new RequestURIImpl();
    uri2.setPath("/");
    String queryString2 = "key=thread2";
    uri2.setQuery(queryString2);
    requestMock2.setRequestURI(uri2);
    requestMock2.setMethod(Method.GET);

    long iterations = 100
    BodyCheckerThread thread1 = new BodyCheckerThread(handler, requestMock,
        queryString.getBytes(), iterations);
    BodyCheckerThread thread2 = new BodyCheckerThread(handler,
View Full Code Here

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

    RequestImpl requestMock = new RequestImpl();
    RequestURIImpl uri = new RequestURIImpl();
    uri.setPath("/test");
    requestMock.setRequestURI(uri);
    requestMock.setMethod(Method.GET);

    ResponseImpl response = new ResponseImpl();
    handler.handle(requestMock, response);
  }
View Full Code Here

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

    uri.setPath("sub");
    request.setRequestURI(uri);
    request.setMethod(Method.GET);

    handler.handle(request, response);

    Assert.assertEquals("get2", value);
  }
View Full Code Here

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

    uri.setPath("");
    request.setRequestURI(uri);
    request.setMethod(Method.GET);

    handler.handle(request, response);

    Assert.assertEquals("get", value);
  }
View Full Code Here

TOP

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

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.