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

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

test cleanup

File size: 2.4 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 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
55 Main.pref.init(false);
56
57 // init projection
58 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
59
60 // make sure we don't upload to or test against production
61 //
62 String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase().trim();
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")) {
65 fail(MessageFormat.format("configured server url ''{0}'' seems to be a productive url, aborting.", url));
66 }
67 }
68}
Note: See TracBrowser for help on using the repository browser.