Search in sources :

Example 6 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_bothNonNull_fails.

/**
 * Tests that the comparator throws an IllegalArgumentException when passed two non-null instances
 * of an unsupported subclass of ProductDimension.
 */
@Test
public void testCompareUnsupportedDimensionTypes_bothNonNull_fails() {
    // Compare two instances of the subclass.
    ProductDimension otherTypeOfDimension1 = new UnsupportedDimensionType();
    ProductDimension otherTypeOfDimension2 = new UnsupportedDimensionType();
    thrown.expect(IllegalArgumentException.class);
    comparator.compare(otherTypeOfDimension1, otherTypeOfDimension2);
}
Also used : ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Example 7 with ProductDimension

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

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

the class BaseProductDimensionComparatorTest method testOnlyOneNull.

@Test
public void testOnlyOneNull() {
    ProductDimension dimension = createOtherProductDimension();
    assertThat("Null should be greater than non-null", comparator.compare(null, dimension), Matchers.greaterThan(0));
    assertThat("Non-null should be less than null", comparator.compare(dimension, null), Matchers.lessThan(0));
}
Also used : ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Example 9 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_secondNonNull_fails.

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

Example 10 with ProductDimension

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

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