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