Search in sources :

Example 1 with ProductBrand

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

the class ProductPartitionTreeTest method testMutateMultiNodeTree.

/**
 * Tests mutating an existing tree with multiple nodes.
 */
@Test
public void testMutateMultiNodeTree() {
    List<AdGroupCriterion> adGroupCriteria = Lists.newArrayList();
    List<CriterionDescriptor> descriptors = Lists.newArrayList();
    descriptors.add(new CriterionDescriptor(false, false, null, null, 1L, null));
    ProductBrand brandGoogle = ProductDimensions.createBrand("google");
    descriptors.add(new CriterionDescriptor(false, false, brandGoogle, null, 2L, 1L));
    descriptors.add(new CriterionDescriptor(true, false, ProductDimensions.createOfferId("A"), 1000000L, 3L, 2L));
    Long offerBOriginalPartitionId = 4L;
    descriptors.add(new CriterionDescriptor(true, true, ProductDimensions.createOfferId("B"), null, offerBOriginalPartitionId, 2L));
    Long brandOtherOriginalPartitionId = 5L;
    descriptors.add(new CriterionDescriptor(true, true, ProductDimensions.createBrand(null), null, brandOtherOriginalPartitionId, 1L));
    ProductBrand brandMotorola = ProductDimensions.createBrand("motorola");
    Long brandMotorolaOriginalPartitionId = 6L;
    descriptors.add(new CriterionDescriptor(true, true, brandMotorola, null, brandMotorolaOriginalPartitionId, 1L));
    descriptors.forEach(descriptor -> adGroupCriteria.add(descriptor.createCriterion()));
    Map<Long, Map<Long, CriterionDescriptor>> descriptorMap = buildDescriptorMap(descriptors);
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, adGroupCriteria);
    assertEquals("ad group ID is incorrect", -1L, tree.getAdGroupId().longValue());
    Queue<ProductPartitionNode> nodes = Lists.newLinkedList();
    nodes.add(tree.getRoot());
    int nodesFound = 0;
    while (!nodes.isEmpty()) {
        ProductPartitionNode node = nodes.remove();
        Long parentId = node.getParent() == null ? null : node.getParent().getProductPartitionId();
        CriterionDescriptor expectedDescriptor = descriptorMap.get(parentId).get(node.getProductPartitionId());
        CriterionDescriptor actualDescriptor = new CriterionDescriptor(node);
        expectedDescriptor.assertDescriptorEquals(actualDescriptor);
        // Add children to process.
        Iterables.addAll(nodes, node.getChildren());
        nodesFound++;
    }
    assertEquals("Tree does not contain the expected # of nodes", adGroupCriteria.size(), nodesFound);
    // Change the bids on leaf nodes.
    ProductPartitionNode brandGoogleNode = tree.getRoot().getChild(brandGoogle);
    ProductPartitionNode offerANode = brandGoogleNode.getChild(ProductDimensions.createOfferId("A"));
    // This should produce 1 SET operation.
    offerANode.setBid(offerANode.getBid() * 10);
    // This should produce 1 REMOVE operation + 1 ADD operation.
    ProductPartitionNode offerBNode = brandGoogleNode.getChild(ProductDimensions.createOfferId("B"));
    offerBNode.asBiddableUnit().setBid(5000000L);
    // This should produce 1 REMOVE operation + 1 ADD operation.
    ProductPartitionNode brandOtherNode = tree.getRoot().getChild(ProductDimensions.createBrand(null));
    brandOtherNode = brandOtherNode.asBiddableUnit();
    // Add an offer C node. This should produce 1 ADD operation.
    ProductPartitionNode offerCNode = brandGoogleNode.addChild(ProductDimensions.createOfferId("C")).asBiddableUnit().setBid(1500000L).putCustomParameter("param1", "value1");
    // Remove the brand Motorola node. This should produce 1 REMOVE operation.
    tree.getRoot().removeChild(brandMotorola);
    // Get the mutate operations generated by the modifications made to the tree.
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals(7, mutateOperations.size());
    // Put the mutate operations in a map keyed by partition ID.
    Map<Long, CriterionDescriptor> opsDescriptorMap = Maps.newHashMap();
    int i = 0;
    for (AdGroupCriterionOperation mutateOperation : mutateOperations) {
        CriterionDescriptor descriptor = new CriterionDescriptor(mutateOperation.getOperand(), i++);
        opsDescriptorMap.put(descriptor.partitionId, descriptor);
    }
    // Check the node that simply had a bid update.
    int setOpNumber = opsDescriptorMap.get(offerANode.getProductPartitionId()).operationNumber;
    assertEquals("Offer A node with a bid update should have a SET operation", Operator.SET, mutateOperations.get(setOpNumber).getOperator());
    // Check the offer B node that went from excluded to biddable.
    int addOfferBOpNumber = opsDescriptorMap.get(offerBNode.getProductPartitionId()).operationNumber;
    assertEquals("Offer B node with a biddable change should have an ADD operation for the new ID", Operator.ADD, mutateOperations.get(addOfferBOpNumber).getOperator());
    int removeOfferBOpNumber = opsDescriptorMap.get(offerBOriginalPartitionId).operationNumber;
    assertEquals("Offer B node with a biddable change should have a REMOVE operation for the original ID", Operator.REMOVE, mutateOperations.get(removeOfferBOpNumber).getOperator());
    // Check the offer C node that was added.
    int addOfferCOpNumber = opsDescriptorMap.get(offerCNode.getProductPartitionId()).operationNumber;
    assertEquals("New offer C node should have an ADD operation for the new ID", Operator.ADD, mutateOperations.get(addOfferCOpNumber).getOperator());
    // Check the brand null node that went from excluded to biddable.
    int addBrandOtherOpNumber = opsDescriptorMap.get(brandOtherNode.getProductPartitionId()).operationNumber;
    assertEquals("Brand null node with a biddable change should have an ADD operation for the new ID", Operator.ADD, mutateOperations.get(addBrandOtherOpNumber).getOperator());
    int brandOtherOpNumber = opsDescriptorMap.get(offerBOriginalPartitionId).operationNumber;
    assertEquals("Brand null node with a biddable change should have a REMOVE operation for the original ID", Operator.REMOVE, mutateOperations.get(brandOtherOpNumber).getOperator());
    // Check the brand Motorola node that was removed.
    int brandMotorolaOpNumber = opsDescriptorMap.get(brandMotorolaOriginalPartitionId).operationNumber;
    assertEquals("Removed node should have a REMOVE operation", Operator.REMOVE, mutateOperations.get(brandMotorolaOpNumber).getOperator());
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) 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) Map(java.util.Map) HashMap(java.util.HashMap) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 2 with ProductBrand

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

the class ProductPartitionNodeTest method testSetBidOnUnit.

@Test
public void testSetBidOnUnit() {
    rootNode = rootNode.asSubdivision();
    ProductBrand childDimension = ProductDimensions.createBrand("google");
    ProductPartitionNode childNode = rootNode.addChild(childDimension);
    assertNull("Bid should be null by default", childNode.getBid());
    childNode = childNode.setBid(1L);
    assertEquals("Bid does not reflect setBid", 1L, childNode.getBid().longValue());
    assertTrue("Node should be a biddable unit", childNode.isBiddableUnit());
    childNode = childNode.asExcludedUnit();
    assertTrue("Node should be an excluded unit", childNode.isExcludedUnit());
    assertFalse("Node should not be a biddable unit", childNode.isBiddableUnit());
    assertNull("Excluded unit should have a null bid", childNode.getBid());
    // Set back to biddable.
    childNode = childNode.asBiddableUnit();
    assertTrue("Node should be a biddable unit", childNode.isBiddableUnit());
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) Test(org.junit.Test)

Example 3 with ProductBrand

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

the class BaseProductDimensionComparatorTest method testCompareToDifferentDimensionType.

@Test
public void testCompareToDifferentDimensionType() {
    ProductDimension dimension = createOtherProductDimension();
    ProductDimension otherTypeOfDimension = dimension instanceof ProductBrand ? ProductDimensions.createOfferId("abc") : ProductDimensions.createBrand("google");
    assertThat("Comparing dimensions of different types should return a non-zero result", comparator.compare(dimension, otherTypeOfDimension), Matchers.not(0));
    assertThat("Comparing dimensions of different types should return a non-zero result", comparator.compare(otherTypeOfDimension, dimension), Matchers.not(0));
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Example 4 with ProductBrand

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

the class ProductBrandComparatorTest method testCaseInsensitive.

@Test
public void testCaseInsensitive() {
    ProductBrand brand1 = ProductDimensions.createBrand("ABC");
    ProductBrand brand2 = ProductDimensions.createBrand("AbC");
    assertEquals("Brands that only differ in case should be equivalent", 0, comparator.compare(brand1, brand2));
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) Test(org.junit.Test)

Example 5 with ProductBrand

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

the class AddProductScope method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the shopping campaign.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId) throws RemoteException {
    // Get the campaign criterion service.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    ProductScope productScope = new ProductScope();
    // This set of dimensions is for demonstration purposes only. It would be
    // extremely unlikely that you want to include so many dimensions in your
    // product scope.
    ProductBrand productBrand = new ProductBrand();
    productBrand.setValue("Nexus");
    ProductCanonicalCondition productCanonicalCondition = new ProductCanonicalCondition();
    productCanonicalCondition.setCondition(ProductCanonicalConditionCondition.NEW);
    ProductCustomAttribute productCustomAttribute = new ProductCustomAttribute();
    productCustomAttribute.setType(ProductDimensionType.CUSTOM_ATTRIBUTE_0);
    productCustomAttribute.setValue("my attribute value");
    ProductOfferId productOfferId = new ProductOfferId();
    productOfferId.setValue("book1");
    ProductType productTypeLevel1Media = new ProductType();
    productTypeLevel1Media.setType(ProductDimensionType.PRODUCT_TYPE_L1);
    productTypeLevel1Media.setValue("Media");
    ProductType productTypeLevel2Books = new ProductType();
    productTypeLevel2Books.setType(ProductDimensionType.PRODUCT_TYPE_L2);
    productTypeLevel2Books.setValue("Books");
    // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
    // category. You can retrieve IDs for categories from the ConstantDataService.
    // See the 'GetProductCategoryTaxonomy' example for more details.
    ProductBiddingCategory productBiddingCategory = new ProductBiddingCategory();
    productBiddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
    productBiddingCategory.setValue(-5914235892932915235L);
    productScope.setDimensions(new ProductDimension[] { productBrand, productCanonicalCondition, productCustomAttribute, productOfferId, productTypeLevel1Media, productTypeLevel2Books, productBiddingCategory });
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(campaignId);
    campaignCriterion.setCriterion(productScope);
    // Create operation.
    CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
    criterionOperation.setOperand(campaignCriterion);
    criterionOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation });
    // Display the result.
    System.out.printf("Created a ProductScope criterion with ID %d.%n", result.getValue(0).getCriterion().getId());
}
Also used : CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductOfferId(com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition) ProductScope(com.google.api.ads.adwords.axis.v201809.cm.ProductScope) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ProductCustomAttribute(com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute) ProductType(com.google.api.ads.adwords.axis.v201809.cm.ProductType) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) ProductBiddingCategory(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)

Aggregations

ProductBrand (com.google.api.ads.adwords.axis.v201809.cm.ProductBrand)13 Test (org.junit.Test)11 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)2 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)2 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)2 ProductCanonicalCondition (com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition)2 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)2 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)1 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 ProductBiddingCategory (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)1 ProductCustomAttribute (com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute)1 ProductDimension (com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)1 ProductOfferId (com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId)1 ProductScope (com.google.api.ads.adwords.axis.v201809.cm.ProductScope)1 ProductType (com.google.api.ads.adwords.axis.v201809.cm.ProductType)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1