Package com.google.api.ads.adwords.axis.v201309.cm

Examples of com.google.api.ads.adwords.axis.v201309.cm.Selector


  @Test
  public void testOrderByBuild() {
    SelectorBuilder builder = new SelectorBuilder();

    builder = builder.orderAscBy("AverageCpm");
    Selector selector = builder.build();

    Assert.assertNotNull(selector.getOrdering());
    Assert.assertEquals(1, selector.getOrdering().length);

    OrderBy orderBy = selector.getOrdering()[0];

    Assert.assertEquals("AverageCpm", orderBy.getField());
    Assert.assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());

    builder.orderAscBy("AverageCpm").orderDescBy("AverageCpc");
    selector = builder.build();

    Assert.assertNotNull(selector.getOrdering());
    Assert.assertEquals(2, selector.getOrdering().length);

    orderBy = selector.getOrdering()[0];

    Assert.assertEquals("AverageCpm", orderBy.getField());
    Assert.assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());

    orderBy = selector.getOrdering()[1];

    Assert.assertEquals("AverageCpc", orderBy.getField());
    Assert.assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());

    selector = builder.removeOrderBy("AverageCpm").build();

    Assert.assertNotNull(selector.getOrdering());
    Assert.assertEquals(1, selector.getOrdering().length);

    orderBy = selector.getOrdering()[0];

    Assert.assertEquals("AverageCpc", orderBy.getField());
    Assert.assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());

  }
View Full Code Here


    DateTime end = new DateTime(2013, 3, 26, 0, 0, 0, 0);
    String formatStart = dateFormat.format(start.toDate());
    String formatEnd = dateFormat.format(end.toDate());

    builder = builder.forDateRange(start, end);
    Selector selector = builder.build();

    Assert.assertEquals(selector.getDateRange().getMin(), formatStart);
    Assert.assertEquals(selector.getDateRange().getMax(), formatEnd);
  }
View Full Code Here

  @Test
  public void testPagingAndLimits() {
    SelectorBuilder builder = new SelectorBuilder();

    builder = builder.offset(10);
    Selector selector = builder.build();

    Assert.assertNotNull(selector.getPaging());
    Assert.assertNotNull(selector.getPaging().getStartIndex());
    Assert.assertNull(selector.getPaging().getNumberResults());
    Assert.assertEquals(selector.getPaging().getStartIndex().intValue(), 10);

    selector = builder.offset(10).limit(20).build();

    Assert.assertNotNull(selector.getPaging());
    Assert.assertNotNull(selector.getPaging().getStartIndex());
    Assert.assertNotNull(selector.getPaging().getNumberResults());
    Assert.assertEquals(selector.getPaging().getStartIndex().intValue(), 10);
    Assert.assertEquals(selector.getPaging().getNumberResults().intValue(), 20);

    selector = builder.offset(10).limit(20).increaseOffsetBy(5).build();

    Assert.assertNotNull(selector.getPaging());
    Assert.assertNotNull(selector.getPaging().getStartIndex());
    Assert.assertNotNull(selector.getPaging().getNumberResults());
    Assert.assertEquals(selector.getPaging().getStartIndex().intValue(), 15);
    Assert.assertEquals(selector.getPaging().getNumberResults().intValue(), 20);

    selector = builder.offset(10).limit(20).increaseOffsetBy(5).removeLimitAndOffset().build();

    Assert.assertNull(selector.getPaging());

    selector = builder.offset(10)
        .limit(20)
        .increaseOffsetBy(5)
        .removeLimitAndOffset()
        .offset(55)
        .limit(4)
        .build();

    Assert.assertNotNull(selector.getPaging());
    Assert.assertNotNull(selector.getPaging().getStartIndex());
    Assert.assertNotNull(selector.getPaging().getNumberResults());
    Assert.assertEquals(selector.getPaging().getStartIndex().intValue(), 55);
    Assert.assertEquals(selector.getPaging().getNumberResults().intValue(), 4);

  }
View Full Code Here

   * Tests that the built selectors don't share internal Paging state.
   */
  @Test
  public void testUniqueInternalPagingState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.fields("Id").offset(10).build();
    Selector selectorTwo = builder.fields("Status").offset(345).build();

    Assert.assertEquals(10, selectorOne.getPaging().getStartIndex().intValue());
    Assert.assertEquals(345, selectorTwo.getPaging().getStartIndex().intValue());
  }
View Full Code Here

   * Tests that the built selectors don't share internal OrderBy state.
   */
  @Test
  public void testUniqueInternalOrderByState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.orderAscBy("Id").build();
    Selector selectorTwo = builder.build();

    OrderBy orderTwo = selectorTwo.getOrdering(0);
    orderTwo.setField("Status");

    Assert.assertEquals("Id", selectorOne.getOrdering(0).getField());
    Assert.assertEquals("Status", selectorTwo.getOrdering(0).getField());
  }
View Full Code Here

   * Tests that the built selectors don't share internal Predicate state.
   */
  @Test
  public void testUniqueInternalPredicateState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.by("Id", "test").build();
    Selector selectorTwo = builder.build();

    Predicate predicateTwo = selectorTwo.getPredicates(0);
    predicateTwo.setField("Status");

    Assert.assertEquals("Id", selectorOne.getPredicates(0).getField());
    Assert.assertEquals("Status", selectorTwo.getPredicates(0).getField());
  }
View Full Code Here

    DateTime startOne = new DateTime(2013, 1, 1, 0, 0, 0, 0);
    DateTime endOne = new DateTime(2013, 1, 31, 0, 0, 0, 0);
    DateTime startTwo = new DateTime(2013, 2, 1, 0, 0, 0, 0);
    DateTime endTwo = new DateTime(2013, 2, 28, 0, 0, 0, 0);

    Selector selectorOne = builder.forDateRange(startOne, endOne).build();
    Selector selectorTwo = builder.forDateRange(startTwo, endTwo).build();

    Assert.assertEquals(dateFormat.format(startOne.toDate()), selectorOne.getDateRange().getMin());
    Assert.assertEquals(dateFormat.format(endOne.toDate()), selectorOne.getDateRange().getMax());
    Assert.assertEquals(dateFormat.format(startTwo.toDate()), selectorTwo.getDateRange().getMin());
    Assert.assertEquals(dateFormat.format(endTwo.toDate()), selectorTwo.getDateRange().getMax());
  }
View Full Code Here

        adWordsServices.get(session, CampaignServiceInterface.class);

    int offset = 0;

    // Create selector.
    Selector selector = new Selector();
    selector.setFields(new String[] {"Id", "Name"});
    selector.setOrdering(new OrderBy[] {new OrderBy("Name", SortOrder.ASCENDING)});
    selector.setPaging(new Paging(offset, PAGE_SIZE));

    CampaignPage page = null;
    do {
      // Get all campaigns.
      page = campaignService.get(selector);

      // Display campaigns.
      if (page.getEntries() != null) {
        for (Campaign campaign : page.getEntries()) {
          System.out.println("Campaign with name \"" + campaign.getName() + "\" and id \""
              + campaign.getId() + "\" was found.");
        }
      } else {
        System.out.println("No campaigns were found.");
      }

      offset += PAGE_SIZE;
      selector.getPaging().setStartIndex(offset);
    } while (offset < page.getTotalNumEntries());
  }
View Full Code Here

    int offset = 0;
    boolean morePages = true;

    // Create selector.
    Selector selector = new Selector();
    selector.setFields(new String[] {"Id", "AdGroupId", "MatchType", "KeywordText"});
    selector.setOrdering(new OrderBy[] {new OrderBy("AdGroupId", SortOrder.ASCENDING)});
    selector.setPaging(new Paging(offset, PAGE_SIZE));

    // Create predicates.
    Predicate adGroupIdPredicate =
        new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
    Predicate criteriaTypePredicate =
        new Predicate("CriteriaType", PredicateOperator.EQUALS, new String[] {"KEYWORD"});
    selector.setPredicates(new Predicate[] {adGroupIdPredicate, criteriaTypePredicate});

    while (morePages) {
      // Get all ad group criteria.
      AdGroupCriterionPage page = adGroupCriterionService.get(selector);

      // Display ad group criteria.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        // Display results.
        for (AdGroupCriterion adGroupCriterionResult : page.getEntries()) {
          System.out.println("Keyword ad group criterion with ad group id \""
              + adGroupCriterionResult.getAdGroupId() + "\", criterion id \""
              + adGroupCriterionResult.getCriterion().getId() + "\", text \""
              + ((Keyword) adGroupCriterionResult.getCriterion()).getText()
              + "\" and match type \""
              + ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType() + "\" was found.");
        }
      } else {
        System.out.println("No ad group criteria were found.");
      }

      offset += PAGE_SIZE;
      selector.getPaging().setStartIndex(offset);
      morePages = offset < page.getTotalNumEntries();
    }
  }
View Full Code Here

   * to clean the builder, the best way to do it, is by creating a new instance.
   *
   * @return the new Selector containing all the configuration that was set previously.
   */
  public Selector build() {
    Selector selectorCopy = new Selector();

    Set<OrderBy> orderingCopy = this.copyOrderingSet();
    Set<Predicate> predicatesCopy = this.copyPredicatesSet();

    selectorCopy.setFields(this.fields.toArray(new String[this.fields.size()]));
    selectorCopy.setOrdering(orderingCopy.toArray(new OrderBy[this.ordering.size()]));
    selectorCopy.setPredicates(predicatesCopy.toArray(new Predicate[this.predicates.size()]));

    if (this.dateRange != null) {
      selectorCopy.setDateRange(new DateRange(this.dateRange.getMin(), this.dateRange.getMax()));
    }
    if (this.paging != null) {
      selectorCopy.setPaging(
          new Paging(this.paging.getStartIndex(), this.paging.getNumberResults()));
    }

    return selectorCopy;
  }
View Full Code Here

TOP

Related Classes of com.google.api.ads.adwords.axis.v201309.cm.Selector

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.