1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.plugins;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.Iterator;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Set;
|
---|
13 |
|
---|
14 | import org.junit.BeforeClass;
|
---|
15 | import org.junit.Rule;
|
---|
16 | import org.junit.Test;
|
---|
17 | import org.junit.rules.Timeout;
|
---|
18 | import org.openstreetmap.josm.JOSMFixture;
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Integration tests of {@link PluginHandler} class.
|
---|
26 | */
|
---|
27 | public class PluginHandlerTestIT {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Global timeout applied to all test methods.
|
---|
31 | */
|
---|
32 | @Rule
|
---|
33 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
34 | public Timeout globalTimeout = Timeout.seconds(10*60);
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Setup test.
|
---|
38 | */
|
---|
39 | @BeforeClass
|
---|
40 | public static void setUp() {
|
---|
41 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Test that available plugins rules can be loaded.
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | public void testValidityOfAvailablePlugins() {
|
---|
49 | // Download complete list of plugins
|
---|
50 | ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask(
|
---|
51 | Main.pref.getOnlinePluginSites());
|
---|
52 | pluginInfoDownloadTask.run();
|
---|
53 | List<PluginInformation> plugins = pluginInfoDownloadTask.getAvailablePlugins();
|
---|
54 | System.out.println("Original plugin list contains " + plugins.size() + " plugins");
|
---|
55 | assertFalse(plugins.isEmpty());
|
---|
56 | PluginInformation info = plugins.get(0);
|
---|
57 | assertFalse(info.getName().isEmpty());
|
---|
58 | assertFalse(info.getClass().getName().isEmpty());
|
---|
59 |
|
---|
60 | // Filter deprecated and unmaintained ones, or those not responsive enough to match our continuous integration needs
|
---|
61 | List<String> uncooperatingPlugins = Arrays.asList("ebdirigo", "scoutsigns");
|
---|
62 | Set<String> deprecatedPlugins = PluginHandler.getDeprecatedAndUnmaintainedPlugins();
|
---|
63 | for (Iterator<PluginInformation> it = plugins.iterator(); it.hasNext();) {
|
---|
64 | PluginInformation pi = it.next();
|
---|
65 | if (deprecatedPlugins.contains(pi.name) || uncooperatingPlugins.contains(pi.name)) {
|
---|
66 | System.out.println("Ignoring " + pi.name + " (deprecated, unmaintained, or uncooperative)");
|
---|
67 | it.remove();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | System.out.println("Filtered plugin list contains " + plugins.size() + " plugins");
|
---|
71 |
|
---|
72 | // Download plugins
|
---|
73 | downloadPlugins(plugins);
|
---|
74 |
|
---|
75 | // Load early plugins
|
---|
76 | PluginHandler.loadEarlyPlugins(null, plugins, null);
|
---|
77 |
|
---|
78 | // Load late plugins
|
---|
79 | PluginHandler.loadLatePlugins(null, plugins, null);
|
---|
80 |
|
---|
81 | assertTrue(PluginHandler.pluginLoadingExceptions.toString(), PluginHandler.pluginLoadingExceptions.isEmpty());
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Download plugins
|
---|
86 | * @param plugins plugins to download
|
---|
87 | */
|
---|
88 | public static void downloadPlugins(Collection<PluginInformation> plugins) {
|
---|
89 | // Update the locally installed plugins
|
---|
90 | PluginDownloadTask pluginDownloadTask = new PluginDownloadTask(NullProgressMonitor.INSTANCE, plugins, null);
|
---|
91 | pluginDownloadTask.run();
|
---|
92 | assertTrue(pluginDownloadTask.getFailedPlugins().toString(), pluginDownloadTask.getFailedPlugins().isEmpty());
|
---|
93 | assertEquals(plugins.size(), pluginDownloadTask.getDownloadedPlugins().size());
|
---|
94 |
|
---|
95 | // Update Plugin info for downloaded plugins
|
---|
96 | PluginHandler.refreshLocalUpdatedPluginInfo(pluginDownloadTask.getDownloadedPlugins());
|
---|
97 | }
|
---|
98 | }
|
---|