@Test public void testGetAuthorizationHeader_oAuth2NoRefresh() throws Exception { final Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); OAuth2Session adsSession = () -> credential; when(oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader( (OAuth2Compatible) adsSession)).thenReturn("OAuth2 Header"); when(adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()).thenReturn(false); assertEquals("OAuth2 Header", authorizationHeaderProvider.getAuthorizationHeader(adsSession, ENDPOINT_URL.toString())); verify(oAuth2Helper, times(0)).refreshCredential(credential); }
@Test public void testGetAuthorizationHeader_oAuth2Refresh() throws Exception { final Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); OAuth2Session adsSession = () -> credential; when(oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader( (OAuth2Compatible) adsSession)).thenReturn("OAuth2 Header"); when(adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()).thenReturn(true); assertEquals("OAuth2 Header", authorizationHeaderProvider.getAuthorizationHeader(adsSession, ENDPOINT_URL.toString())); verify(oAuth2Helper).refreshCredential(credential); }
/** * Tests setting the headers. */ @SuppressWarnings("unchecked") @Test public void testSetHeaders() throws Exception { Object soapClient = new Object(); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); AdManagerSession adManagerSession = new AdManagerSession.Builder() .withApplicationName("FooBar") .withOAuth2Credential(credential) .withEndpoint("https://ads.google.com") .withNetworkCode("networkCode") .build(); adManagerHttpHeaderHandler.setHttpHeaders(soapClient, adManagerSession); verify(soapClientHandler).putAllHttpHeaders(eq(soapClient), any(Map.class)); }
public AdManagerSessionTest(boolean isImmutable) { this.isImmutable = isImmutable; this.credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); this.allSettingsBuilder = new AdManagerSession.Builder() .withApplicationName("FooBar") .withEndpoint("https://ads.google.com") .withOAuth2Credential(credential) .withNetworkCode("networkCode"); }
@Test public void testCheckServiceClientPreconditions_passOAuth2() throws Exception { AdWordsServiceClientFactoryHelper helper = new AdWordsServiceClientFactoryHelper( adsServiceClientFactory, adsServiceDescriptorFactory, soapClientHandler, adsLibConfiguration); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); AdWordsSession adWordsSession = new AdWordsSession.Builder() .withUserAgent("FooBar") .withEndpoint("https://www.google.com") .withOAuth2Credential(credential) .withDeveloperToken("developerToken") .build(); helper.checkServiceClientPreconditions(adWordsSession, com.google.api.ads.adwords.lib.factory.helper.testing.v201406.cm.TestService.class); } }
@Test public void testCheckServiceClientPreconditions_passOAuth2() throws Exception { AdManagerServiceClientFactoryHelper helper = new AdManagerServiceClientFactoryHelper( adsServiceClientFactory, adsServiceDescriptorFactory, soapClientHandler, adsLibConfiguration); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); AdManagerSession adManagerSession = new AdManagerSession.Builder() .withApplicationName("FooBar") .withNetworkCode("1000") .withEndpoint("https://ads.google.com") .withOAuth2Credential(credential) .build(); helper.checkServiceClientPreconditions(adManagerSession, com.google.api.ads.admanager.lib.factory.helper.testing.v201811.TestService.class); } }
public AdWordsSessionTest(boolean isImmutable) { this.isImmutable = isImmutable; this.credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); this.reportingConfiguration = new ReportingConfiguration.Builder().skipReportHeader(true).skipReportSummary(true).build(); this.allSettingsBuilder = new AdWordsSession.Builder() .withClientCustomerId("customer id") .withDeveloperToken("developer token") .withEndpoint("https://www.google.com") .enablePartialFailure() .enableValidateOnly() .withOAuth2Credential(credential) .withUserAgent("user agent") .withReportingConfiguration(reportingConfiguration); }