Package com.gistlabs.mechanize.impl

Examples of com.gistlabs.mechanize.impl.MechanizeAgent


*/
public class CookiesTest {

  @Test
  public void testCookieRepresentiveIsTheSame() {
    Mechanize agent = new MechanizeAgent();
    Cookie cookie = agent.cookies().addNewCookie("ID", "Value", ".test.com");
    assertSame(cookie, agent.cookies().get("ID", ".test.com"));
    assertSame(cookie, agent.cookies().get("ID", ".test.com"));
  }
View Full Code Here


    assertSame(cookie, agent.cookies().get("ID", ".test.com"));
  }

  @Test
  public void testRemovingASingleCookie() {
    Mechanize agent = new MechanizeAgent();
    Cookie cookie1 = agent.cookies().addNewCookie("ID", "MyID", ".wikipedia.org");
    Cookie cookie2 = agent.cookies().addNewCookie("ID2", "MySecondID", "wikipedia.org");

    agent.cookies().remove(cookie1);
    assertFalse(agent.cookies().getAll().contains(cookie1));
    assertTrue(agent.cookies().getAll().contains(cookie2));
  }
View Full Code Here

*/
public class MechanizeAgentIntTest extends MechanizeTestCase {
  static final String firefoxUserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.1) Gecko/20100122 firefox/3.6.1";

  protected Mechanize agent() {
    return new MechanizeAgent().setUserAgent(firefoxUserAgent);
  }
View Full Code Here

  //@org.junit.Test
  public void testRedirect() throws IOException {
    String username = "";
    String password = "";
    Mechanize agent = new MechanizeAgent(buildClient());

    String manageKindleUrl = "http://www.amazon.com/gp/digital/fiona/manage/ref=gno_yam_myk";
    AbstractDocument signinPage = agent.get(manageKindleUrl);

    debug(signinPage);

    Form form = signinPage.forms().get(0);
    form.get("email").setValue(username);
View Full Code Here

*/
public class WikipediaSearchForAngelaMerkelAndDownloadingImagesIT {

  @Test
  public void testLoadWikipediaIndexPage() {
    Mechanize agent = new MechanizeAgent();
    AbstractDocument page = agent.get("http://www.wikipedia.org");
    assertNotNull(page);
    assertTrue(page.size() > 10000);
    Links links = page.links();
    assertTrue(links.size() > 10);
    assertNotNull(links.find("*[title*='English']"));
 
View Full Code Here

    assertNotNull(links.find("*[title*='English']"));
  }

  @Test
  public void testClickingEnglishWikipediaVersionLink() {
    Mechanize agent = new MechanizeAgent();
    AbstractDocument page = agent.get("http://www.wikipedia.org");
    assertNotNull(page);
    assertTrue(page.size() > 10000);
    Links links = page.links();
    assertTrue(links.size() > 10);
    Link link = links.find("*[title*='English']");
 
View Full Code Here

    assertEquals("Wikipedia, the free encyclopedia", englishPage.getTitle());
  }

  @Test
  public void testSearchingWikipediaForAngelaMerkelInGermanLanguageUtilizingSelectAndTextInput() {
    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

* @author Martin Kersten<Martin.Kersten.mk@gmail.com>
*/
public class CookiesTest {
  //@Test // no longer working
  public void xtestWikipediaSendsNoCookies() {
    Mechanize agent = new MechanizeAgent();

    agent.get("http://www.wikipedia.org");
    assertEquals(0, agent.cookies().getCount());
  }
View Full Code Here


  /** Tests if google stores two cookies. It uses a special link to prevent google form choosing a different homepage depending on the ip being used. */
  @Test
  public void testGoogleComSendsTwoCookies() {
    MechanizeAgent agent = new MechanizeAgent();

    agent.
    doRequest("https://www.google.co.uk/setprefdomain?prefdom=US&sig=0_iEtQ0487gjqkcvDjBk5XCH1G_WU%3D").
    addHeader("Accept-Language", "en-US").
    get();
    assertEquals(2, agent.cookies().getCount());
    assertNotNull(agent.cookies().get("NID", ".google.co.uk"));
    assertNotNull(agent.cookies().get("PREF", ".google.co.uk"));
  }
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

TOP

Related Classes of com.gistlabs.mechanize.impl.MechanizeAgent

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.