Search in sources :

Example 6 with ForApiBuilder

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();
}
Also used : ForApiBuilder(com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 7 with ForApiBuilder

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();
}
Also used : ForApiBuilder(com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 8 with ForApiBuilder

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();
}
Also used : ForApiBuilder(com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Aggregations

ForApiBuilder (com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder)8 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)8 Test (org.junit.Test)8