source: josm/trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java@ 7087

Last change on this file since 7087 was 7085, checked in by Don-vip, 10 years ago

allow to disable auto-save of preferences file for unit tests (ant chmod does not seem to work from Jenkins)

File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm;
3
4import static org.junit.Assert.fail;
5
6import java.io.File;
7import java.text.MessageFormat;
8import java.util.logging.Logger;
9
10import org.openstreetmap.josm.data.projection.Projections;
11import org.openstreetmap.josm.io.OsmApi;
12import org.openstreetmap.josm.tools.I18n;
13
14public class JOSMFixture {
15 static private final Logger logger = Logger.getLogger(JOSMFixture.class.getName());
16
17 static public JOSMFixture createUnitTestFixture() {
18 return new JOSMFixture("test/config/unit-josm.home");
19 }
20
21 static public JOSMFixture createFunctionalTestFixture() {
22 return new JOSMFixture("test/config/functional-josm.home");
23 }
24
25 static public JOSMFixture createPerformanceTestFixture() {
26 return new JOSMFixture("test/config/performance-josm.home");
27 }
28
29 private final String josmHome;
30
31 public JOSMFixture(String josmHome) {
32 this.josmHome = josmHome;
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()) {
44 fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing or not readable.", "josm.home", josmHome));
45 }
46 }
47 System.setProperty("josm.home", josmHome);
48 Main.initApplicationPreferences();
49 Main.pref.enableSaveOnPut(false);
50 I18n.init();
51 // initialize the plaform hook, and
52 Main.determinePlatformHook();
53 // call the really early hook before we anything else
54 Main.platform.preStartupHook();
55
56 Main.pref.init(false);
57 I18n.set(Main.pref.get("language", "en"));
58
59 // init projection
60 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
61
62 // make sure we don't upload to or test against production
63 //
64 String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase().trim();
65 if (url.startsWith("http://www.openstreetmap.org") || url.startsWith("http://api.openstreetmap.org")
66 || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://api.openstreetmap.org")) {
67 fail(MessageFormat.format("configured server url ''{0}'' seems to be a productive url, aborting.", url));
68 }
69 }
70}
Note: See TracBrowser for help on using the repository browser.