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