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

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

fixes for unit tests

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 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 I18n.set(Main.pref.get("language", "en"));
57
58 // init projection
59 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
60
61 // make sure we don't upload to or test against production
62 //
63 String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase().trim();
64 if (url.startsWith("http://www.openstreetmap.org") || url.startsWith("http://api.openstreetmap.org")
65 || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://api.openstreetmap.org")) {
66 fail(MessageFormat.format("configured server url ''{0}'' seems to be a productive url, aborting.", url));
67 }
68 }
69}
Note: See TracBrowser for help on using the repository browser.