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