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.Iterator;
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Set;
|
---|
12 |
|
---|
13 | import org.junit.BeforeClass;
|
---|
14 | import org.junit.Rule;
|
---|
15 | import org.junit.Test;
|
---|
16 | import org.junit.rules.Timeout;
|
---|
17 | import org.openstreetmap.josm.JOSMFixture;
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Integration tests of {@link PluginHandler} class.
|
---|
23 | */
|
---|
24 | public class PluginHandlerTestIT {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Global timeout applied to all test methods.
|
---|
28 | */
|
---|
29 | @Rule
|
---|
30 | public Timeout globalTimeout = Timeout.seconds(10*60);
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Setup test.
|
---|
34 | */
|
---|
35 | @BeforeClass
|
---|
36 | public static void setUp() {
|
---|
37 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Test that available plugins rules can be loaded.
|
---|
42 | */
|
---|
43 | @Test
|
---|
44 | public void testValidityOfAvailablePlugins() {
|
---|
45 | // Download complete list of plugins
|
---|
46 | ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask(
|
---|
47 | Main.pref.getOnlinePluginSites());
|
---|
48 | pluginInfoDownloadTask.run();
|
---|
49 | List<PluginInformation> plugins = pluginInfoDownloadTask.getAvailablePlugins();
|
---|
50 | System.out.println("Original plugin list contains " + plugins.size() + " plugins");
|
---|
51 | assertFalse(plugins.isEmpty());
|
---|
52 | PluginInformation info = plugins.get(0);
|
---|
53 | assertFalse(info.getName().isEmpty());
|
---|
54 | assertFalse(info.getClass().getName().isEmpty());
|
---|
55 |
|
---|
56 | // Filter deprecated and unmaintained ones
|
---|
57 | List<String> uncooperatingPlugins = Arrays.asList("ebdirigo");
|
---|
58 | Set<String> deprecatedPlugins = PluginHandler.getDeprecatedAndUnmaintainedPlugins();
|
---|
59 | for (Iterator<PluginInformation> it = plugins.iterator(); it.hasNext();) {
|
---|
60 | PluginInformation pi = it.next();
|
---|
61 | if (deprecatedPlugins.contains(pi.name) || uncooperatingPlugins.contains(pi.name)) {
|
---|
62 | System.out.println("Ignoring " + pi.name + " (deprecated, unmaintained, or uncooperative)");
|
---|
63 | it.remove();
|
---|
64 | }
|
---|
65 | }
|
---|
66 | System.out.println("Filtered plugin list contains " + plugins.size() + " plugins");
|
---|
67 |
|
---|
68 | // Update the locally installed plugins
|
---|
69 | PluginDownloadTask pluginDownloadTask = new PluginDownloadTask(NullProgressMonitor.INSTANCE, plugins, null);
|
---|
70 | pluginDownloadTask.run();
|
---|
71 | assertTrue(pluginDownloadTask.getFailedPlugins().toString(), pluginDownloadTask.getFailedPlugins().isEmpty());
|
---|
72 | assertEquals(plugins.size(), pluginDownloadTask.getDownloadedPlugins().size());
|
---|
73 |
|
---|
74 | // Update Plugin info for downloaded plugins
|
---|
75 | PluginHandler.refreshLocalUpdatedPluginInfo(pluginDownloadTask.getDownloadedPlugins());
|
---|
76 |
|
---|
77 | // Load early plugins
|
---|
78 | PluginHandler.loadEarlyPlugins(null, plugins, null);
|
---|
79 |
|
---|
80 | // Load late plugins
|
---|
81 | PluginHandler.loadLatePlugins(null, plugins, null);
|
---|
82 |
|
---|
83 | assertTrue(PluginHandler.pluginLoadingExceptions.toString(), PluginHandler.pluginLoadingExceptions.isEmpty());
|
---|
84 | }
|
---|
85 | }
|
---|