1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging;
|
---|
3 |
|
---|
4 | import org.junit.Assert;
|
---|
5 | import org.junit.BeforeClass;
|
---|
6 | import org.junit.Test;
|
---|
7 | import org.openstreetmap.TestUtils;
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.tools.Utils;
|
---|
10 | import org.xml.sax.SAXException;
|
---|
11 |
|
---|
12 | import java.io.IOException;
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.List;
|
---|
15 |
|
---|
16 | import static org.CustomMatchers.hasSize;
|
---|
17 | import static org.hamcrest.CoreMatchers.is;
|
---|
18 | import static org.junit.Assert.assertThat;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link TaggingPresetReader} class.
|
---|
22 | */
|
---|
23 | public class TaggingPresetReaderTest {
|
---|
24 |
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUpClass() {
|
---|
27 | Main.initApplicationPreferences();
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Gets path to test data directory for given ticketid.
|
---|
32 | * @param ticketid
|
---|
33 | * @return
|
---|
34 | */
|
---|
35 | protected static String getRegressionDataDir(int ticketid) {
|
---|
36 | return TestUtils.getTestDataRoot() + "/regress/" + ticketid;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Gets path to given file in test data directory for given ticketid.
|
---|
41 | * @param ticketid
|
---|
42 | * @param filename
|
---|
43 | * @return
|
---|
44 | */
|
---|
45 | protected static String getRegressionDataFile(int ticketid, String filename) {
|
---|
46 | return getRegressionDataDir(ticketid) + '/' + filename;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * #8954 - last checkbox in the preset is not added
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | public void test8954() throws SAXException, IOException {
|
---|
54 | String presetfile = getRegressionDataFile(8954, "preset.xml");
|
---|
55 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, false);
|
---|
56 | Assert.assertEquals("Number of preset items", 1, presets.size());
|
---|
57 | final TaggingPreset preset = presets.iterator().next();
|
---|
58 | Assert.assertEquals("Number of entries", 1, preset.data.size());
|
---|
59 | final TaggingPresetItem item = preset.data.get(0);
|
---|
60 | Assert.assertTrue("Entry is not checkbox", item instanceof TaggingPresetItems.Check);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void testNestedChunks() throws Exception {
|
---|
65 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(TestUtils.getTestDataRoot() + "preset_chunk.xml", true);
|
---|
66 | assertThat(presets, hasSize(1));
|
---|
67 | final TaggingPreset abc = presets.iterator().next();
|
---|
68 | final List<String> keys = Utils.transform(abc.data, new Utils.Function<TaggingPresetItem, String>() {
|
---|
69 | @Override
|
---|
70 | public String apply(TaggingPresetItem x) {
|
---|
71 | return ((TaggingPresetItems.Key) x).key;
|
---|
72 | }
|
---|
73 | });
|
---|
74 | assertThat(keys.toString(), is("[A1, A2, A3, B1, B2, B3, C1, C2, C3]"));
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Validate internal presets
|
---|
79 | * See #9027
|
---|
80 | */
|
---|
81 | @Test
|
---|
82 | public void readDefaulPresets() throws SAXException, IOException {
|
---|
83 | String presetfile = "resource://data/defaultpresets.xml";
|
---|
84 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, true);
|
---|
85 | Assert.assertTrue("Default presets are empty", presets.size()>0);
|
---|
86 | }
|
---|
87 |
|
---|
88 | }
|
---|