@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());
  }
  /**
   * @param query to search for.
   * @param attrs attributes to return from search
   * @param ldifFile to compare with
   * @throws Exception On test failure.
   */
  @Parameters({"searchServletQuery", "searchServletAttrs", "searchServletLdif"})
  @Test(groups = {"servlettest"})
  public void dsmlSearchServlet(final String query, final String attrs, final String ldifFile)
      throws Exception {
    final String ldif = TestUtil.readFileIntoString(ldifFile);
    final DsmlResult entry = new DsmlResult(TestUtil.convertLdifToEntry(ldif));

    final ServletUnitClient sc = this.dsmlServletRunner.newClient();
    // test basic dsml query
    WebRequest request =
        new PostMethodWebRequest("http://servlets.search.ldap.middleware.vt.edu/DsmlPeopleSearch");
    request.setParameter("query", query);
    request.setParameter("attrs", attrs.split("\\|"));

    WebResponse response = sc.getResponse(request);

    AssertJUnit.assertNotNull(response);
    AssertJUnit.assertEquals("text/xml", response.getContentType());
    AssertJUnit.assertEquals(entry.toDsmlv1(), response.getText());

    // test plain text
    request =
        new PostMethodWebRequest("http://servlets.search.ldap.middleware.vt.edu/DsmlPeopleSearch");
    request.setParameter("content-type", "text");
    request.setParameter("query", query);
    request.setParameter("attrs", attrs.split("\\|"));
    response = sc.getResponse(request);

    AssertJUnit.assertNotNull(response);
    AssertJUnit.assertEquals("text/plain", response.getContentType());
    AssertJUnit.assertEquals(entry.toDsmlv1(), response.getText());

    // test dsmlv2
    request =
        new PostMethodWebRequest("http://servlets.search.ldap.middleware.vt.edu/DsmlPeopleSearch");
    request.setParameter("dsml-version", "2");
    request.setParameter("query", query);
    request.setParameter("attrs", attrs.split("\\|"));
    response = sc.getResponse(request);

    AssertJUnit.assertNotNull(response);
    AssertJUnit.assertEquals("text/xml", response.getContentType());
    AssertJUnit.assertEquals(entry.toDsmlv2(), response.getText());
  }
  protected void initServlet(String webXml) throws Exception {
    ServletRunner runner = new ServletRunner(new File(srcdir, webXml), "");
    client = runner.newClient();
    ic = client.newInvocation("http://localhost:8080/app1");

    originalServletContext = ic.getServlet().getServletConfig().getServletContext();
    servletContext = createServletContextWrapper(true);
    request = ic.getRequest();
    response = ic.getResponse();
  }
  /**
   * @param query to search for.
   * @param attrs attributes to return from search
   * @param ldifFile to compare with
   * @throws Exception On test failure.
   */
  @Parameters({"searchServletQuery", "searchServletAttrs", "searchServletLdif"})
  @Test(groups = {"servlettest"})
  public void searchServlet(final String query, final String attrs, final String ldifFile)
      throws Exception {
    final String ldif = TestUtil.readFileIntoString(ldifFile);
    final LdapEntry entry = TestUtil.convertLdifToEntry(ldif);

    final ServletUnitClient sc = this.ldifServletRunner.newClient();
    final WebRequest request =
        new PostMethodWebRequest("http://servlets.search.ldap.middleware.vt.edu/LdifPeopleSearch");
    request.setParameter("query", query);
    request.setParameter("attrs", attrs.split("\\|"));

    final WebResponse response = sc.getResponse(request);

    AssertJUnit.assertNotNull(response);
    AssertJUnit.assertEquals("text/plain", response.getContentType());

    final LdapEntry result = TestUtil.convertLdifToEntry(response.getText());
    AssertJUnit.assertEquals(entry, result);
  }
 protected String doTest() throws IOException, SAXException {
   ServletUnitClient sc = sr.newClient();
   WebRequest request = new GetMethodWebRequest("http://incongru.net/empty");
   WebResponse response = sc.getResponse(request);
   return response.getText();
 }