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