use of com.google.api.ads.adwords.jaxws.factory.AdWordsServices in project googleads-java-lib by googleads.
the class AdWordsJaxWsSoapCompressionIntegrationTest method testGoldenSoap_oauth2.
/**
* Tests making a JAX-WS 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();
BudgetServiceInterface budgetService = 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 = budgetService.mutate(Lists.newArrayList(operation)).getValue().get(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.jaxws.factory.AdWordsServices in project googleads-java-lib by googleads.
the class AdWordsJaxWsSoapIntegrationTest method testGoldenSoap_oauth2.
/**
* Tests making a JAX-WS Ad Manager API call with OAuth2.
*/
@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();
BudgetServiceInterface budgetService = 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 = budgetService.mutate(Lists.newArrayList(operation)).getValue().get(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());
Diff diff = DiffBuilder.compare(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION)).withTest(testHttpServer.getLastRequestBody()).checkForSimilar().build();
assertFalse(diff.hasDifferences());
assertFalse("Did not request compression but request was compressed", testHttpServer.wasLastRequestBodyCompressed());
assertEquals("Bearer TEST_ACCESS_TOKEN", testHttpServer.getLastAuthorizationHttpHeader());
}
use of com.google.api.ads.adwords.jaxws.factory.AdWordsServices in project googleads-java-lib by googleads.
the class AdWordsJaxWsSoapTimeoutIntegrationTest method testRequestTimeoutEnforced.
/**
* Tests that the request timeout in ads.properties is enforced.
*/
@Test
public void testRequestTimeoutEnforced() throws Exception {
testHttpServer.setMockResponseBody(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION));
testHttpServer.setDelay(200L);
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 budgetService = 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);
thrown.expect(WebServiceException.class);
thrown.expectMessage("Read timed out");
budgetService.mutate(Lists.newArrayList(operation));
}
Aggregations