Package com.gistlabs.mechanize.integration.test

Source Code of com.gistlabs.mechanize.integration.test.GoogleApiJsonIT

/**
* Copyright (C) 2012-2014 Gist Labs, LLC. (http://gistlabs.com)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.gistlabs.mechanize.integration.test;

import static org.junit.Assert.*;

import org.json.JSONException;
import org.junit.Test;

import com.gistlabs.mechanize.Mechanize;
import com.gistlabs.mechanize.document.html.HtmlDocument;
import com.gistlabs.mechanize.document.json.JsonDocument;
import com.gistlabs.mechanize.impl.MechanizeAgent;

/**
*
*/
public class GoogleApiJsonIT {
  String googleUrl = "https://www.googleapis.com/urlshortener/v1/url";
  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());
  }

  @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
    //String value = json.getRoot().find("analytics month countries#US count").getValue();
    //assertTrue(value, Integer.valueOf(value)>=1);
  }
}
TOP

Related Classes of com.gistlabs.mechanize.integration.test.GoogleApiJsonIT

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.