/**
  * Uses a parser to build a JDom document from the response stream.
  *
  * @param webResponse
  * @return the JDom document
  * @throws IOException
  * @throws JDOMException
  */
 protected Document createDocumentFromResponse(WebResponse webResponse)
     throws IOException, JDOMException {
   InputStream responseStream = null;
   try {
     SAXBuilder builder = new SAXBuilder();
     responseStream = webResponse.getInputStream();
     return builder.build(responseStream);
   } finally {
     if (responseStream != null) {
       responseStream.close();
     }
   }
 }
Example #2
0
  public static void outputImageMatchesBaseline(
      final WebResponse response, final String baselineImage) throws IOException {
    final File baseline = new File(baselineImage);

    assertTrue(baseline.exists());

    log.debug("Response content length: " + response.getContentLength());

    Raster raster = GDALUtils.toRaster(GDALUtils.open(response.getInputStream()));
    Assert.assertNotNull("Test Image: not loaded, could not read stream", raster);

    TestUtils.compareRasters(baseline, raster);
  }
Example #3
0
  public void testWSDL() throws Exception {
    WebConversation conversation = new WebConversation();
    String destination = testProps.getProperty("destination");
    if (destination != null && destination.length() > 0) {
      WebRequest request = new GetMethodWebRequest(destination + "?WSDL");

      WebResponse response = conversation.getResponse(request);

      int i = response.getContentLength();
      InputSource is = new InputSource(response.getInputStream());

      Document doc = builder.parse(is);

      doc.getDocumentElement();
      System.out.println("My test");
    }
  }
  @Test
  public void testTransferException() throws Exception {
    WebRequest req =
        new PostMethodWebRequest(
            CONTEXT_URL + "/services/hello", new ByteArrayInputStream("".getBytes()), "text/plain");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);

    assertEquals(500, response.getResponseCode());
    assertEquals(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, response.getContentType());
    Object object = HttpHelper.deserializeJavaObjectFromStream(response.getInputStream());
    assertNotNull(object);

    IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, object);
    assertEquals("Damn", cause.getMessage());
  }
 /** Verifies the proxified reception of the default Bob and Alice diagram */
 public void testDefaultProxy() throws Exception {
   WebConversation conversation = new WebConversation();
   WebRequest request =
       new GetMethodWebRequest(
           getServerUrl() + "proxy/" + getServerUrl() + "resource/test2diagrams.txt");
   WebResponse response = conversation.getResource(request);
   // Analyze response
   // Verifies the Content-Type header
   // assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
   // Get the image and verify its size (~2000 bytes)
   InputStream responseStream = response.getInputStream();
   ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
   byte[] buf = new byte[1024];
   int n = 0;
   while ((n = responseStream.read(buf)) != -1) {
     imageStream.write(buf, 0, n);
   }
   imageStream.close();
   responseStream.close();
   byte[] inMemoryImage = imageStream.toByteArray();
   int diagramLen = inMemoryImage.length;
   assertTrue(diagramLen > 1500);
   assertTrue(diagramLen < 2500);
 }
Example #6
0
 public static void writeBaselineImage(final WebResponse response, final String path)
     throws IOException {
   writeBaselineImage(response.getInputStream(), path);
 }