Search in sources :

Example 31 with Operation

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

the class ProductPartitionNodeAdapterTest method testCommonAttributes.

/**
 * Asserts that the attributes of {@code adGroupCriterion} match expectations.
 *
 * @param node the node from which the criterion was built
 * @param adGroupCriterion the criterion created by {@link ProductPartitionNodeAdapter}
 * @param isForRemove if true, this method will only check the attributes required for a REMOVE
 *        operation
 */
private void testCommonAttributes(ProductPartitionNode node, AdGroupCriterion adGroupCriterion, boolean isForRemove) {
    assertEquals("Ad group ID is incorrect", adGroupId, adGroupCriterion.getAdGroupId());
    Criterion criterion = adGroupCriterion.getCriterion();
    assertTrue("Criterion should be a ProductPartition", criterion instanceof ProductPartition);
    assertEquals("Partition ID is incorrect", node.getProductPartitionId(), criterion.getId());
    if (isForRemove) {
        assertEquals("Type of AdGroupCriterion for REMOVE should be the base class", AdGroupCriterion.class, adGroupCriterion.getClass());
        // The above checks suffice for REMOVE operations.
        return;
    }
    ProductPartition partition = (ProductPartition) criterion;
    assertEquals("The caseValue of the partition does not match the dimension of the node", 0, new ProductDimensionComparator().compare(partition.getCaseValue(), node.getDimension()));
    if (node.getParent() == null) {
        assertNull("Parent ID should be null", partition.getParentCriterionId());
    } else {
        assertEquals("Parent ID does not match ID of parent node", node.getParent().getProductPartitionId(), partition.getParentCriterionId());
    }
    if (node.isBiddableUnit()) {
        assertTrue("Biddable node should be translated into a BiddableAdGroupCriterion", adGroupCriterion instanceof BiddableAdGroupCriterion);
        BiddableAdGroupCriterion biddableCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
        BiddingStrategyConfiguration biddingStrategyConfig = biddableCriterion.getBiddingStrategyConfiguration();
        if (node.getBid() == null) {
            assertArrayEquals(new Bids[0], biddingStrategyConfig.getBids());
        } else {
            Bids bid = biddingStrategyConfig.getBids(0);
            assertTrue("Bid should be a CpcBid", bid instanceof CpcBid);
            CpcBid cpcBid = (CpcBid) bid;
            assertEquals("Bid amount is incorrect", node.getBid(), cpcBid.getBid().getMicroAmount());
            assertEquals("Partition is not a UNIT partition", ProductPartitionType.UNIT, partition.getPartitionType());
        }
        assertEquals("tracking URL template is incorrect", node.getTrackingUrlTemplate(), biddableCriterion.getTrackingUrlTemplate());
        // The adapter should always have a CustomParameters object, even if the node had no params.
        // This ensures that the parameters will be cleared (via doReplace=true) if all params were
        // removed from the node.
        CustomParameters customParameters = biddableCriterion.getUrlCustomParameters();
        assertNotNull("Biddable criterion does not have custom parameters", customParameters);
        assertEquals("doReplace for custom parameters should always be true", true, customParameters.getDoReplace());
        // Convert the BiddableAdGroupCriterion's custom parameters to a map to simplify comparison
        // against the node's custom parameter map.
        Map<String, String> actualCustomParameters = new HashMap<>();
        for (CustomParameter customParameter : customParameters.getParameters()) {
            actualCustomParameters.put(customParameter.getKey(), customParameter.getValue());
        }
        assertEquals("node and criterion do not have the same custom parameters", node.getCustomParameters(), actualCustomParameters);
    } else {
        assertTrue("Excluded node should be translated into a NegativeAdGroupCriterion", adGroupCriterion instanceof NegativeAdGroupCriterion);
    }
}
Also used : HashMap(java.util.HashMap) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) 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) 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) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) CustomParameter(com.google.api.ads.adwords.axis.v201809.cm.CustomParameter) CustomParameters(com.google.api.ads.adwords.axis.v201809.cm.CustomParameters) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Example 32 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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 33 with Operation

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

the class AxisBatchJobUploadBodyProviderTest method addCampaignOperation.

@Override
protected void addCampaignOperation(BatchJobMutateRequest request, long campaignId, String campaignName, String status, String advertisingChannelType, long budgetId, String biddingStrategyType, boolean enhancedCpcEnabled) {
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setName(campaignName);
    campaign.setStatus(CampaignStatus.fromString(status));
    campaign.setAdvertisingChannelType(AdvertisingChannelType.fromString(advertisingChannelType));
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.fromString(biddingStrategyType));
    ManualCpcBiddingScheme cpcBiddingScheme = new ManualCpcBiddingScheme();
    cpcBiddingScheme.setEnhancedCpcEnabled(enhancedCpcEnabled);
    biddingStrategyConfiguration.setBiddingScheme(cpcBiddingScheme);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) ManualCpcBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)

Example 34 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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 35 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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)

Aggregations

ArrayList (java.util.ArrayList)24 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)18 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)17 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)16 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)14 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)14 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)13 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)13 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)12 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)12 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)11 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)11 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)9 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)8 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)8 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)8 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)8