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 | import static org.junit.Assert.assertTrue;
|
---|
8 |
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.util.Collection;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.stream.Collectors;
|
---|
13 |
|
---|
14 | import org.junit.Assert;
|
---|
15 | import org.junit.Rule;
|
---|
16 | import org.junit.Test;
|
---|
17 | import org.openstreetmap.josm.TestUtils;
|
---|
18 | import org.openstreetmap.josm.gui.tagging.presets.items.Check;
|
---|
19 | import org.openstreetmap.josm.gui.tagging.presets.items.Key;
|
---|
20 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
21 | import org.xml.sax.SAXException;
|
---|
22 |
|
---|
23 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Unit tests of {@link TaggingPresetReader} class.
|
---|
27 | */
|
---|
28 | public class TaggingPresetReaderTest {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Setup rule
|
---|
32 | */
|
---|
33 | @Rule
|
---|
34 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
35 | public JOSMTestRules test = new JOSMTestRules().platform();
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * #8954 - last checkbox in the preset is not added
|
---|
39 | * @throws SAXException if any XML error occurs
|
---|
40 | * @throws IOException if any I/O error occurs
|
---|
41 | */
|
---|
42 | @Test
|
---|
43 | public void testTicket8954() throws SAXException, IOException {
|
---|
44 | String presetfile = TestUtils.getRegressionDataFile(8954, "preset.xml");
|
---|
45 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, false);
|
---|
46 | Assert.assertEquals("Number of preset items", 1, presets.size());
|
---|
47 | final TaggingPreset preset = presets.iterator().next();
|
---|
48 | Assert.assertEquals("Number of entries", 1, preset.data.size());
|
---|
49 | final TaggingPresetItem item = preset.data.get(0);
|
---|
50 | Assert.assertTrue("Entry is not checkbox", item instanceof Check);
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Test nested chunks
|
---|
55 | * @throws SAXException if any XML error occurs
|
---|
56 | * @throws IOException if any I/O error occurs
|
---|
57 | */
|
---|
58 | @Test
|
---|
59 | public void testNestedChunks() throws SAXException, IOException {
|
---|
60 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(TestUtils.getTestDataRoot() + "preset_chunk.xml", true);
|
---|
61 | assertThat(presets, hasSize(1));
|
---|
62 | final TaggingPreset abc = presets.iterator().next();
|
---|
63 | assertTrue(abc.data.stream().allMatch(Key.class::isInstance));
|
---|
64 | final List<String> keys = abc.data.stream().map(x -> ((Key) x).key).collect(Collectors.toList());
|
---|
65 | assertEquals("[A1, A2, A3, B1, B2, B3, C1, C2, C3]", keys.toString());
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Validate internal presets
|
---|
70 | * See #9027
|
---|
71 | * @throws SAXException if any XML error occurs
|
---|
72 | * @throws IOException if any I/O error occurs
|
---|
73 | */
|
---|
74 | @Test
|
---|
75 | public void testReadDefaulPresets() throws SAXException, IOException {
|
---|
76 | String presetfile = "resource://data/defaultpresets.xml";
|
---|
77 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, true);
|
---|
78 | Assert.assertTrue("Default presets are empty", presets.size() > 0);
|
---|
79 | }
|
---|
80 | }
|
---|