source: josm/trunk/test/functional/org/openstreetmap/josm/fixtures/JOSMFixture.java@ 2748

Last change on this file since 2748 was 2748, checked in by Gubaer, 14 years ago

new: JOSM now supports OAuth

See also online help for server preferences and new OAuth Authorisation Wizard

File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.fixtures;
3
4import static org.junit.Assert.fail;
5
6import java.io.File;
7import java.text.MessageFormat;
8import java.util.Properties;
9import java.util.logging.Level;
10import java.util.logging.Logger;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.osm.DataSetMergerTest;
14import org.openstreetmap.josm.data.projection.Mercator;
15import org.openstreetmap.josm.io.OsmApi;
16import org.openstreetmap.josm.tools.I18n;
17
18public class JOSMFixture {
19 static private final Logger logger = Logger.getLogger(JOSMFixture.class.getName());
20
21 static public JOSMFixture createUnitTestFixture() {
22 return new JOSMFixture("/test-unit-env.properties");
23 }
24
25 static public JOSMFixture createFunctionalTestFixture() {
26 return new JOSMFixture("/test-functional-env.properties");
27 }
28
29 private Properties testProperties;
30 private String testPropertiesResourceName;
31
32 public JOSMFixture(String testPropertiesResourceName) {
33 this.testPropertiesResourceName = testPropertiesResourceName;
34 }
35
36 public void init() {
37 testProperties = new Properties();
38
39 // load properties
40 //
41 try {
42 testProperties.load(DataSetMergerTest.class.getResourceAsStream(testPropertiesResourceName));
43 } catch(Exception e){
44 logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", testPropertiesResourceName));
45 fail(MessageFormat.format("failed to load property file ''{0}''. \nMake sure the path ''$project_root/test/config'' is on the classpath.", testPropertiesResourceName));
46 }
47
48 // check josm.home
49 //
50 String josmHome = testProperties.getProperty("josm.home");
51 if (josmHome == null) {
52 fail(MessageFormat.format("property ''{0}'' not set in test environment", "josm.home"));
53 } else {
54 File f = new File(josmHome);
55 if (! f.exists() || ! f.canRead()) {
56 fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing or not readable.\nEdit ''{2}'' and update the value ''josm.home''. ", "josm.home", josmHome,testPropertiesResourceName ));
57 }
58 }
59 System.setProperty("josm.home", josmHome);
60 I18n.init();
61 // initialize the plaform hook, and
62 Main.determinePlatformHook();
63 // call the really early hook before we anything else
64 Main.platform.preStartupHook();
65
66 Main.pref.init(false);
67
68 // init projection
69 Main.proj = new Mercator();
70
71 // make sure we don't upload to or test against production
72 //
73 String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase().trim();
74 if (url.startsWith("http://www.openstreetmap.org")
75 || url.startsWith("http://api.openstreetmap.org")) {
76 fail(MessageFormat.format("configured server url ''{0}'' seems to be a productive url, aborting.", url));
77 }
78 }
79}
Note: See TracBrowser for help on using the repository browser.