Ejemplo n.º 1
0
  /**
   * @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());
  }
Ejemplo n.º 2
0
  /**
   * @param ldifFile to create.
   * @param webXml web.xml for queries
   * @throws Exception On test failure.
   */
  @Parameters({"createEntry10", "webXml"})
  @BeforeClass(groups = {"servlettest"})
  public void createLdapEntry(final String ldifFile, final String webXml) throws Exception {
    final String ldif = TestUtil.readFileIntoString(ldifFile);
    testLdapEntry = TestUtil.convertLdifToEntry(ldif);

    Ldap ldap = TestUtil.createSetupLdap();
    ldap.create(testLdapEntry.getDn(), testLdapEntry.getLdapAttributes().toAttributes());
    ldap.close();
    ldap = TestUtil.createLdap();
    while (!ldap.compare(
        testLdapEntry.getDn(), new SearchFilter(testLdapEntry.getDn().split(",")[0]))) {
      Thread.sleep(100);
    }
    ldap.close();

    this.ldifServletRunner = new ServletRunner(new File(webXml));
    this.dsmlServletRunner = new ServletRunner(new File(webXml));
  }
Ejemplo n.º 3
0
  /**
   * @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);
  }
Ejemplo n.º 4
0
 /** @throws Exception On test failure. */
 @AfterClass(groups = {"servlettest"})
 public void deleteLdapEntry() throws Exception {
   final Ldap ldap = TestUtil.createSetupLdap();
   ldap.delete(testLdapEntry.getDn());
   ldap.close();
 }