use of com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromFile_refreshTokenBadWithFilePath.
/**
* Tests that the builder correctly identifies the file path.
*/
@Test
public void testReadPropertiesFromFile_refreshTokenBadWithFilePath() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientId", "clientId");
config.setProperty("api.admanager.clientSecret", "clientSecret");
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("A refresh token must be set as api.admanager.refreshToken in /home/user/path." + "\nIt is required for offline credentials. If you need to create one, " + "see the GetRefreshToken example.");
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_clientIdTokenBadWithFilePath.
/**
* Tests that the builder correctly identifies the file path.
*/
@Test
public void testReadPropertiesFromFile_clientIdTokenBadWithFilePath() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientSecret", "clientSecret");
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 ID must be set as api.admanager.clientId 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_clientIdNoFilePath.
/**
* Tests that the builder correctly leaves out the file path.
*/
@Test
public void testReadPropertiesFromFile_clientIdNoFilePath() throws Exception {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setProperty("api.admanager.clientSecret", "clientSecret");
config.setProperty("api.admanager.refreshToken", "refreshToken");
ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);
thrown.expect(ValidationException.class);
thrown.expectMessage("Client ID 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