Examples of MockHttpResponse


Examples of org.jboss.resteasy.mock.MockHttpResponse

         if (dispatcher == null)
         {
            return null;
         }
         enhanceRequest(request);
         return dispatcher.internalInvocation(request, new MockHttpResponse(), entity);
      }
      finally
      {
      }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      POJOResourceFactory noDefaults = new POJOResourceFactory(SimpleResource.class);
      dispatcher.getRegistry().addResourceFactory(noDefaults);

      {
         MockHttpRequest request = MockHttpRequest.get("/basic");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("basic", response.getContentAsString());
      }
      {
         MockHttpRequest request = MockHttpRequest.put("/basic");
         request.content("basic".getBytes());
         request.contentType("text/plain");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(204, response.getStatus());
      }
      {
         MockHttpRequest request = MockHttpRequest.get("/queryParam?" + "param=" + URLEncoder.encode("hello world", "UTF-8"));
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("hello world", response.getContentAsString());
      }
      {
         MockHttpRequest request = MockHttpRequest.get("/uriParam/1234");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("1234", response.getContentAsString());
      }
   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      POJOResourceFactory noDefaults = new POJOResourceFactory(LocatingResource.class);
      dispatcher.getRegistry().addResourceFactory(noDefaults);

      {
         MockHttpRequest request = MockHttpRequest.get("/locating/basic");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("basic", response.getContentAsString());
      }
      {
         MockHttpRequest request = MockHttpRequest.put("/locating/basic");
         request.content("basic".getBytes());
         request.contentType("text/plain");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(204, response.getStatus());
      }
      {
         MockHttpRequest request = MockHttpRequest.get("/locating/queryParam?" + "param=" + URLEncoder.encode("hello world", "UTF-8"));
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("hello world", response.getContentAsString());
      }
      {
         MockHttpRequest request = MockHttpRequest.get("/locating/uriParam/1234");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("1234", response.getContentAsString());
      }
   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      POJOResourceFactory noDefaults = new POJOResourceFactory(LocatingResource.class);
      dispatcher.getRegistry().addResourceFactory(noDefaults);

      {
         MockHttpRequest request = MockHttpRequest.get("/locating/uriParam/x123");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());

         // XXX Should this be SC_NOT_FOUND?
         // Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
         Assert.assertEquals("", response.getContentAsString());
      }

   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      POJOResourceFactory noDefaults = new POJOResourceFactory(LocatingResource.class);
      dispatcher.getRegistry().addResourceFactory(noDefaults);

      {
         MockHttpRequest request = MockHttpRequest.get("/notlocating");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
         Assert.assertEquals("", response.getContentAsString());
      }

   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      POJOResourceFactory noDefaults = new POJOResourceFactory(LocatingResource.class);
      dispatcher.getRegistry().addResourceFactory(noDefaults);

      {
         MockHttpRequest request = MockHttpRequest.get("/locating/notmatching");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
         Assert.assertEquals("", response.getContentAsString());
      }

   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      POJOResourceFactory noDefaults = new POJOResourceFactory(LocatingResource.class);
      dispatcher.getRegistry().addResourceFactory(noDefaults);

      {
         MockHttpRequest request = MockHttpRequest.get("/subresource/subresource/subresource/basic");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("basic", response.getContentAsString());
      }

   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      {

         System.out.println("Expect to see WARN about not injecting in subresources");

         MockHttpRequest request = MockHttpRequest.get("/subresource/testContextParam");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(204, response.getStatus());
      }

   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();

      dispatcher.getRegistry().addPerRequestResource(CollectionResource.class);
      {
         MockHttpRequest request = MockHttpRequest.get("/collection/annotation_free_subresource");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("got", response.getContentAsString());
         Assert.assertNotNull(response.getOutputHeaders().get("Content-Type"));
         Assert.assertTrue(response.getOutputHeaders().get("Content-Type").size() > 0);
         Assert.assertEquals(MediaType.TEXT_PLAIN_TYPE, response.getOutputHeaders().get("Content-Type").get(0));
      }

      {
         MockHttpRequest request = MockHttpRequest.post("/collection/annotation_free_subresource");
         request.content("hello!".getBytes()).contentType(MediaType.TEXT_PLAIN);
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("posted: hello!", response.getContentAsString());
      }
   }
View Full Code Here

Examples of org.jboss.resteasy.mock.MockHttpResponse

    for (String characterSet : characterSets) {
      MockHttpRequest request = MockHttpRequest.get(path);
      request.accept("application/xml");
      request.header("Accept-Charset", characterSet);
   
      MockHttpResponse response = new MockHttpResponse();
      dispatcher.invoke(request, response);
      assertEquals("Status code.", 200, response.getStatus());

      String contentType = response.getOutputHeaders().getFirst("Content-Type").toString();
      String charsetPattern = "application/xml\\s*;\\s*charset\\s*=\\s*\"?" + characterSet + "\"?";
      String charsetErrorMessage = contentType + " does not match " + charsetPattern;
      assertTrue(charsetErrorMessage, contentType.matches(charsetPattern));

      String xml = response.getContentAsString();
      String encodingPattern = "<\\?xml[^>]*encoding\\s*=\\s*['\"]" + characterSet + "['\"].*";
      String encodingErrorMessage = xml + " does not match " + encodingPattern;
      assertTrue(encodingErrorMessage, xml.matches(encodingPattern));
    }
  }
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.