Search in sources :

Example 71 with Ad

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

the class ProductPartitionTreeTest method testCreateMultiNodeTreeFromScratch.

/**
 * Tests creating an empty tree and then adding several levels of nodes.
 */
@Test
public void testCreateMultiNodeTreeFromScratch() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
    ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
    ProductPartitionNode brand1Offer1 = brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L).putCustomParameter("param1", "value1").putCustomParameter("param2", "value2");
    ProductPartitionNode brand1Offer2 = brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
    ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
    int expectedOpCount = 5;
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", expectedOpCount, mutateOperations.size());
    List<CriterionDescriptor> nodeDescriptors = Stream.of(rootNode, brand1, brand1Offer1, brand1Offer2, brand2).map(CriterionDescriptor::new).collect(Collectors.toList());
    int opNum = 0;
    List<CriterionDescriptor> opDescriptors = Lists.newArrayList();
    Map<Long, CriterionDescriptor> opDescriptorsById = Maps.newHashMap();
    for (AdGroupCriterionOperation op : mutateOperations) {
        CriterionDescriptor opDescriptor = new CriterionDescriptor(op.getOperand(), opNum++);
        opDescriptors.add(opDescriptor);
        opDescriptorsById.put(opDescriptor.partitionId, opDescriptor);
    }
    Map<Long, Map<Long, CriterionDescriptor>> opDescriptorMap = buildDescriptorMap(opDescriptors);
    for (CriterionDescriptor nodeDescriptor : nodeDescriptors) {
        CriterionDescriptor opDescriptor = opDescriptorMap.get(nodeDescriptor.parentPartitionId).get(nodeDescriptor.partitionId);
        nodeDescriptor.assertDescriptorEquals(opDescriptor);
        AdGroupCriterionOperation op = mutateOperations.get(opDescriptor.operationNumber);
        assertEquals("operator is incorrect", Operator.ADD, op.getOperator());
        if (nodeDescriptor.parentPartitionId != null) {
            CriterionDescriptor parentOpDescriptor = opDescriptorsById.get(nodeDescriptor.parentPartitionId);
            assertNotNull("no operation found for parent", parentOpDescriptor);
            assertThat("operation # for parent is > operation # for child", opDescriptor.operationNumber, Matchers.greaterThan(parentOpDescriptor.operationNumber));
        }
    }
    assertThat("Tree toString does not contain the root's detailed toString", tree.toString(), Matchers.containsString(tree.getRoot().toDetailedString()));
    assertThat("Tree toString does not contain the ad group ID", tree.toString(), Matchers.containsString(tree.getAdGroupId().toString()));
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Map(java.util.Map) HashMap(java.util.HashMap) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

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