Search in sources :

Example 1 with ProductPartition

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

the class ProductPartitionTreeTest method testCreateUltimatelyEmptyTree.

/**
 * Tests creating a tree that in its <em>final</em> state is just an empty tree.
 */
@Test
public void testCreateUltimatelyEmptyTree() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
    ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
    brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L);
    brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
    ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
    // Now remove the two child nodes under the root and set the root back to a UNIT. This should
    // result in operations that simply create the root node.
    rootNode.removeChild(brand1.getDimension());
    rootNode.removeChild(brand2.getDimension());
    rootNode = rootNode.asBiddableUnit();
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", 1, mutateOperations.size());
    AdGroupCriterionOperation operation = mutateOperations.iterator().next();
    assertEquals("Should have a single operation to ADD the root node", Operator.ADD, operation.getOperator());
    BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion) operation.getOperand();
    assertNull("Product dimension of operation's operand should be null", ((ProductPartition) adGroupCriterion.getCriterion()).getCaseValue());
    assertTrue("Partition ID of the operand should be negative", adGroupCriterion.getCriterion().getId().longValue() < 0L);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 2 with ProductPartition

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

the class ProductPartitionTreeTest method testCreateEmptyTree.

/**
 * Tests creating an empty ad group tree. In this case, all operations generated should be ADD
 * operations.
 */
@Test
public void testCreateEmptyTree() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    assertNotNull("Even an empty tree should automatically have a root node", tree.getRoot());
    assertTrue("The root node for an empty tree should have a negative (temporary) ID", tree.getRoot().getProductPartitionId().longValue() < 0L);
    assertTrue("The root node for an empty tree should be a UNIT", tree.getRoot().isUnit());
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", 1, mutateOperations.size());
    AdGroupCriterionOperation operation = mutateOperations.iterator().next();
    assertEquals("Should have a single operation to ADD the root node", Operator.ADD, operation.getOperator());
    BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion) operation.getOperand();
    assertNull("Product dimension of operation's operand should be null", ((ProductPartition) adGroupCriterion.getCriterion()).getCaseValue());
    assertTrue("Partition ID of the operand should be negative", adGroupCriterion.getCriterion().getId().longValue() < 0L);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 3 with ProductPartition

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

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

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

BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)9 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)7 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)6 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)3 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)3 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)3 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)2 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)2 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)2 Test (org.junit.Test)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdGroupCriterionPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionPage)1 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)1 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)1 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)1 CustomParameter (com.google.api.ads.adwords.axis.v201809.cm.CustomParameter)1 CustomParameters (com.google.api.ads.adwords.axis.v201809.cm.CustomParameters)1 AdGroupCriterionField (com.google.api.ads.adwords.lib.selectorfields.v201809.cm.AdGroupCriterionField)1 HashMap (java.util.HashMap)1