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

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

clear image provider cache before/after integration tests. The previous Jenkins job heap dump revealed it contained 14.000 entries and consumed up to 3Gb of memory

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