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