/** * Constructor used by Guice. * * @param session Used to pull authentication data. * @param authorizationHeaderProvider Used to population the authentication data into a header. * @param userAgentCombiner Used to populate the User-Agent header. * @param adWordsLibConfiguration Used to obtain configuration options affecting report requests. * @param responseInterceptor Response interceptor to use for requests generated by this factory * helper. */ @Inject ReportRequestFactoryHelper(AdWordsSession session, AuthorizationHeaderProvider authorizationHeaderProvider, UserAgentCombiner userAgentCombiner, HttpTransport httpTransport, AdWordsLibConfiguration adWordsLibConfiguration, ReportResponseInterceptor responseInterceptor) { this.session = session; this.authorizationHeaderProvider = authorizationHeaderProvider; this.userAgentCombiner = userAgentCombiner; this.httpTransport = httpTransport; this.reportDownloadTimeout = (session.getReportingConfiguration() != null && session.getReportingConfiguration().getReportDownloadTimeout() != null) ? session.getReportingConfiguration().getReportDownloadTimeout() : adWordsLibConfiguration.getReportDownloadTimeout(); this.responseInterceptor = responseInterceptor; }
@Test public void testPropertyFileIncludedInConfig() throws Exception { File adsPropertiesFile = createPropertiesFile(); System.setProperty("user.home", adsPropertiesFile.getParentFile().getAbsolutePath()); AdWordsLibConfiguration config = Guice.createInjector(new AdWordsModule()).getInstance(AdWordsLibConfiguration.class); assertFalse(config.isAutoRefreshOAuth2TokenEnabled()); }
/** * Constructor used by Guice. * * @param session Used to pull authentication data. * @param authorizationHeaderProvider Used to population the authentication data into a header. * @param userAgentCombiner Used to populate the User-Agent header. * @param adWordsLibConfiguration Used to obtain configuration options affecting report requests. * @param responseInterceptor Response interceptor to use for requests generated by this factory * helper. */ @Inject ReportRequestFactoryHelper(AdWordsSession session, AuthorizationHeaderProvider authorizationHeaderProvider, UserAgentCombiner userAgentCombiner, HttpTransport httpTransport, AdWordsLibConfiguration adWordsLibConfiguration, ReportResponseInterceptor responseInterceptor) { this.session = session; this.authorizationHeaderProvider = authorizationHeaderProvider; this.userAgentCombiner = userAgentCombiner; this.httpTransport = httpTransport; this.reportDownloadTimeout = (session.getReportingConfiguration() != null && session.getReportingConfiguration().getReportDownloadTimeout() != null) ? session.getReportingConfiguration().getReportDownloadTimeout() : adWordsLibConfiguration.getReportDownloadTimeout(); this.responseInterceptor = responseInterceptor; }
/** * Tests that {@link AdHocReportDownloadHelper#getReportDownloadTimeout()} retrieves the global * timeout if not set on the helper. */ @Test public void testGetReportDownloadTimeout() { assertEquals( AdWordsInternals.getInstance().getAdWordsLibConfiguration().getReportDownloadTimeout(), helper.getReportDownloadTimeout()); }
/** * Tests that {@link AdHocReportDownloadHelper#setReportDownloadTimeout(int)} sets the * helper-specific timeout and does not affect the global timeout. */ @Test public void testSetReportDownloadTimeout() { int internalsTimeout = AdWordsInternals.getInstance().getAdWordsLibConfiguration().getReportDownloadTimeout(); assertEquals(internalsTimeout, helper.getReportDownloadTimeout()); int helperTimeout = internalsTimeout + 10; helper.setReportDownloadTimeout(helperTimeout); assertEquals("Timeout on helper does not reflect changes made via setReportDownloadTimeout", helperTimeout, helper.getReportDownloadTimeout()); assertEquals("Setting the timeout on a helper instance modified the global timeout", internalsTimeout, AdWordsInternals.getInstance().getAdWordsLibConfiguration().getReportDownloadTimeout()); }
throws ValidationException, AuthenticationException, IOException { final int timeoutFromLibConfig = 42; when(adWordsLibConfiguration.getReportDownloadTimeout()).thenReturn(timeoutFromLibConfig); AdWordsSession session = new AdWordsSession.Builder()