Search in sources :

Example 6 with Campaign

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

the class AxisBatchJobUploadBodyProviderTest method addCampaignOperation.

@Override
protected void addCampaignOperation(BatchJobMutateRequest request, long campaignId, String campaignName, String status, String advertisingChannelType, long budgetId, String biddingStrategyType, boolean enhancedCpcEnabled) {
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setName(campaignName);
    campaign.setStatus(CampaignStatus.fromString(status));
    campaign.setAdvertisingChannelType(AdvertisingChannelType.fromString(advertisingChannelType));
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.fromString(biddingStrategyType));
    ManualCpcBiddingScheme cpcBiddingScheme = new ManualCpcBiddingScheme();
    cpcBiddingScheme.setEnhancedCpcEnabled(enhancedCpcEnabled);
    biddingStrategyConfiguration.setBiddingScheme(cpcBiddingScheme);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) ManualCpcBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)

Example 7 with Campaign

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

the class JaxWsSerializationTest method testSerializeBatchJobMutateRequest.

@SuppressWarnings("cast")
@Test
public void testSerializeBatchJobMutateRequest() throws IOException, SAXException {
    BatchJobMutateRequest request = new BatchJobMutateRequest();
    CampaignOperation campaignOp = new CampaignOperation();
    campaignOp.setOperator(Operator.ADD);
    Campaign campaign = new Campaign();
    campaign.setId(-1L);
    campaign.setName("Test campaign");
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    campaignOp.setOperand(campaign);
    request.addOperation(campaignOp);
    AdGroupOperation adGroupOp = new AdGroupOperation();
    adGroupOp.setOperator(Operator.ADD);
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Test ad group");
    adGroup.setCampaignId(campaign.getId());
    adGroupOp.setOperand(adGroup);
    request.addOperation(adGroupOp);
    JaxBSerializer<BatchJobMutateRequest> serializer = new JaxBSerializer<>(BatchJobMutateRequest.class, new QName("https://adwords.google.com/api/adwords/cm/v201809", "mutate"));
    String serializedRequest = serializer.serialize(request);
    assertNotNull("Null serialized request returned", serializedRequest);
    String expectedSerializedRequest = CharStreams.toString(new InputStreamReader(JaxWsSerializationTest.class.getResourceAsStream("resources/BatchJobMutate.request.xml"), UTF_8));
    // Perform XML diffs using the custom difference listener that properly handles namespaces
    // and attributes.
    Diff diff = DiffBuilder.compare(expectedSerializedRequest).withDifferenceEvaluator(DifferenceEvaluators.chain(DifferenceEvaluators.Default, new CustomDifferenceEvaluator())).withTest(serializedRequest).checkForSimilar().build();
    assertFalse("Serialized request does not match expected value", diff.hasDifferences());
    // Serialize again, this time without the XML declaration, and confirm the serialized XML
    // matches the expected string.
    serializedRequest = serializer.serialize(request, false);
    expectedSerializedRequest = expectedSerializedRequest.replaceFirst("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>", "");
    diff = DiffBuilder.compare(expectedSerializedRequest).normalizeWhitespace().withDifferenceEvaluator(new CustomDifferenceEvaluator()).withTest(serializedRequest).checkForSimilar().build();
    assertFalse("Serialized request with XML declaration excluded does not match expected value", diff.hasDifferences());
}
Also used : CustomDifferenceEvaluator(com.google.api.ads.common.lib.soap.testing.CustomDifferenceEvaluator) BatchJobMutateRequest(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateRequest) Campaign(com.google.api.ads.adwords.jaxws.v201809.cm.Campaign) InputStreamReader(java.io.InputStreamReader) Diff(org.xmlunit.diff.Diff) QName(javax.xml.namespace.QName) CampaignOperation(com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation) JaxBSerializer(com.google.api.ads.common.lib.soap.jaxb.JaxBSerializer) AdGroup(com.google.api.ads.adwords.jaxws.v201809.cm.AdGroup) AdGroupOperation(com.google.api.ads.adwords.jaxws.v201809.cm.AdGroupOperation) Test(org.junit.Test)

Example 8 with Campaign

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

the class BatchJobHelperTest method getPauseCampaignOperation.

@Override
protected Operation getPauseCampaignOperation(Long campaignId) {
    CampaignOperation op = new CampaignOperation();
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setStatus(CampaignStatus.PAUSED);
    op.setOperand(campaign);
    op.setOperator(Operator.SET);
    return op;
}
Also used : Campaign(com.google.api.ads.adwords.jaxws.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation)

Example 9 with Campaign

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

the class BatchJobHelperTest method assertDownloadResponse.

@Override
protected void assertDownloadResponse(BatchJobMutateResponse downloadResponse) {
    assertEquals("Wrong # of mutate results", 1, downloadResponse.getMutateResults().length);
    Operand operand = downloadResponse.getMutateResults()[0].getOperand();
    Campaign campaign = operand.getCampaign();
    assertEquals("ID is incorrect", Long.valueOf(12345L), campaign.getId());
    assertEquals("Status is incorrect", CampaignStatus.PAUSED, campaign.getStatus());
}
Also used : Campaign(com.google.api.ads.adwords.jaxws.v201809.cm.Campaign) Operand(com.google.api.ads.adwords.jaxws.v201809.cm.Operand)

Example 10 with Campaign

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

the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobResponseWithoutErrors.

/**
 * Tests that a response without errors will be properly deserialized.
 */
@Test
public void testDeserializeBatchJobResponseWithoutErrors() throws Exception {
    BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithoutErrors.xml"));
    assertNotNull(response);
    // Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion
    assertEquals(4, response.getMutateResults().length);
    assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
    assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
    assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) Test(org.junit.Test)

Aggregations

Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)23 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)15 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)15 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)11 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)9 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)9 Test (org.junit.Test)6 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)5 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)5 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)4 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)3 ManualCpcBiddingScheme (com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)3 ShoppingSetting (com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting)3 Campaign (com.google.api.ads.adwords.jaxws.v201809.cm.Campaign)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)2 DynamicSearchAdsSetting (com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting)2 GeoTargetTypeSetting (com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting)2