use of com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromFile_clientSecretTokenBadWithFilePath.
/**
* Tests that the builder correctly identifies the file path.
*/
@Test
public void testReadPropertiesFromFile_clientSecretTokenBadWithFilePath() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientId", "clientId");
config.setProperty("api.admanager.refreshToken", "refreshToken");
when(configurationHelper.fromFile("/home/user/path")).thenReturn(config);
ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);
thrown.expect(ValidationException.class);
thrown.expectMessage("Client secret must be set as api.admanager.clientSecret in /home/user/path." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https://console.developers.google.com/project");
builder.fromFile("/home/user/path").build();
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromFile_withOverride.
/**
* Tests that the builder correctly reads from a file.
*/
@Test
public void testReadPropertiesFromFile_withOverride() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientId", "clientId");
config.setProperty("api.admanager.clientSecret", "clientSecret");
config.setProperty("api.admanager.refreshToken", "refreshToken");
when(configurationHelper.fromFile("path")).thenReturn(config);
ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);
OfflineCredentials offlineCredentials = builder.fromFile("path").withRefreshToken("overrideRefreshToken").build();
assertEquals("clientId", offlineCredentials.getClientId());
assertEquals("clientSecret", offlineCredentials.getClientSecret());
assertEquals("overrideRefreshToken", offlineCredentials.getRefreshToken());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromFile_refreshTokenNoFilePath.
/**
* Tests that the builder correctly leaves out the file path.
*/
@Test
public void testReadPropertiesFromFile_refreshTokenNoFilePath() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientId", "clientId");
config.setProperty("api.admanager.clientSecret", "clientSecret");
ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);
thrown.expect(ValidationException.class);
thrown.expectMessage("A refresh token must be set." + "\nIt is required for offline credentials. If you need to create one, " + "see the GetRefreshToken example.");
builder.from(config).build();
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromFile.
/**
* Tests that the builder correctly reads from a file.
*/
@Test
public void testReadPropertiesFromFile() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientId", "clientId");
config.setProperty("api.admanager.clientSecret", "clientSecret");
config.setProperty("api.admanager.refreshToken", "refreshToken");
when(configurationHelper.fromFile("path")).thenReturn(config);
ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);
OfflineCredentials offlineCredentials = builder.fromFile("path").build();
assertEquals("clientId", offlineCredentials.getClientId());
assertEquals("clientSecret", offlineCredentials.getClientSecret());
assertEquals("refreshToken", offlineCredentials.getRefreshToken());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromFile_clientSecretNoFilePath.
/**
* Tests that the builder correctly leaves out the file path.
*/
@Test
public void testReadPropertiesFromFile_clientSecretNoFilePath() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientId", "clientId");
config.setProperty("api.admanager.refreshToken", "refreshToken");
ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);
thrown.expect(ValidationException.class);
thrown.expectMessage("Client secret must be set." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https://console.developers.google.com/project");
builder.from(config).build();
}
Aggregations