1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.testutils;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
5 | import org.openstreetmap.josm.data.notes.Note;
|
---|
6 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
7 | import org.openstreetmap.josm.data.osm.IPrimitive;
|
---|
8 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
9 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
10 | import org.openstreetmap.josm.io.Capabilities;
|
---|
11 | import org.openstreetmap.josm.io.OsmApi;
|
---|
12 | import org.openstreetmap.josm.io.OsmApiInitializationException;
|
---|
13 | import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
---|
14 | import org.openstreetmap.josm.io.OsmTransferException;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * A fake OSM API server. It is used to test again.
|
---|
18 | * <p>
|
---|
19 | * It provides only basic features.
|
---|
20 | * <p>
|
---|
21 | * These image servers are blacklisted:
|
---|
22 | * <ul>
|
---|
23 | * <li>.*blacklisted.*</li>
|
---|
24 | * <li>^(invalid|bad).*</li>
|
---|
25 | * </ul>
|
---|
26 | *
|
---|
27 | * @author Michael Zangl
|
---|
28 | */
|
---|
29 | public class FakeOsmApi extends OsmApi {
|
---|
30 |
|
---|
31 | private static FakeOsmApi instance;
|
---|
32 |
|
---|
33 | private boolean initialized = false;
|
---|
34 |
|
---|
35 | protected FakeOsmApi() {
|
---|
36 | super("http://fake.xxx/api");
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public void initialize(ProgressMonitor monitor, boolean fastFail)
|
---|
41 | throws OsmTransferCanceledException, OsmApiInitializationException {
|
---|
42 | // we do not connect to any server so we do not need that.
|
---|
43 | initialized = true;
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public synchronized Capabilities getCapabilities() {
|
---|
48 | if (!initialized) {
|
---|
49 | return null;
|
---|
50 | } else {
|
---|
51 | Capabilities capabilities = new Capabilities();
|
---|
52 | capabilities.put("blacklist", "regex", ".*blacklisted.*");
|
---|
53 | capabilities.put("blacklist", "regex", "^https?://(invalid|bad).*");
|
---|
54 | capabilities.put("version", "minimum", "0.6");
|
---|
55 | capabilities.put("version", "maximum", "0.6");
|
---|
56 | return capabilities;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public void createPrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
|
---|
62 | throw new UnsupportedOperationException("Not implemented");
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public void modifyPrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
|
---|
67 | throw new UnsupportedOperationException("Not implemented");
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
|
---|
72 | throw new UnsupportedOperationException("Not implemented");
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public void openChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException {
|
---|
77 | throw new UnsupportedOperationException("Not implemented");
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public void updateChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
|
---|
82 | throw new UnsupportedOperationException("Not implemented");
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public void closeChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
|
---|
87 | throw new UnsupportedOperationException("Not implemented");
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Override
|
---|
91 | public Note createNote(LatLon latlon, String text, ProgressMonitor monitor) throws OsmTransferException {
|
---|
92 | throw new UnsupportedOperationException("Not implemented");
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Override
|
---|
96 | public Note addCommentToNote(Note note, String comment, ProgressMonitor monitor) throws OsmTransferException {
|
---|
97 | throw new UnsupportedOperationException("Not implemented");
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public Note closeNote(Note note, String closeMessage, ProgressMonitor monitor) throws OsmTransferException {
|
---|
102 | throw new UnsupportedOperationException("Not implemented");
|
---|
103 | }
|
---|
104 |
|
---|
105 | @Override
|
---|
106 | public Note reopenNote(Note note, String reactivateMessage, ProgressMonitor monitor) throws OsmTransferException {
|
---|
107 | throw new UnsupportedOperationException("Not implemented");
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Gets and caches an instance of this API.
|
---|
112 | * @return The API intance. Always the same object.
|
---|
113 | */
|
---|
114 | public static synchronized FakeOsmApi getInstance() {
|
---|
115 | if (instance == null) {
|
---|
116 | instance = new FakeOsmApi();
|
---|
117 | cacheInstance(instance);
|
---|
118 | }
|
---|
119 | return instance;
|
---|
120 | }
|
---|
121 | }
|
---|