Package org.jboss.seam.mock

Examples of org.jboss.seam.mock.ResourceRequestEnvironment


   ResourceRequestEnvironment requestEnv;

   @BeforeClass
   public void prepareEnv() throws Exception
   {
      requestEnv = new ResourceRequestEnvironment(this)
      {
         @Override
         public Map<String, Object> getDefaultHeaders()
         {
            return new HashMap<String, Object>()


   }

   @Test(dataProvider = "queryPaths")
   public void testResourceQuery(String path) throws Exception
   {
      new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, "/restv1" + path)
      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {

   ResourceRequestEnvironment requestEnv;

   @BeforeClass
   public void prepareEnv() throws Exception
   {
      requestEnv = new ResourceRequestEnvironment(this)
      {
         @Override
         public Map<String, Object> getDefaultHeaders()
         {
            return new HashMap<String, Object>()

   @Test
   public void testCategories() throws Exception
   {

      // Just verify we can do that, even if it doesn't make much sense
      new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, "/restv1/category").run();
     
      reset();

      new ResourceRequest(requestEnv, Method.GET, "/restv1/category")
      {

   @Test
   public void testSubresourceGET() throws Exception
   {
      final String path = "/restv1/garage/1";

      new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, path)
      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {

   public void testResourceHomeRead(final String resourcePath) throws Exception
   {
      final String expectedResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><category><categoryId>1</categoryId><name>Antiques</name></category>";
      final String path = "/restv1" + resourcePath + "/1";

      new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, path)
      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {

      final String name = "Airplanes";
      final String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><category><name>" + name + "</name></category>";
      final String mediaType = "application/xml";
      final String path = "/restv1" + resourcePath;

      new ResourceRequest(new ResourceRequestEnvironment(this), Method.POST, path)
      {
         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {
            super.prepareRequest(request);

   {
      final String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><category><categoryId>5</categoryId><name>" + resourcePath.hashCode() + "</name></category>";
      final String mediaType = "application/xml";
      final String path = "/restv1" + resourcePath + "/5";

      new ResourceRequest(new ResourceRequestEnvironment(this), Method.PUT, path)
      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {
            super.prepareRequest(request);
            request.setContentType(mediaType);
            request.addHeader("Content-Type", mediaType);
            request.setContent(body.getBytes());
         }

         @Override
         protected void onResponse(EnhancedMockHttpServletResponse response)
         {
            assertEquals(response.getStatus(), 204, "Unexpected response code.");
         }

      }.run();
     
      reset();

      new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, path)
      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {

   public void testResourceHomeDelete() throws Exception
   {

      final String path = "/restv1/configuredCategory/15004";

      new ResourceRequest(new ResourceRequestEnvironment(this), Method.DELETE, path)
      {

         @Override
         protected void onResponse(EnhancedMockHttpServletResponse response)
         {
            assertEquals(response.getStatus(), 204, "Unexpected response code.");
         }

      }.run();
     
      reset();
     
      new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, path)
      {

         @Override
         protected void prepareRequest(EnhancedMockHttpServletRequest request)
         {

   ResourceRequestEnvironment sharedEnvironment;
   @BeforeClass
   public void prepareSharedEnvironment() throws Exception
   {
      sharedEnvironment = new ResourceRequestEnvironment(this)
      {
         @Override
         public Map<String, Object> getDefaultHeaders()
         {
            return new HashMap<String, Object>()

TOP

Related Classes of org.jboss.seam.mock.ResourceRequestEnvironment

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.