Package org.exoplatform.services.rest.tools

Examples of org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter


      groovyPublisher.publishPerRequest(script, new BaseResourceId("g1"), null);

      assertEquals(1, binder.getSize());
      assertEquals(1, groovyPublisher.resources.size());

      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();

      EnvironmentContext envctx = new EnvironmentContext();

      HttpServletRequest httpRequest =
         new MockHttpServletRequest("http://localhost:8080/context/a/b", null, 0, "GET", null);
      envctx.put(HttpServletRequest.class, httpRequest);

      ContainerResponse resp =
         launcher.service("GET", "http://localhost:8080/context/a/b", "http://localhost:8080/context", null, null,
            writer, envctx);
      assertEquals(200, resp.getStatus());
      assertEquals("GET\n/context/a/b", new String(writer.getBody()));
   }
View Full Code Here


   public void testProvidersPreference() throws Exception
   {
      applicationRegistry.addApplication(new Application2());
      // If StringEntityProvider1 override default reader/writer for String
      // then string must be in upper case in service's method.
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse resp = launcher.service("POST", "/abc", "", null, message.getBytes(), writer, null);
      assertEquals(200, resp.getStatus());
      // Must be returned in lower case.
      assertEquals(message.toLowerCase(), new String(writer.getBody()));
   }
View Full Code Here

   public void testReturn() throws Exception
   {
      Resource2 r2 = new Resource2();
      registry(r2);
      MultivaluedMap<String, String> h = new MultivaluedMapImpl();
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();

      h.putSingle("accept", "text/plain");
      ContainerResponse response = launcher.service("GET", "/bytes", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/octet-stream", response.getContentType().toString());
      assertEquals("to be or not to be".getBytes("UTF-8").length + "", response.getHttpHeaders().getFirst(
         HttpHeaders.CONTENT_LENGTH).toString());
      assertEquals("to be or not to be", new String(writer.getBody()));

      response = launcher.service("GET", "/string", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("text/plain", response.getContentType().toString());
      assertEquals("to be or not to be", new String(writer.getBody()));

      response = launcher.service("GET", "/stream", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/octet-stream", response.getContentType().toString());
      assertEquals("to be or not to be", new String(writer.getBody()));

      response = launcher.service("GET", "/reader", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("text/plain", response.getContentType().toString());
      assertEquals("to be or not to be", new String(writer.getBody()));

      Pattern pattern = Pattern.compile("(<\\?xml .*\\?>)");
      String xml = pattern.matcher(XML_DATA).replaceFirst("");

      h.putSingle("accept", "application/xml");
      response = launcher.service("GET", "/dom", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/xml", response.getContentType().toString());
      String result = new String(writer.getBody());
      result = pattern.matcher(result).replaceFirst("");
      assertEquals(xml, result);

      response = launcher.service("GET", "/sax", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/xml", response.getContentType().toString());
      result = new String(writer.getBody());
      result = pattern.matcher(result).replaceFirst("");
      assertEquals(xml, result);

      response = launcher.service("GET", "/ss", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/xml", response.getContentType().toString());
      result = new String(writer.getBody());
      result = pattern.matcher(result).replaceFirst("");
      assertEquals(xml, result);

      response = launcher.service("GET", "/so", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/octet-stream", response.getContentType().toString());
      assertEquals("to be or not to be", new String(writer.getBody()));

      response = launcher.service("GET", "/response", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("text/plain", response.getContentType().toString());
      assertEquals("to be or not to be".getBytes("UTF-8").length + "", response.getHttpHeaders().getFirst(
         HttpHeaders.CONTENT_LENGTH).toString());
      assertEquals("to be or not to be", new String(writer.getBody()));

      unregistry(r2);
   }
View Full Code Here

   }

   public void testReadSystemPropertyFail() throws Exception
   {
      groovyPublisher.publishPerRequest(script, new BaseResourceId("g1"), null);
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse resp = launcher.service("GET", "/a/b", "", null, null, writer, null);
      assertEquals(500, resp.getStatus());
      assertTrue((new String(writer.getBody()).toLowerCase()).startsWith("access denied"));
   }
View Full Code Here

      registry(r2);
      MultivaluedMap<String, String> h = new MultivaluedMapImpl();

      // Resource2#m1()
      h.putSingle("accept", "application/xml");
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse response = launcher.service("GET", "/", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/xml", response.getContentType().toString());
      Book book = (Book)response.getEntity();
      assertEquals("Hamlet", book.getTitle());
      assertEquals("William Shakespeare", book.getAuthor());
      assertTrue(book.isSendByPost());

      // Resource2#m2()
      writer = new ByteArrayContainerResponseWriter();
      response = launcher.service("POST", "/", "", h, null, writer, null);
      assertEquals(200, response.getStatus());
      assertEquals("application/xml", response.getContentType().toString());
      book = (Book)response.getEntity();
      assertEquals("Hamlet\n", book.getTitle());
View Full Code Here

         groovyPublisher.publishPerRequest(script, resourceId, null);

      assertEquals(1, binder.getSize());
      assertEquals(1, groovyPublisher.resources.size());

      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse resp = launcher.service("GET", "/a/b", "", null, null, writer, null);
      assertEquals(200, resp.getStatus());
      assertEquals("exo container's component", new String(writer.getBody()));
   }
View Full Code Here

      String cs =
         binder.getResources().get(0).getObjectModel().getObjectClass().getProtectionDomain().getCodeSource()
            .getLocation().toString();
      assertEquals("file:/groovy/script/jaxrs", cs);

      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse resp = launcher.service("GET", "/a/groovy", "", null, null, writer, null);
      assertEquals(200, resp.getStatus());
      assertEquals("hello groovy", new String(writer.getBody()));

      groovyPublisher.unpublishResource(resourceId);

      assertEquals(0, binder.getSize());
      assertEquals(0, groovyPublisher.resources.size());
View Full Code Here

   }

   public void testDependency() throws Exception
   {
      groovyPublisher.publishPerRequest(script, new BaseResourceId("GMain1"), null);
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse resp = launcher.service("GET", "/a", "", null, null, writer, null);
      assertEquals(200, resp.getStatus());
      assertEquals("dependencies.Dep1", new String(writer.getBody()));
   }
View Full Code Here

      super.tearDown();
   }

   public void testErrorResponse() throws Exception
   {
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse response = launcher.service("GET", "/a/4", "", null, null, writer, null);
      assertEquals(500, response.getStatus());
      String entity = new String(writer.getBody());
      assertEquals(errorMessage, entity);
      assertNotNull(response.getHttpHeaders().getFirst(ExtHttpHeaders.JAXRS_BODY_PROVIDED));
   }
View Full Code Here

      assertNotNull(response.getHttpHeaders().getFirst(ExtHttpHeaders.JAXRS_BODY_PROVIDED));
   }

   public void testUncheckedException() throws Exception
   {
      ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
      ContainerResponse response = launcher.service("GET", "/a/3", "", null, null, writer, null);
      assertEquals(500, response.getStatus());
      String entity = new String(writer.getBody());
      assertEquals(errorMessage, entity);
      assertNotNull(response.getHttpHeaders().getFirst(ExtHttpHeaders.JAXRS_BODY_PROVIDED));
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter

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.