[2600] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[7068] | 2 | package org.openstreetmap.josm;
|
---|
[2600] | 3 |
|
---|
| 4 | import static org.junit.Assert.fail;
|
---|
| 5 |
|
---|
| 6 | import java.io.File;
|
---|
| 7 | import java.text.MessageFormat;
|
---|
| 8 | import java.util.logging.Logger;
|
---|
| 9 |
|
---|
[5556] | 10 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
[2600] | 11 | import org.openstreetmap.josm.io.OsmApi;
|
---|
[2748] | 12 | import org.openstreetmap.josm.tools.I18n;
|
---|
[2600] | 13 |
|
---|
| 14 | public class JOSMFixture {
|
---|
| 15 | static private final Logger logger = Logger.getLogger(JOSMFixture.class.getName());
|
---|
| 16 |
|
---|
| 17 | static public JOSMFixture createUnitTestFixture() {
|
---|
[7068] | 18 | return new JOSMFixture("test/config/unit-josm.home");
|
---|
[2600] | 19 | }
|
---|
| 20 |
|
---|
| 21 | static public JOSMFixture createFunctionalTestFixture() {
|
---|
[7068] | 22 | return new JOSMFixture("test/config/functional-josm.home");
|
---|
[2600] | 23 | }
|
---|
| 24 |
|
---|
[7068] | 25 | static public JOSMFixture createPerformanceTestFixture() {
|
---|
| 26 | return new JOSMFixture("test/config/performance-josm.home");
|
---|
| 27 | }
|
---|
[2600] | 28 |
|
---|
[7068] | 29 | private final String josmHome;
|
---|
| 30 |
|
---|
| 31 | public JOSMFixture(String josmHome) {
|
---|
| 32 | this.josmHome = josmHome;
|
---|
[2600] | 33 | }
|
---|
| 34 |
|
---|
| 35 | public void init() {
|
---|
| 36 |
|
---|
| 37 | // check josm.home
|
---|
| 38 | //
|
---|
| 39 | if (josmHome == null) {
|
---|
| 40 | fail(MessageFormat.format("property ''{0}'' not set in test environment", "josm.home"));
|
---|
| 41 | } else {
|
---|
| 42 | File f = new File(josmHome);
|
---|
| 43 | if (! f.exists() || ! f.canRead()) {
|
---|
[7068] | 44 | fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing or not readable.", "josm.home", josmHome));
|
---|
[2600] | 45 | }
|
---|
| 46 | }
|
---|
[3988] | 47 | System.setProperty("josm.home", josmHome);
|
---|
[6471] | 48 | Main.initApplicationPreferences();
|
---|
[2748] | 49 | I18n.init();
|
---|
| 50 | // initialize the plaform hook, and
|
---|
| 51 | Main.determinePlatformHook();
|
---|
| 52 | // call the really early hook before we anything else
|
---|
| 53 | Main.platform.preStartupHook();
|
---|
| 54 |
|
---|
[2600] | 55 | Main.pref.init(false);
|
---|
| 56 |
|
---|
| 57 | // init projection
|
---|
[5556] | 58 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
[2600] | 59 |
|
---|
| 60 | // make sure we don't upload to or test against production
|
---|
| 61 | //
|
---|
| 62 | String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase().trim();
|
---|
[6920] | 63 | if (url.startsWith("http://www.openstreetmap.org") || url.startsWith("http://api.openstreetmap.org")
|
---|
| 64 | || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://api.openstreetmap.org")) {
|
---|
[2600] | 65 | fail(MessageFormat.format("configured server url ''{0}'' seems to be a productive url, aborting.", url));
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|