Search in sources :

Example 81 with AdWordsSession

use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.

the class AdWordsSessionUtilTest method getInvalidCid.

private static long getInvalidCid(String invalidCid) throws ValidationException {
    AdWordsSession session = getTestAdWordsSessionWithoutCid();
    session.setClientCustomerId(invalidCid);
    return AdWordsSessionUtil.getClientCustomerId(session);
}
Also used : AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession)

Example 82 with AdWordsSession

use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.

the class ApiInvocationHandlerWithRateLimiterTest method testCidChangeInAdWordsSession.

/**
 * Test that the {@link ApiInvocationHandlerWithRateLimiter} class holds an AdWordsSession
 * reference, instead of creating a copy of it.
 */
@Test
public void testCidChangeInAdWordsSession() throws ValidationException {
    AdWordsSession session = AdWordsSessionUtilTest.getTestAdWordsSessionWithoutCid();
    session.setClientCustomerId(TEST_CID1);
    Object obj = new Object();
    // Don't use ApiServicesRetryStrategy, because in ApiRateLimiterTest we need to change system
    // settings before creating its instance for the expected testing behavior!
    ApiRetryStrategy retryStrategy = ApiReportingRetryStrategy.newInstance();
    ApiInvocationHandlerWithRateLimiter awapiInvocationHandler = new ApiInvocationHandlerWithRateLimiter(obj, session, retryStrategy);
    assertSame("Same adwords session object check.", session, awapiInvocationHandler.getAdWordsSession());
    assertTrue("AdWordsSession cid1 check", awapiInvocationHandler.getAdWordsSession().getClientCustomerId().equals(TEST_CID1));
    session.setClientCustomerId(TEST_CID2);
    assertSame("Same adwords session object check.", session, awapiInvocationHandler.getAdWordsSession());
    assertTrue("AdWordsSession cid2 check", awapiInvocationHandler.getAdWordsSession().getClientCustomerId().equals(TEST_CID2));
}
Also used : AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) Test(org.junit.Test)

Example 83 with AdWordsSession

use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.

the class AdWordsAxisModule method configure.

@Override
public void configure() {
    bind(new TypeLiteral<AxisSoapHeaderFactory<AdWordsServiceDescriptor>>() {
    }).to(new TypeLiteral<AdWordsAxisSoapHeaderFactory>() {
    });
    bind(new TypeLiteral<HeaderHandler<AdWordsSession, AdWordsServiceDescriptor>>() {
    }).to(new TypeLiteral<AdWordsAxisHeaderHandler>() {
    });
    install(new AxisModule());
    install(new AdWordsModule());
    install(new AdWordsSoapModule());
    configureConfigurations(this.getClass().getResource("conf/props/build.properties"));
}
Also used : TypeLiteral(com.google.inject.TypeLiteral) AdWordsModule(com.google.api.ads.adwords.lib.AdWordsModule) AdWordsSoapModule(com.google.api.ads.adwords.lib.AdWordsSoapModule) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) AdWordsServiceDescriptor(com.google.api.ads.adwords.lib.client.AdWordsServiceDescriptor) AxisModule(com.google.api.ads.common.lib.soap.axis.AxisModule)

Example 84 with AdWordsSession

use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.

the class AdWordsAxisSoapCompressionIntegrationTest method testGoldenSoap_oauth2_compressionEnabled.

/**
 * Tests making an Axis AdWords API call with OAuth2 and compression enabled.
 */
@Test
public void testGoldenSoap_oauth2_compressionEnabled() throws Exception {
    testHttpServer.setMockResponseBody(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION));
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build();
    credential.setAccessToken("TEST_ACCESS_TOKEN");
    AdWordsSession session = new AdWordsSession.Builder().withUserAgent("TEST_APP").withOAuth2Credential(credential).withEndpoint(testHttpServer.getServerUrl()).withDeveloperToken("TEST_DEVELOPER_TOKEN").withClientCustomerId("TEST_CLIENT_CUSTOMER_ID").build();
    BudgetServiceInterface companyService = new AdWordsServices().get(session, BudgetServiceInterface.class);
    Budget budget = new Budget();
    budget.setName("Test Budget Name");
    Money money = new Money();
    money.setMicroAmount(50000000L);
    budget.setAmount(money);
    budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
    BudgetOperation operation = new BudgetOperation();
    operation.setOperand(budget);
    operation.setOperator(Operator.ADD);
    Budget responseBudget = companyService.mutate(new BudgetOperation[] { operation }).getValue(0);
    assertEquals("Budget ID does not match", 251877074L, responseBudget.getBudgetId().longValue());
    assertEquals("Budget name does not match", budget.getName(), responseBudget.getName());
    assertEquals("Budget amount does not match", budget.getAmount().getMicroAmount(), responseBudget.getAmount().getMicroAmount());
    assertEquals("Budget delivery method does not match", budget.getDeliveryMethod(), responseBudget.getDeliveryMethod());
    assertTrue("Compression was enabled but the last request body was not compressed", testHttpServer.wasLastRequestBodyCompressed());
    Diff diff = DiffBuilder.compare(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION)).withTest(testHttpServer.getLastRequestBody()).checkForSimilar().build();
    assertFalse(diff.hasDifferences());
    assertEquals("Bearer TEST_ACCESS_TOKEN", testHttpServer.getLastAuthorizationHttpHeader());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) Diff(org.xmlunit.diff.Diff) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) DiffBuilder(org.xmlunit.builder.DiffBuilder) BudgetOperation(com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation) BudgetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.BudgetServiceInterface) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) Test(org.junit.Test) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)

Example 85 with AdWordsSession

use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.

the class AdWordsAxisSoapIntegrationTest method testGoldenSoap_oauth2.

/**
 * Tests making an Axis AdWords API call with OAuth2 and compression enabled.
 */
@Test
public void testGoldenSoap_oauth2() throws Exception {
    testHttpServer.setMockResponseBody(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION));
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build();
    credential.setAccessToken("TEST_ACCESS_TOKEN");
    AdWordsSession session = new AdWordsSession.Builder().withUserAgent("TEST_APP").withOAuth2Credential(credential).withEndpoint(testHttpServer.getServerUrl()).withDeveloperToken("TEST_DEVELOPER_TOKEN").withClientCustomerId("TEST_CLIENT_CUSTOMER_ID").build();
    testBudgetServiceMutateRequest(session);
    assertEquals("Bearer TEST_ACCESS_TOKEN", testHttpServer.getLastAuthorizationHttpHeader());
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) DiffBuilder(org.xmlunit.builder.DiffBuilder) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Aggregations

AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)121 Credential (com.google.api.client.auth.oauth2.Credential)104 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)102 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)101 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)100 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)100 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)97 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)97 RemoteException (java.rmi.RemoteException)97 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)24 Test (org.junit.Test)15 IOException (java.io.IOException)14 OfflineCredentials (com.google.api.ads.common.lib.auth.OfflineCredentials)12 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)10 Api (com.google.api.ads.common.lib.auth.OfflineCredentials.Api)9 DEFAULT_CONFIGURATION_FILENAME (com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME)9 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)8 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)7 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)7 List (java.util.List)7