Package com.gistlabs.mechanize

Examples of com.gistlabs.mechanize.Resource


    Mechanize agent = new MechanizeAgent();
    AbstractDocument page = agent.get("http://www.wikipedia.org");
    Form form = page.forms().find(".search-form");
    form.findSelect(byIdOrName("language")).getOption("de").select();
    form.findSearch(byIdOrName("search")).set("Angela Merkel");
    Resource response = form.findSubmitButton(byIdOrName("go")).submit();
    assertTrue(response.getTitle().startsWith("Angela Merkel"));
  }
View Full Code Here


public class ApacheImageCacheIT {

  @Test
  public void testCachedResource() throws JSONException, Exception {
    MechanizeAgent agent = new MechanizeAgent();
    Resource res1 = agent.get("http://apache.org/images/feather-small.gif");
    assertNull(res1.getResponse().getFirstHeader("Via"));

    Resource res2 = agent.get("http://apache.org/images/feather-small.gif");
    assertTrue(res2.getResponse().getFirstHeader("Via").getValue().indexOf("mechanize")>-1);

    assertEquals(date(res1), date(res2));

    // tweak response to shorten cache time
    res2.getResponse().setHeader("Cache-Control", "max-age=0;must-revalidate");
    res2.getResponse().removeHeaders("Expires");

    // check between the cache and HttpClient to make sure the response is 304 not modified
    agent.addFilter(new MechanizeChainFilter() {
      @Override
      public HttpResponse execute(final HttpUriRequest request, final HttpContext context, final MechanizeFilter chain) {
        HttpResponse response = chain.execute(request, context);
        assertEquals(304, response.getStatusLine().getStatusCode());
        return response;
      }
    });

    Resource res3 = agent.get("http://apache.org/images/feather-small.gif");
    assertTrue(res3.getResponse().getFirstHeader("Via").getValue().indexOf("mechanize")>-1);
  }
View Full Code Here

  public void testGooglePageSearchForm() {
    Mechanize agent = new MechanizeAgent();
    AbstractDocument page = agent.get("http://www.google.com");
    Form form = page.form("f");
    form.get("q").set("mechanize java");
    Resource response = form.submit();
    assertTrue(response.getTitle().startsWith("mechanize java"));
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public <T extends Resource> T request(final HttpRequestBase request) {
    try {
      HttpResponse response = execute(client, request);
      Resource resource = toPage(request, response);
      return (T)resource;
    } catch (Exception e) {
      throw MechanizeExceptionFactory.newException(e);
    }
  }
View Full Code Here

        newHtml("Test Page", newForm("form").id("form")));
    addPageRequest("http://test.com/form", newHtml("OK", ""));

    AbstractDocument page = agent().get("http://test.com");
    Form form = page.forms().find("#form");
    Resource response = form.submit();
    assertEquals("OK", response.getTitle());
    assertFalse(form.isDoPost());
  }
View Full Code Here

TOP

Related Classes of com.gistlabs.mechanize.Resource

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.