1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.history;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.fail;
|
---|
5 |
|
---|
6 | import java.awt.BorderLayout;
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.io.InputStream;
|
---|
10 | import java.text.MessageFormat;
|
---|
11 | import java.util.Properties;
|
---|
12 | import java.util.logging.Level;
|
---|
13 | import java.util.logging.Logger;
|
---|
14 |
|
---|
15 | import javax.swing.JFrame;
|
---|
16 |
|
---|
17 | import org.junit.BeforeClass;
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
20 | import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
|
---|
21 | import org.openstreetmap.josm.data.osm.history.History;
|
---|
22 | import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
|
---|
23 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
24 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
25 | import org.openstreetmap.josm.io.OsmServerHistoryReader;
|
---|
26 | import org.openstreetmap.josm.io.OsmTransferException;
|
---|
27 |
|
---|
28 | public class HistoryBrowserTest extends JFrame {
|
---|
29 |
|
---|
30 | static private Logger logger = Logger.getLogger(HistoryBrowserTest.class.getName());
|
---|
31 |
|
---|
32 | static Properties testProperties;
|
---|
33 |
|
---|
34 | @BeforeClass
|
---|
35 | static public void init() {
|
---|
36 | testProperties = new Properties();
|
---|
37 |
|
---|
38 | // load properties
|
---|
39 | //
|
---|
40 | try {
|
---|
41 | InputStream is = HistoryBrowserTest.class.getResourceAsStream("/test-functional-env.properties");
|
---|
42 | try {
|
---|
43 | testProperties.load(is);
|
---|
44 | } finally {
|
---|
45 | is.close();
|
---|
46 | }
|
---|
47 | } catch(IOException e){
|
---|
48 | logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
|
---|
49 | fail(MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
|
---|
50 | }
|
---|
51 |
|
---|
52 | // check josm.home
|
---|
53 | //
|
---|
54 | String josmHome = testProperties.getProperty("josm.home");
|
---|
55 | if (josmHome == null) {
|
---|
56 | fail(MessageFormat.format("property ''{0}'' not set in test environment", "josm.home"));
|
---|
57 | } else {
|
---|
58 | File f = new File(josmHome);
|
---|
59 | if (! f.exists() || ! f.canRead()) {
|
---|
60 | fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing or not readable", "josm.home", josmHome));
|
---|
61 | }
|
---|
62 | }
|
---|
63 | System.setProperty("josm.home", josmHome);
|
---|
64 | Main.pref.init(false);
|
---|
65 |
|
---|
66 | // init projection
|
---|
67 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
68 | }
|
---|
69 |
|
---|
70 | private HistoryBrowser browser;
|
---|
71 |
|
---|
72 | protected void build() {
|
---|
73 | setSize(500,500);
|
---|
74 | getContentPane().setLayout(new BorderLayout());
|
---|
75 | browser = new HistoryBrowser();
|
---|
76 | getContentPane().add(browser, BorderLayout.CENTER);
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected void populate(OsmPrimitiveType type, long id) {
|
---|
80 | OsmServerHistoryReader reader = new OsmServerHistoryReader(type, id);
|
---|
81 | HistoryDataSet ds = null;
|
---|
82 | try {
|
---|
83 | ds = reader.parseHistory(NullProgressMonitor.INSTANCE);
|
---|
84 | } catch(OsmTransferException e) {
|
---|
85 | Main.error(e);
|
---|
86 | return;
|
---|
87 | }
|
---|
88 | History h = ds.getHistory(new SimplePrimitiveId(id, type));
|
---|
89 | browser.populate(h);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Constructs a new {@code HistoryBrowserTest}.
|
---|
94 | */
|
---|
95 | public HistoryBrowserTest(){
|
---|
96 | build();
|
---|
97 | //populate(OsmPrimitiveType.NODE,354117);
|
---|
98 | //populate(OsmPrimitiveType.WAY,37951);
|
---|
99 | populate(OsmPrimitiveType.RELATION,5055);
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 | static public void main(String args[]) {
|
---|
104 | HistoryBrowserTest.init();
|
---|
105 | new HistoryBrowserTest().setVisible(true);
|
---|
106 | }
|
---|
107 | }
|
---|