source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java@ 10326

Last change on this file since 10326 was 10326, checked in by Don-vip, 8 years ago

ignore https://github.com/yopaseopor/traffic_signs_preset_JOSM and https://github.com/yopaseopor/traffic_signs_style_JOSM from integration tests because of far too frequent missing icons errors, see https://github.com/yopaseopor/traffic_signs_style_JOSM/issues/1, https://github.com/yopaseopor/traffic_signs_style_JOSM/issues/2, https://github.com/yopaseopor/traffic_signs_style_JOSM/issues/4 etc.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.map;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.io.IOException;
8import java.util.ArrayList;
9import java.util.Collection;
10import java.util.HashSet;
11import java.util.Set;
12
13import org.junit.BeforeClass;
14import org.junit.Rule;
15import org.junit.Test;
16import org.junit.rules.Timeout;
17import org.openstreetmap.josm.JOSMFixture;
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
20import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
21import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
22import org.xml.sax.SAXException;
23
24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25
26/**
27 * Integration tests of {@link TaggingPresetPreference} class.
28 */
29public class TaggingPresetPreferenceTestIT {
30
31 /**
32 * Global timeout applied to all test methods.
33 */
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public Timeout globalTimeout = Timeout.seconds(10*60);
37
38 /**
39 * Setup test.
40 */
41 @BeforeClass
42 public static void setUpBeforeClass() {
43 JOSMFixture.createUnitTestFixture().init();
44 }
45
46 /**
47 * Test that available tagging presets are valid.
48 * @throws Exception in case of error
49 */
50 @Test
51 public void testValidityOfAvailablePresets() throws Exception {
52 Collection<ExtendedSourceEntry> sources = new TaggingPresetPreference.TaggingPresetSourceEditor()
53 .loadAndGetAvailableSources();
54 assertFalse(sources.isEmpty());
55 // Double traditional timeouts to avoid random problems
56 Main.pref.putInteger("socket.timeout.connect", 30);
57 Main.pref.putInteger("socket.timeout.read", 60);
58 Collection<Throwable> allErrors = new ArrayList<>();
59 Set<String> allMessages = new HashSet<>();
60 for (ExtendedSourceEntry source : sources) {
61 System.out.println(source.url);
62 try {
63 testPresets(allMessages, source);
64 } catch (IOException e) {
65 try {
66 Main.warn(e);
67 // try again in case of temporary network error
68 testPresets(allMessages, source);
69 } catch (SAXException | IOException e1) {
70 e.printStackTrace();
71 // ignore frequent network errors with www.freietonne.de causing too much Jenkins failures
72 // also ignore https://github.com/yopaseopor/traffic_signs_preset_JOSM because of far too frequent missing icons errors
73 if (!source.url.contains("www.freietonne.de") && !source.url.contains("yopaseopor/traffic_signs")) {
74 allErrors.add(e1);
75 }
76 System.out.println(" => KO");
77 }
78 } catch (SAXException e) {
79 e.printStackTrace();
80 allErrors.add(e);
81 System.out.println(" => KO");
82 }
83 }
84 assertTrue(allErrors.toString(), allErrors.isEmpty());
85 assertTrue(allMessages.toString(), allMessages.isEmpty());
86 }
87
88 private static void testPresets(Set<String> allMessages, ExtendedSourceEntry source) throws SAXException, IOException {
89 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
90 assertFalse(presets.isEmpty());
91 Collection<String> errorsAndWarnings = Main.getLastErrorAndWarnings();
92 boolean error = false;
93 for (String message : errorsAndWarnings) {
94 if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) {
95 error = true;
96 allMessages.add(message);
97 }
98 }
99 System.out.println(error ? " => KO" : " => OK");
100 if (error) {
101 Main.clearLastErrorAndWarnings();
102 }
103 }
104}
Note: See TracBrowser for help on using the repository browser.