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);
}
}
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());
}
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);
}
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;
}
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;
}
Aggregations