use of com.google.api.ads.adwords.lib.utils.testing.GenericAdWordsServices in project googleads-java-lib by googleads.
the class AdHocReportDownloadHelperTest method testDownloadReportWithBadEndpoint_fails.
/**
* Tests that the helper will throw a {@link ConnectException} wrapped in a
* {@link ReportException} when the endpoint is for an unused port on localhost.
*/
@Test
public void testDownloadReportWithBadEndpoint_fails() throws Throwable {
int port = TestPortFinder.getInstance().checkOutUnusedPort();
try {
// Construct the session to use an endpoint that is NOT in use on localhost.
AdWordsSession sessionWithBadEndpoint = new AdWordsSession.Builder().withUserAgent("TEST_APP").withOAuth2Credential(credential).withEndpoint("https://localhost:" + port).withDeveloperToken("TEST_DEVELOPER_TOKEN").withClientCustomerId("TEST_CLIENT_CUSTOMER_ID").build();
helper = new GenericAdWordsServices().getBootstrapper().getInstanceOf(sessionWithBadEndpoint, AdHocReportDownloadHelper.class);
// Set up the ReportRequest so it will pass basic validation.
when(reportRequest.getRequestType()).thenReturn(RequestType.AWQL);
String awqlString = "SELECT BadField1 FROM NOT_A_REPORT DURING NOT_A_TIME_PERIOD";
when(reportRequest.getReportRequestString()).thenReturn(awqlString);
// The cause should be a ConnectException (see expected annotation) since the endpoint
// port is not in use.
thrown.expect(ReportException.class);
thrown.expectCause(Matchers.<Exception>instanceOf(ConnectException.class));
downloadReport();
} finally {
TestPortFinder.getInstance().releaseUnusedPort(port);
}
}
use of com.google.api.ads.adwords.lib.utils.testing.GenericAdWordsServices in project googleads-java-lib by googleads.
the class ReportDownloaderTest method testGetFromAdWordsServices.
@Test
public void testGetFromAdWordsServices() throws Exception {
AdWordsServicesInterface adWordsServices = new GenericAdWordsServices();
ReportDownloaderInterface downloader = adWordsServices.getUtility(adWordsSession, ReportDownloaderInterface.class);
assertNotNull("Null downloader from AdWordsServices", downloader);
}
use of com.google.api.ads.adwords.lib.utils.testing.GenericAdWordsServices in project googleads-java-lib by googleads.
the class AdHocReportDownloadHelperTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Enum<?> downloadFormat = TestDownloadFormat.CSV;
Mockito.<Enum<?>>when(reportRequest.getDownloadFormat()).thenReturn(downloadFormat);
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();
helper = new GenericAdWordsServices().getBootstrapper().getInstanceOf(session, AdHocReportDownloadHelper.class);
exceptionBuilder = DetailedReportDownloadResponseException::new;
}
use of com.google.api.ads.adwords.lib.utils.testing.GenericAdWordsServices in project googleads-java-lib by googleads.
the class AdWordsPluginModuleTest method testCombinedUserAgentBehavior.
/**
* Verifies that {@link UserAgentCombiner} instances behave as expected when an {@link
* AdWordsPluginModule} is or is not provided to the injector.
*/
@Test
public void testCombinedUserAgentBehavior() {
// Create a mock ExtensionUserAgentProvider that returns a specific string from getUserAgent.
String pluginUserAgentSnippet = "MyCustomExtension";
when(extensionUserAgentProvider.getUserAgent()).thenReturn(pluginUserAgentSnippet);
// Create an AdWordsServicesInterface using an AdWordsPluginModule configured with the
// ExtensionUserAgentProvider.
GenericAdWordsServices genericAdWordsServices = (GenericAdWordsServices) new GenericAdWordsServices().withPluginModule(new AdWordsPluginModule(extensionUserAgentProvider));
// Get the combined user agent from the UserAgentCombiner provided by the
// AdWordsServicesInterface, and confirm the combined user agent it returns includes the
// string from the mock ExtensionUserAgentProvider.
UserAgentCombiner userAgentCombiner = genericAdWordsServices.getBootstrapper().getInstanceOf(session, UserAgentCombiner.class);
String combinedUserAgent = userAgentCombiner.getUserAgent("foo");
assertThat("Combined user agent does not contain the string from the plugin", combinedUserAgent, Matchers.containsString(pluginUserAgentSnippet));
// Get a UserAgentCombiner from an AdWordsServicesInterface without a plugin and confirm the
// combined user agent it returns does not contain the string from the mock
// ExtensionUserAgentProvider.
genericAdWordsServices = new GenericAdWordsServices();
userAgentCombiner = genericAdWordsServices.getBootstrapper().getInstanceOf(session, UserAgentCombiner.class);
combinedUserAgent = userAgentCombiner.getUserAgent("foo");
assertThat("Combined user agent contains string from the plugin, but plugin was not provided", combinedUserAgent, Matchers.not(Matchers.containsString(pluginUserAgentSnippet)));
}
Aggregations