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

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

fix #9778, fix #9806 - access OSM API and JOSM website in HTTPS by default + other HTTPS links where applicable + update CONTRIBUTION

File size: 3.2 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.projection.Projections;
14import org.openstreetmap.josm.io.OsmApi;
15import org.openstreetmap.josm.tools.I18n;
16
17public class JOSMFixture {
18 static private final Logger logger = Logger.getLogger(JOSMFixture.class.getName());
19
20 static public JOSMFixture createUnitTestFixture() {
21 return new JOSMFixture("/test-unit-env.properties");
22 }
23
24 static public JOSMFixture createFunctionalTestFixture() {
25 return new JOSMFixture("/test-functional-env.properties");
26 }
27
28 private Properties testProperties;
29 private String testPropertiesResourceName;
30
31 public JOSMFixture(String testPropertiesResourceName) {
32 this.testPropertiesResourceName = testPropertiesResourceName;
33 }
34
35 public void init() {
36 testProperties = new Properties();
37
38 // load properties
39 //
40 try {
41 testProperties.load(JOSMFixture.class.getResourceAsStream(testPropertiesResourceName));
42 } catch(Exception e){
43 logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", testPropertiesResourceName));
44 fail(MessageFormat.format("failed to load property file ''{0}''. \nMake sure the path ''$project_root/test/config'' is on the classpath.", testPropertiesResourceName));
45 }
46
47 // check josm.home
48 //
49 String josmHome = testProperties.getProperty("josm.home");
50 if (josmHome == null) {
51 fail(MessageFormat.format("property ''{0}'' not set in test environment", "josm.home"));
52 } else {
53 File f = new File(josmHome);
54 if (! f.exists() || ! f.canRead()) {
55 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 ));
56 }
57 }
58 System.setProperty("josm.home", josmHome);
59 Main.initApplicationPreferences();
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.setProjection(Projections.getProjectionByCode("EPSG:3857")); // 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") || url.startsWith("http://api.openstreetmap.org")
75 || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://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.