From 7e172d2aafb16063bf7da2da42996e56c7b53a1c Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 19 Dec 2015 12:20:54 +0100 Subject: [PATCH] Move secrets for live tests into a property file, so missing that file won't fail the build. --- .../test/de/schildbach/pte/live/.gitignore | 2 +- .../pte/live/AbstractProviderLiveTest.java | 23 +++++++++++++++ .../pte/live/ParisProviderLiveTest.java | 2 +- .../schildbach/pte/live/Secrets.java.template | 29 ------------------- .../pte/live/VaoProviderLiveTest.java | 2 +- .../pte/live/VbnProviderLiveTest.java | 2 +- .../pte/live/VgnProviderLiveTest.java | 2 +- .../pte/live/secrets.properties.template | 5 ++++ 8 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 enabler/test/de/schildbach/pte/live/Secrets.java.template create mode 100644 enabler/test/de/schildbach/pte/live/secrets.properties.template diff --git a/enabler/test/de/schildbach/pte/live/.gitignore b/enabler/test/de/schildbach/pte/live/.gitignore index 02e7100b..5798680b 100644 --- a/enabler/test/de/schildbach/pte/live/.gitignore +++ b/enabler/test/de/schildbach/pte/live/.gitignore @@ -1 +1 @@ -Secrets.java +secrets.properties diff --git a/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java index c568f8dd..52cfc12d 100644 --- a/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/AbstractProviderLiveTest.java @@ -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); + } + } } diff --git a/enabler/test/de/schildbach/pte/live/ParisProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/ParisProviderLiveTest.java index d1e91b51..5b30044e 100644 --- a/enabler/test/de/schildbach/pte/live/ParisProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/ParisProviderLiveTest.java @@ -31,7 +31,7 @@ public class ParisProviderLiveTest extends AbstractNavitiaProviderLiveTest { public ParisProviderLiveTest() { - super(new ParisProvider(Secrets.NAVITIA_AUTHORIZATION)); + super(new ParisProvider(secretProperty("navitia.authorization"))); } @Test diff --git a/enabler/test/de/schildbach/pte/live/Secrets.java.template b/enabler/test/de/schildbach/pte/live/Secrets.java.template deleted file mode 100644 index 5cf2174d..00000000 --- a/enabler/test/de/schildbach/pte/live/Secrets.java.template +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2015 the original author or authors. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package de.schildbach.pte.live; - -/** - * @author Andreas Schildbach - */ -public final class Secrets -{ - public static final String VGN_API_BASE = "insert vgn base here"; - public static final String NAVITIA_AUTHORIZATION = "insert navitia authorization here"; - public static final String VBN_JSON_API_AUTHORIZATION = "insert vao authorization here"; - public static final String VAO_JSON_API_AUTHORIZATION = "insert vao authorization here"; -} diff --git a/enabler/test/de/schildbach/pte/live/VaoProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/VaoProviderLiveTest.java index 79daf1a5..e8f77674 100644 --- a/enabler/test/de/schildbach/pte/live/VaoProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/VaoProviderLiveTest.java @@ -41,7 +41,7 @@ public class VaoProviderLiveTest extends AbstractProviderLiveTest { public VaoProviderLiveTest() { - super(new VaoProvider(Secrets.VAO_JSON_API_AUTHORIZATION)); + super(new VaoProvider(secretProperty("vao.json_api_authorization"))); } @Test diff --git a/enabler/test/de/schildbach/pte/live/VbnProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/VbnProviderLiveTest.java index 4f228192..86679211 100644 --- a/enabler/test/de/schildbach/pte/live/VbnProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/VbnProviderLiveTest.java @@ -44,7 +44,7 @@ public class VbnProviderLiveTest extends AbstractProviderLiveTest { public VbnProviderLiveTest() { - super(new VbnProvider(Secrets.VBN_JSON_API_AUTHORIZATION)); + super(new VbnProvider(secretProperty("vbn.json_api_authorization"))); } @Test diff --git a/enabler/test/de/schildbach/pte/live/VgnProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/VgnProviderLiveTest.java index d3f98afc..c95bfb32 100644 --- a/enabler/test/de/schildbach/pte/live/VgnProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/VgnProviderLiveTest.java @@ -42,7 +42,7 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest { public VgnProviderLiveTest() { - super(new VgnProvider(Secrets.VGN_API_BASE)); + super(new VgnProvider(secretProperty("vgn.api_base"))); } @Test diff --git a/enabler/test/de/schildbach/pte/live/secrets.properties.template b/enabler/test/de/schildbach/pte/live/secrets.properties.template new file mode 100644 index 00000000..fd07402f --- /dev/null +++ b/enabler/test/de/schildbach/pte/live/secrets.properties.template @@ -0,0 +1,5 @@ +# Secrets are needed to run some of the live tests. +vgn.api_base = +navitia.authorization = +vbn.json_api_authorization = +vao.json_api_authorization =