Move secrets for live tests into a property file, so missing that file won't fail the build.

This commit is contained in:
Andreas Schildbach 2015-12-19 12:20:54 +01:00
parent 6c1ee94b91
commit 7e172d2aaf
8 changed files with 33 additions and 34 deletions

View file

@ -20,8 +20,10 @@ package de.schildbach.pte.live;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.EnumSet;
import java.util.Properties;
import java.util.Set;
import javax.annotation.Nullable;
@ -139,4 +141,25 @@ public abstract class AbstractProviderLiveTest
{
return provider.queryMoreTrips(context, later);
}
protected final static String secretProperty(final String key)
{
try
{
final Properties properties = new Properties();
final String secretPropertiesFilename = "secrets.properties";
final InputStream is = AbstractProviderLiveTest.class.getResourceAsStream(secretPropertiesFilename);
if (is == null)
throw new IllegalStateException("Could not find secret property file " + secretPropertiesFilename + " in classpath.");
properties.load(is);
final String secret = properties.getProperty(key);
if (secret == null)
throw new IllegalStateException("Could not find secret value for '" + key + "' in " + secretPropertiesFilename + ".");
return secret;
}
catch (final IOException x)
{
throw new RuntimeException(x);
}
}
}