/** * Tests that the builder does not fail when missing everything but a service account key and * service account user. */ @Test public void testReadPropertiesFromConfiguration_onlyKeyFilePathAndUser() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePath"); config.setProperty("api.admanager.serviceAccountUser", "someUser@example.com"); OfflineCredentials credentials = new Builder().forApi(Api.AD_MANAGER).from(config).build(); assertEquals( "service account user should have been set from the config", "someUser@example.com", credentials.getServiceAccountUser()); }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testReadPropertiesFromConfiguration_adWordsServiceAccount() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); String jsonKeyFilePath = "someJsonKeyFilePath"; config.setProperty("api.adwords.jsonKeyFilePath", jsonKeyFilePath); OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.ADWORDS) .from(config) .build(); assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath()); assertNull("service account user should be null", offlineCredentials.getServiceAccountUser()); // Create another credential with the service account user set. String serviceAccountUser = "someUser@example.com"; offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.ADWORDS) .from(config) .withServiceAccountUser(serviceAccountUser) .build(); assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath()); assertEquals(serviceAccountUser, offlineCredentials.getServiceAccountUser()); }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testReadPropertiesFromConfiguration_dfpServiceAccount() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); String jsonKeyFilePath = "someJsonKeyFilePath"; config.setProperty("api.admanager.jsonKeyFilePath", jsonKeyFilePath); OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath()); assertNull("service account user should be null", offlineCredentials.getServiceAccountUser()); // Create another credential with the service account user set. String serviceAccountUser = "someUser@example.com"; offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .withServiceAccountUser(serviceAccountUser) .build(); assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath()); assertEquals(serviceAccountUser, offlineCredentials.getServiceAccountUser()); }