Examples of MechanizeAgent


Examples of com.gistlabs.mechanize.impl.MechanizeAgent

*/
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

Examples of com.gistlabs.mechanize.impl.MechanizeAgent

*/
public class GoogleSearchForMechanizeJavaIT {

  @Test
  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

Examples of com.gistlabs.mechanize.impl.MechanizeAgent

  String shortUrl = "http://goo.gl/daal8";
  String longUrl = "http://gistlabs.com/software/mechanize-for-java/";

  @Test
  public void testShortUrl() throws JSONException {
    Mechanize agent = new MechanizeAgent();
    HtmlDocument html = agent.get(shortUrl);
    assertEquals(longUrl, html.getUri());
  }
View Full Code Here

Examples of com.gistlabs.mechanize.impl.MechanizeAgent

    assertEquals(longUrl, html.getUri());
  }

  @Test
  public void testGoogleApi() throws JSONException {
    MechanizeAgent agent = new MechanizeAgent();
    JsonDocument json = agent.doRequest(googleUrl).add("shortUrl", shortUrl).add("projection", "FULL").get();
    //String debug = json.asString();

    assertEquals(longUrl, json.getRoot().find("longUrl").getValue());

    //FRAGILE TEST no longer works
View Full Code Here

Examples of com.gistlabs.mechanize.impl.MechanizeAgent

*/
public class AndroidJsonApiIT {

  @Test
  public void testAndroidJsonApiDemo() throws JSONException {
    Mechanize agent = new MechanizeAgent();
    JsonDocument page = (JsonDocument) agent.get("http://api.androidhive.info/contacts/");

    List<? extends JsonNode> contacts = page.getRoot().getChildren("contacts");
    assertNotNull(contacts);
    assertEquals("c200", contacts.get(0).getAttribute("id"));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.