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

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

make the distinction between unit tests (*Test.java) and integration tests (*TestIT.java)

File size: 3.4 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
24/**
25 * Integration tests of {@link TaggingPresetPreference} class.
26 */
27public class TaggingPresetPreferenceTestIT {
28
29 /**
30 * Global timeout applied to all test methods.
31 */
32 @Rule
33 public Timeout globalTimeout = Timeout.seconds(10*60);
34
35 /**
36 * Setup test.
37 */
38 @BeforeClass
39 public static void setUpBeforeClass() {
40 JOSMFixture.createUnitTestFixture().init();
41 }
42
43 /**
44 * Test that available tagging presets are valid.
45 */
46 @Test
47 public void testValidityOfAvailablePresets() {
48 Collection<ExtendedSourceEntry> sources = new TaggingPresetPreference.TaggingPresetSourceEditor()
49 .loadAndGetAvailableSources();
50 assertFalse(sources.isEmpty());
51 // Double traditional timeouts to avoid random problems
52 Main.pref.putInteger("socket.timeout.connect", 30);
53 Main.pref.putInteger("socket.timeout.read", 60);
54 Collection<Throwable> allErrors = new ArrayList<>();
55 Set<String> allMessages = new HashSet<>();
56 for (ExtendedSourceEntry source : sources) {
57 System.out.println(source.url);
58 try {
59 testPresets(allMessages, source);
60 } catch (IOException e) {
61 try {
62 Main.warn(e);
63 // try again in case of temporary network error
64 testPresets(allMessages, source);
65 } catch (SAXException | IOException e1) {
66 e.printStackTrace();
67 allErrors.add(e1);
68 System.out.println(" => KO");
69 }
70 } catch (SAXException e) {
71 e.printStackTrace();
72 allErrors.add(e);
73 System.out.println(" => KO");
74 }
75 }
76 assertTrue(allErrors.isEmpty());
77 assertTrue(allMessages.isEmpty());
78 }
79
80 private static void testPresets(Set<String> allMessages, ExtendedSourceEntry source) throws SAXException, IOException {
81 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
82 assertFalse(presets.isEmpty());
83 Collection<String> errorsAndWarnings = Main.getLastErrorAndWarnings();
84 boolean error = false;
85 for (String message : errorsAndWarnings) {
86 if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) {
87 error = true;
88 allMessages.add(message);
89 }
90 }
91 System.out.println(error ? " => KO" : " => OK");
92 if (error) {
93 Main.clearLastErrorAndWarnings();
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.