source: josm/trunk/test/unit/org/openstreetmap/josm/gui/tagging/PresetClassificationsTest.java@ 7937

Last change on this file since 7937 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import static org.junit.Assert.assertTrue;
5
6import java.io.IOException;
7import java.util.Collection;
8import java.util.Collections;
9import java.util.EnumSet;
10import java.util.List;
11
12import org.junit.BeforeClass;
13import org.junit.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.OsmUtils;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.tools.Utils;
20import org.xml.sax.SAXException;
21
22public class PresetClassificationsTest {
23
24 final static TaggingPresetSelector.PresetClassifications classifications = new TaggingPresetSelector.PresetClassifications();
25
26 /**
27 * Setup test.
28 */
29 @BeforeClass
30 public static void setUp() throws IOException, SAXException {
31 JOSMFixture.createUnitTestFixture().init();
32 final Collection<TaggingPreset> presets = TaggingPresetReader.readAll("resource://data/defaultpresets.xml", true);
33 classifications.loadPresets(presets);
34 }
35
36 private List<TaggingPresetSelector.PresetClassification> getMatchingPresets(String searchText, OsmPrimitive w) {
37 return classifications.getMatchingPresets(searchText, true, true, EnumSet.of(TaggingPresetType.forPrimitive(w)), Collections.singleton(w));
38 }
39
40 private List<String> getMatchingPresetNames(String searchText, OsmPrimitive w) {
41 return Utils.transform(getMatchingPresets(searchText, w), new Utils.Function<TaggingPresetSelector.PresetClassification, String>() {
42 @Override
43 public String apply(TaggingPresetSelector.PresetClassification x) {
44 return x.preset.name;
45 }
46 });
47 }
48
49 @Test
50 public void testBuilding() throws Exception {
51 final Way w = new Way();
52 final Node n1 = new Node();
53 w.addNode(n1);
54 w.addNode(new Node());
55 w.addNode(new Node());
56 assertTrue("unclosed way should not match building preset", !getMatchingPresetNames("building", w).contains("Building"));
57 w.addNode(n1);
58 assertTrue("closed way should match building preset", getMatchingPresetNames("building", w).contains("Building"));
59 }
60
61 @Test
62 public void testRelationsForTram() {
63 final OsmPrimitive tram = OsmUtils.createPrimitive("way railway=tram");
64 assertTrue("railway=tram should match 'Railway Route' for relation creation", getMatchingPresetNames("route", tram).contains("Railway Route"));
65 assertTrue("railway=tram should match 'Public Transport Route' for relation creation", getMatchingPresetNames("route", tram).contains("Public Transport Route"));
66 assertTrue("railway=tram should not match 'Bus route'", !getMatchingPresetNames("route", tram).contains("Bus route"));
67 }
68}
Note: See TracBrowser for help on using the repository browser.