1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.map;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 | import static org.junit.Assert.fail;
|
---|
7 |
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.Collection;
|
---|
11 | import java.util.HashSet;
|
---|
12 | import java.util.Set;
|
---|
13 |
|
---|
14 | import org.junit.BeforeClass;
|
---|
15 | import org.junit.Test;
|
---|
16 | import org.openstreetmap.josm.JOSMFixture;
|
---|
17 | import org.openstreetmap.josm.Main;
|
---|
18 | import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
|
---|
19 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
|
---|
20 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
|
---|
21 | import org.xml.sax.SAXException;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests of {@link TaggingPresetPreference} class.
|
---|
25 | */
|
---|
26 | public class TaggingPresetPreferenceTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test.
|
---|
30 | */
|
---|
31 | @BeforeClass
|
---|
32 | public static void setUpBeforeClass() {
|
---|
33 | JOSMFixture.createUnitTestFixture().init();
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Test that available tagging presets are valid.
|
---|
38 | */
|
---|
39 | @Test
|
---|
40 | public void testValidityOfAvailablePresets() {
|
---|
41 | Collection<ExtendedSourceEntry> sources = new TaggingPresetPreference.TaggingPresetSourceEditor()
|
---|
42 | .loadAndGetAvailableSources();
|
---|
43 | assertFalse(sources.isEmpty());
|
---|
44 | Collection<Throwable> allErrors = new ArrayList<>();
|
---|
45 | Set<String> allMessages = new HashSet<>();
|
---|
46 | for (ExtendedSourceEntry source : sources) {
|
---|
47 | System.out.print(source.url);
|
---|
48 | try {
|
---|
49 | Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
|
---|
50 | assertFalse(presets.isEmpty());
|
---|
51 | System.out.println(" => OK");
|
---|
52 | allMessages.addAll(Main.getLastErrorAndWarnings());
|
---|
53 | } catch (SAXException | IOException e) {
|
---|
54 | e.printStackTrace();
|
---|
55 | allErrors.add(e);
|
---|
56 | System.out.println(" => KO");
|
---|
57 | }
|
---|
58 | }
|
---|
59 | assertTrue(allErrors.isEmpty());
|
---|
60 | for (String message : allMessages) {
|
---|
61 | if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) {
|
---|
62 | fail(message);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|