Package com.google.gdata.client.analytics

Examples of com.google.gdata.client.analytics.DataQuery


  /**
   * Tests if a filter has already been set.
   */
  public void testUpdateQuery_filterIsSet() {
    String filter = "ga:visits>5";
    DataQuery dataQuery = TestUtil.getFilledDataQuery();
    dataQuery.setFilters(filter);

    queryManager.updateQuery(dataQuery);

    String expectedFilter = filter + ";";
    assertTrue(expectedFilter.equals(dataQuery.getFilters()));
  }
View Full Code Here


  /**
   * Tests getting the maximum filter list length.
   */
  public void testGetFilterMaxListSize() {
    DataQuery dataQuery = TestUtil.getFilledDataQuery();
    dataQuery.setStartDate("2005-01-01");
    dataQuery.setEndDate("2010-06-01");

    int numDays = DataQueryUtil.getNumberOfDays(dataQuery);
    int maxResults = 2000;
    int expectedValue = maxResults / numDays;

View Full Code Here

   * Tests getting the maximum character length.
   */
  public void testGetFilterMaxCharLength_noFilter() {
    int maxQueryLen = QueryManagerGroupImpl.MAX_QUERY_LEN;

    DataQuery dataQueryExpected = TestUtil.getFilledDataQuery();
    dataQueryExpected.setFilters("");
    int expectedSize = maxQueryLen - dataQueryExpected.getUrl().toString().length();

    DataQuery dataQueryTest = TestUtil.getFilledDataQuery();
    dataQueryTest.setFilters(null);

    assertEquals(expectedSize, queryManager.getFilterMaxCharLength(maxQueryLen, dataQueryTest));
  }
View Full Code Here

   * Tests getting the maximum character length.
   */
  public void testGetFilterMaxCharLength_withFilter() {
    int maxQueryLen = QueryManagerGroupImpl.MAX_QUERY_LEN;

    DataQuery dataQuery = TestUtil.getFilledDataQuery();
    dataQuery.setFilters("ga:source==google;");

    int expectedSize =  maxQueryLen - dataQuery.getUrl().toString().length();

    assertEquals(expectedSize, queryManager.getFilterMaxCharLength(maxQueryLen, dataQuery));
  }
View Full Code Here

  /**
   * Ensures the filters in the DataQuery remain intact.
   */
  public void testSetFilterMaxCharLength_preserveFilter() {
    String filters = "ga:source==foo;ga:visits>5;";
    DataQuery dataQuery = TestUtil.getFilledDataQuery();
    dataQuery.setFilters(filters);

    queryManager.getFilterMaxCharLength(2000, dataQuery);
    String result = dataQuery.getFilters();
    assertTrue(filters.equals(result));
  }
View Full Code Here

  /**
   * Tests initializing the table.
   */
  public void testInitTable() {

    DataQuery dataQuery = TestUtil.getFilledDataQuery();
    int numDays = DataQueryUtil.getNumberOfDays(dataQuery);

    List<String> dimensionValues = new ArrayList<String>(2);
    dimensionValues.add("/foo");
    dimensionValues.add("/bar");

    Results resultTable = new Results();
    resultTable.initTable(dataQuery, dimensionValues);

    String expectedDim = dataQuery.getDimensions();
    String resultDim = resultTable.getDimensionName();
    assertEquals(expectedDim, resultDim);

    assertEquals(numDays, resultTable.getNumCols());
    assertEquals(dimensionValues.size(), resultTable.getNumRows());
View Full Code Here

   * Creates and returns the default DataQuery.
   *
   * @return AnalyticsService to be used
   */
  private static DataQuery getDataQuery() {
    DataQuery query = null;
    try {
      // Create a query using the DataQuery Object.
      query = new DataQuery(new URL(
          "https://www.google.com/analytics/feeds/data"));
      query.setStartDate("2009-04-01");
      query.setEndDate("2009-04-30");
      query.setDimensions("ga:pageTitle,ga:pagePath");
      query.setMetrics("ga:visits,ga:pageviews");
      query.setSort("-ga:pageviews");
      query.setMaxResults(10);
      query.setIds(TABLE_ID);
    } catch (MalformedURLException e) {
      System.err.println("Error, malformed URL: " + e.getMessage());
      System.exit(-1);
    }
    return query;
View Full Code Here

  /**
   * Tests getting filtered queries.
   */
  public void testGetFilteredQueries() {

    DataQuery dataQueryTest = TestUtil.getFilledDataQuery();
    String dimensionName = "ga:landingPagePath";
    dataQueryTest.setDimensions(dimensionName);

    List<String> dimensionValues = new ArrayList<String>();
    String dimensionValue = "/foo";
    dimensionValues.add(dimensionValue);

    // Ensure list of filters is being set.
    queries = queryManager.getFilteredQueries(dataQueryTest, dimensionValues);
    assertNotNull(queries);
    assertNotNull(queries.getFilterList());
    assertEquals(dimensionValues.size(), queries.getFilterList().size());

    String expectedFilter = Filter.getEqualityFilter(dimensionName, dimensionValue);
    assertEquals(expectedFilter, queries.getFilterList().get(0));

    // Ensure query is updated.
    DataQuery resultQuery = queries.getFilteredQuery(0);

    DataQuery expectedQuery = TestUtil.getFilledDataQuery();
    expectedQuery.setDimensions(dimensionName);

    queryManager.updateQuery(expectedQuery);

    assertEquals(expectedQuery.getMaxResults(), resultQuery.getMaxResults());
    assertTrue(expectedQuery.getSort().equals(resultQuery.getSort()));

    String expectedDim = expectedQuery.getDimensions();
    String resultDim = resultQuery.getDimensions();
    assertTrue(expectedDim.equals(resultDim));
  }
View Full Code Here

  /**
   * Tests getting that getFiltered work in a loop.
   */
  public void testGetFilteredQueries_InALoop() {
    DataQuery dataQueryTest = TestUtil.getFilledDataQuery();
    String dimensionName = "ga:landingPagePath";
    dataQueryTest.setDimensions(dimensionName);

    List<String> dimensionValues = new ArrayList<String>();
    dimensionValues.add("/foo");
    dimensionValues.add("/bar");
    dimensionValues.add("/bat");

    queries = queryManager.getFilteredQueries(dataQueryTest, dimensionValues);

    DataQuery expectedQuery = TestUtil.getFilledDataQuery();
    expectedQuery.setDimensions(dimensionName);
    queryManager.updateQuery(expectedQuery);

    Iterator<String> dimValueIter = dimensionValues.iterator();
    while (queries.hasNext()) {

      String dimensionValue = dimValueIter.next();
      String expectedFilter = Filter.getEqualityFilter(dimensionName, dimensionValue);
      expectedQuery.setFilters(expectedFilter);

      DataQuery testQuery = queries.next();
      assertEquals(expectedQuery.getUrl().toString(), testQuery.getUrl().toString());
    }
  }
View Full Code Here

  /**
   * Tests updating the query.
   */
  public void testGetUpdatedQuery() {
    DataQuery query = TestUtil.getFilledDataQuery();
    queryManager.updateQuery(query);

    int maxResults = DataQueryUtil.getNumberOfDays(query);
    assertEquals(maxResults, query.getMaxResults());
    assertTrue("ga:date".equals(query.getSort()));
    assertTrue("ga:date".equals(query.getDimensions()));
    assertEquals(-1, query.getStartIndex());
  }
View Full Code Here

TOP

Related Classes of com.google.gdata.client.analytics.DataQuery

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.