Search in sources :

Example 26 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.

the class AxisSerializerTest method testSerialize.

@Test
public void testSerialize() throws SAXException, IOException {
    BatchJobMutateRequest mutate = new BatchJobMutateRequest();
    List<Operation> ops = Lists.newArrayList();
    Campaign campaign = new Campaign();
    campaign.setId(-1L);
    campaign.setName("Test campaign");
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    ops.add(new CampaignOperation(Operator.ADD, "ADD", campaign));
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Test ad group");
    adGroup.setCampaignId(campaign.getId());
    ops.add(new AdGroupOperation(Operator.ADD, "ADD", adGroup));
    mutate.setOperations(ops.toArray(new Operation[0]));
    AxisSerializer serializer = new AxisSerializer();
    StringWriter writer = new StringWriter();
    SerializationContext context = new SerializationContext(writer);
    context.setSendDecl(true);
    context.setPretty(true);
    serializer.serialize(mutate, context);
    String serializedRequest = writer.toString();
    assertNotNull("Serialized request is null", serializedRequest);
    String expectedSerializedRequest = CharStreams.toString(new InputStreamReader(AxisSerializerTest.class.getResourceAsStream("resources/BatchJobMutate.request.xml"), UTF_8));
    Diff diff = DiffBuilder.compare(expectedSerializedRequest).withTest(serializedRequest).checkForSimilar().build();
    assertFalse("Serialized request does not match expected XML", diff.hasDifferences());
}
Also used : SerializationContext(org.apache.axis.encoding.SerializationContext) BatchJobMutateRequest(com.google.api.ads.adwords.axis.utils.v201809.batchjob.BatchJobMutateRequest) InputStreamReader(java.io.InputStreamReader) Diff(org.xmlunit.diff.Diff) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Operation(com.google.api.ads.adwords.axis.v201809.cm.Operation) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) StringWriter(java.io.StringWriter) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation) Test(org.junit.Test)

Example 27 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.

the class ServiceQueryTest method testHasNextWithSpecifiedAdGroupBidLandscapePage.

/**
 * Tests using {@link ServiceQuery#hasNext(AdGroupBidLandscapePage)} to check if there is still a
 * next page.
 */
@Test
public void testHasNextWithSpecifiedAdGroupBidLandscapePage() {
    // First iteration. There are no previous pages.
    AdGroupBidLandscapePage page = null;
    assertTrue(serviceQuery.hasNext(page));
    // Make ad group bid landscape page contain 400 bid landscape points (200 per ad group bid
    // landscape point).
    int numBidLandscapePoints = 200;
    BidLandscapeLandscapePoint bidLandscapeLandscapePoint = new BidLandscapeLandscapePoint();
    List<BidLandscapeLandscapePoint> bidLandscapeLandscapePoints = new ArrayList<>();
    bidLandscapeLandscapePoints.addAll(Collections.nCopies(numBidLandscapePoints, bidLandscapeLandscapePoint));
    AdGroupBidLandscape bidLandscape = mock(AdGroupBidLandscape.class);
    when(bidLandscape.getLandscapePoints()).thenReturn(bidLandscapeLandscapePoints.toArray(new BidLandscapeLandscapePoint[0]));
    page = mock(AdGroupBidLandscapePage.class);
    when(page.getEntries()).thenReturn(new AdGroupBidLandscape[] { bidLandscape, bidLandscape });
    serviceQuery = new ServiceQuery.Builder().fields("Id", "Name").limit(0, 100).build();
    // 2 * 200 landscape points are greater than the page size that is 100.
    assertTrue(serviceQuery.hasNext(page));
    serviceQuery = new ServiceQuery.Builder().fields("Id", "Name").limit(0, 500).build();
    // 2 * 200 landscape points are less than the page size that is 500.
    assertFalse(serviceQuery.hasNext(page));
}
Also used : AdGroupBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidLandscapePage) ArrayList(java.util.ArrayList) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) AdGroupBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidLandscape) Test(org.junit.Test)

Example 28 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.

the class ProductPartitionNodeAdapter method createCriterionForRemove.

/**
 * Returns a new AdGroupCriterion configured for a REMOVE operation.
 *
 * @param node the node whose criterion should be removed
 * @param adGroupId the ad group ID of the criterion
 */
static AdGroupCriterion createCriterionForRemove(ProductPartitionNode node, long adGroupId) {
    Preconditions.checkNotNull(node, "Null node");
    AdGroupCriterion adGroupCriterion = new AdGroupCriterion();
    adGroupCriterion.setAdGroupId(adGroupId);
    adGroupCriterion.setCriterion(new ProductPartition());
    adGroupCriterion.getCriterion().setId(node.getProductPartitionId());
    return adGroupCriterion;
}
Also used : BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 29 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.

the class ProductPartitionNodeAdapter method createCriterionForSetBiddableUnit.

/**
 * Returns a new AdGroupCriterion configured for a SET operation that will set the criterion's
 * bid, tracking template, and custom parameters.
 *
 * @param node the node whose criterion should be updated
 * @param adGroupId the ad group ID of the criterion
 * @param biddingConfig the bidding strategy configuration of the criterion
 */
static AdGroupCriterion createCriterionForSetBiddableUnit(ProductPartitionNode node, long adGroupId, BiddingStrategyConfiguration biddingConfig) {
    Preconditions.checkNotNull(node, "Null node");
    Preconditions.checkNotNull(biddingConfig, "Null bidding configuration");
    Preconditions.checkArgument(node.isBiddableUnit(), "Node is not a biddable unit");
    BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion();
    biddableCriterion.setAdGroupId(adGroupId);
    ProductPartition partition = new ProductPartition();
    partition.setId(node.getProductPartitionId());
    if (node.getParent() != null) {
        partition.setParentCriterionId(node.getParent().getProductPartitionId());
    }
    partition.setCaseValue(node.getDimension());
    partition.setPartitionType(ProductPartitionType.UNIT);
    biddableCriterion.setCriterion(partition);
    // Set the bidding attributes on the new ad group criterion.
    if (node.getBid() != null) {
        Money bidMoney = new Money();
        bidMoney.setMicroAmount(node.getBid());
        CpcBid cpcBid = new CpcBid();
        cpcBid.setBid(bidMoney);
        biddingConfig.setBids(new Bids[] { cpcBid });
    } else {
        biddingConfig.setBids(new Bids[0]);
    }
    biddableCriterion.setBiddingStrategyConfiguration(biddingConfig);
    // Set the upgraded URL attributes on the new ad group criterion.
    if (node.getTrackingUrlTemplate() != null) {
        biddableCriterion.setTrackingUrlTemplate(node.getTrackingUrlTemplate());
    }
    biddableCriterion.setUrlCustomParameters(createCustomParameters(node));
    return biddableCriterion;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 30 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.

the class ProductPartitionNodeAdapter method createCriterionForAdd.

/**
 * Returns a new AdGroupCriterion configured for an ADD operation.
 *
 * @param node the node whose criterion should be added
 * @param adGroupId the ad group ID of the criterion
 * @param biddingConfig the bidding strategy configuration of the criterion
 */
static AdGroupCriterion createCriterionForAdd(ProductPartitionNode node, long adGroupId, BiddingStrategyConfiguration biddingConfig) {
    Preconditions.checkNotNull(node, "Null node");
    Preconditions.checkNotNull(biddingConfig, "Null bidding configuration");
    AdGroupCriterion adGroupCriterion;
    if (node.isExcludedUnit()) {
        adGroupCriterion = new NegativeAdGroupCriterion();
    } else if (node.isBiddableUnit()) {
        BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion();
        if (node.getBid() != null) {
            Money bidMoney = new Money();
            bidMoney.setMicroAmount(node.getBid());
            CpcBid cpcBid = new CpcBid();
            cpcBid.setBid(bidMoney);
            cpcBid.setCpcBidSource(BidSource.CRITERION);
            biddingConfig.setBids(new Bids[] { cpcBid });
            biddableCriterion.setBiddingStrategyConfiguration(biddingConfig);
        }
        if (node.getTrackingUrlTemplate() != null) {
            biddableCriterion.setTrackingUrlTemplate(node.getTrackingUrlTemplate());
        }
        biddableCriterion.setUrlCustomParameters(createCustomParameters(node));
        adGroupCriterion = biddableCriterion;
    } else {
        adGroupCriterion = new BiddableAdGroupCriterion();
    }
    adGroupCriterion.setAdGroupId(adGroupId);
    ProductPartition partition = new ProductPartition();
    partition.setId(node.getProductPartitionId());
    if (node.getParent() != null) {
        partition.setParentCriterionId(node.getParent().getProductPartitionId());
    }
    partition.setCaseValue(node.getDimension());
    partition.setPartitionType(node.isUnit() ? ProductPartitionType.UNIT : ProductPartitionType.SUBDIVISION);
    adGroupCriterion.setCriterion(partition);
    return adGroupCriterion;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Aggregations

AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)20 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)19 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)16 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)16 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)15 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 ArrayList (java.util.ArrayList)14 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)13 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)12 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)12 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)12 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)10 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)10 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)9 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)9 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)7 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)7