Search in sources :

Example 11 with ProductDimension

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

the class ProductPartitionNodeTest method testDimensionToString_unknownAttribute.

/**
 * Test to confirm that {@link ProductPartitionNode#toString(ProductDimension)} handles a
 * malformed {@link ProductDimension} gracefully without throwing an exception.
 */
@Test
public void testDimensionToString_unknownAttribute() throws Exception {
    ProductBrand productBrand = mock(ProductBrand.class);
    when(productBrand.getValue()).thenThrow(new RuntimeException());
    assertThat("ProductPartitionNode did not fail gracefully when interpreting the attributes of " + "a malformed ProductDimension", ProductPartitionNode.toString(productBrand), Matchers.containsString("UNKNOWN"));
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) Test(org.junit.Test)

Example 12 with ProductDimension

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

the class ProductPartitionTreeImpl method createNonEmptyAdGroupTree.

/**
 * Returns a new tree based on a non-empty collection of ad group criteria. All parameters
 * required.
 *
 * @param adGroupId the ID of the ad group
 * @param parentIdMap the multimap from parent product partition ID to child criteria
 * @return a new ProductPartitionTree
 */
private static ProductPartitionTreeImpl createNonEmptyAdGroupTree(Long adGroupId, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
    Preconditions.checkNotNull(adGroupId, "Null ad group ID");
    Preconditions.checkArgument(!parentIdMap.isEmpty(), "parentIdMap passed for ad group ID %s is empty", adGroupId);
    Preconditions.checkArgument(parentIdMap.containsKey(null), "No root criterion found in the list of ad group criteria for ad group ID %s", adGroupId);
    AdGroupCriterion rootCriterion = Iterables.getOnlyElement(parentIdMap.get(null));
    Preconditions.checkState(rootCriterion instanceof BiddableAdGroupCriterion, "Root criterion for ad group ID %s is not a BiddableAdGroupCriterion", adGroupId);
    BiddableAdGroupCriterion biddableRootCriterion = (BiddableAdGroupCriterion) rootCriterion;
    BiddingStrategyConfiguration biddingStrategyConfig = biddableRootCriterion.getBiddingStrategyConfiguration();
    Preconditions.checkState(biddingStrategyConfig != null, "Null bidding strategy config on the root node of ad group ID %s", adGroupId);
    ProductPartitionNode rootNode = new ProductPartitionNode(null, (ProductDimension) null, rootCriterion.getCriterion().getId(), new ProductDimensionComparator());
    // Set the root's bid if a bid exists on the BiddableAdGroupCriterion.
    Money rootNodeBid = getBid(biddableRootCriterion);
    if (rootNodeBid != null) {
        rootNode = rootNode.asBiddableUnit().setBid(rootNodeBid.getMicroAmount());
    }
    rootNode = rootNode.setTrackingUrlTemplate(biddableRootCriterion.getTrackingUrlTemplate());
    rootNode = copyCustomParametersToNode(biddableRootCriterion, rootNode);
    addChildNodes(rootNode, parentIdMap);
    return new ProductPartitionTreeImpl(adGroupId, biddingStrategyConfig, rootNode);
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)

Example 13 with ProductDimension

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

the class BaseProductDimensionComparatorTest method testNeitherNull.

@Test
public void testNeitherNull() {
    ProductDimension otherDimension = createOtherProductDimension();
    List<? extends ProductDimension> nonOtherDimensions = createNonOtherProductDimensions();
    if (nonOtherDimensions == null) {
        return;
    }
    int result = comparator.compare(otherDimension, nonOtherDimensions.get(0));
    assertThat("The 'other' case should be > the non-other case", result, Matchers.greaterThan(0));
}
Also used : ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Example 14 with ProductDimension

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

the class BaseProductDimensionComparatorTest method testCompareUnsupportedDimensionTypes_firstUnsupported_fails.

/**
 * Tests that the comparator throws an IllegalArgumentException when passed an instance of an
 * unsupported subclass of ProductDimension as the first argument, and an instance of a supported
 * type as the second argument.
 */
@Test
public void testCompareUnsupportedDimensionTypes_firstUnsupported_fails() {
    // Compare an unsupported type to null.
    ProductDimension unsupportedTypeOfDimension = new UnsupportedDimensionType();
    thrown.expect(IllegalArgumentException.class);
    comparator.compare(unsupportedTypeOfDimension, createOtherProductDimension());
}
Also used : ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Example 15 with ProductDimension

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

the class BaseProductDimensionComparatorTest method testCompareUnsupportedDimensionTypes_firstNonNull_fails.

/**
 * Tests that the comparator throws an IllegalArgumentException when passed a non-null instance
 * of an unsupported subclass of ProductDimension as the first argument, and null as the second
 * argument.
 */
@Test
public void testCompareUnsupportedDimensionTypes_firstNonNull_fails() {
    // Compare an unsupported type to null.
    ProductDimension unsupportedTypeOfDimension = new UnsupportedDimensionType();
    thrown.expect(IllegalArgumentException.class);
    comparator.compare(unsupportedTypeOfDimension, null);
}
Also used : ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Aggregations

ProductDimension (com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)13 Test (org.junit.Test)12 ProductBrand (com.google.api.ads.adwords.axis.v201809.cm.ProductBrand)4 ProductBiddingCategory (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)2 ProductCanonicalCondition (com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition)2 ProductCustomAttribute (com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute)2 ProductOfferId (com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId)2 ProductType (com.google.api.ads.adwords.axis.v201809.cm.ProductType)2 NodeDifference (com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionNodeDiffer.NodeDifference)1 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)1 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)1 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)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 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)1 ProductAdwordsGrouping (com.google.api.ads.adwords.axis.v201809.cm.ProductAdwordsGrouping)1 ProductAdwordsLabels (com.google.api.ads.adwords.axis.v201809.cm.ProductAdwordsLabels)1 ProductCanonicalConditionCondition (com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalConditionCondition)1