Changeset 15508 in josm for trunk/test/unit/org
- Timestamp:
- 2019-11-04T22:19:54+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java
r15242 r15508 8 8 import java.awt.GraphicsEnvironment; 9 9 import java.awt.HeadlessException; 10 import java.io.IOException; 11 import java.util.ArrayList; 10 12 import java.util.Arrays; 11 13 import java.util.Collection; … … 14 16 import java.util.List; 15 17 import java.util.Map; 18 import java.util.Map.Entry; 16 19 import java.util.Set; 17 20 import java.util.function.Consumer; … … 19 22 20 23 import org.apache.commons.lang3.exception.ExceptionUtils; 21 import org.junit.Rule; 24 import org.junit.BeforeClass; 25 import org.junit.ClassRule; 22 26 import org.junit.Test; 27 import org.openstreetmap.josm.TestUtils; 23 28 import org.openstreetmap.josm.data.Preferences; 24 29 import org.openstreetmap.josm.data.gpx.GpxData; … … 31 36 import org.openstreetmap.josm.spi.preferences.Config; 32 37 import org.openstreetmap.josm.testutils.JOSMTestRules; 38 import org.openstreetmap.josm.tools.Destroyable; 33 39 import org.openstreetmap.josm.tools.Utils; 34 40 … … 40 46 public class PluginHandlerTestIT { 41 47 48 private static List<String> errorsToIgnore = new ArrayList<>(); 42 49 /** 43 50 * Setup test. 44 51 */ 45 @ Rule52 @ClassRule 46 53 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 47 public JOSMTestRules test = new JOSMTestRules().main().projection().preferences().https().timeout(10*60*1000); 54 public static JOSMTestRules test = new JOSMTestRules().main().projection().preferences().https() 55 .timeout(10 * 60 * 1000); 56 57 /** 58 * Setup test 59 * 60 * @throws IOException in case of I/O error 61 */ 62 @BeforeClass 63 public static void beforeClass() throws IOException { 64 errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(PluginHandlerTestIT.class)); 65 } 48 66 49 67 /** … … 75 93 } 76 94 95 Map<String, Throwable> noRestartExceptions = new HashMap<>(); 96 testCompletelyRestartlessPlugins(loadedPlugins, noRestartExceptions); 97 77 98 debugPrint(invalidManifestEntries); 78 99 debugPrint(loadingExceptions); 79 100 debugPrint(layerExceptions); 101 debugPrint(noRestartExceptions); 102 103 invalidManifestEntries = filterKnownErrors(invalidManifestEntries); 104 loadingExceptions = filterKnownErrors(loadingExceptions); 105 layerExceptions = filterKnownErrors(layerExceptions); 106 noRestartExceptions = filterKnownErrors(noRestartExceptions); 107 80 108 String msg = Arrays.toString(invalidManifestEntries.entrySet().toArray()) + '\n' + 81 109 Arrays.toString(loadingExceptions.entrySet().toArray()) + '\n' + 82 Arrays.toString(layerExceptions.entrySet().toArray()); 110 Arrays.toString(layerExceptions.entrySet().toArray()) + '\n' 111 + Arrays.toString(noRestartExceptions.entrySet().toArray()); 83 112 assertTrue(msg, invalidManifestEntries.isEmpty() && loadingExceptions.isEmpty() && layerExceptions.isEmpty()); 113 } 114 115 private static void testCompletelyRestartlessPlugins(List<PluginInformation> loadedPlugins, 116 Map<String, Throwable> noRestartExceptions) { 117 try { 118 List<PluginInformation> restartable = loadedPlugins.parallelStream() 119 .filter(info -> PluginHandler.getPlugin(info.name) instanceof Destroyable) 120 .collect(Collectors.toList()); 121 // ensure good plugin behavior with regards to Destroyable (i.e., they can be 122 // removed and readded) 123 for (int i = 0; i < 2; i++) { 124 assertFalse(PluginHandler.removePlugins(restartable)); 125 assertTrue(restartable.stream().noneMatch(info -> PluginHandler.getPlugins().contains(info))); 126 loadPlugins(restartable); 127 } 128 129 assertTrue(PluginHandler.removePlugins(loadedPlugins)); 130 assertTrue(restartable.parallelStream().noneMatch(info -> PluginHandler.getPlugins().contains(info))); 131 } catch (Exception | LinkageError t) { 132 Throwable root = ExceptionUtils.getRootCause(t); 133 root.printStackTrace(); 134 noRestartExceptions.put(findFaultyPlugin(loadedPlugins, root), root); 135 } 136 } 137 138 private static <T> Map<String, T> filterKnownErrors(Map<String, T> errorMap) { 139 return errorMap.entrySet().parallelStream() 140 .filter(entry -> !errorsToIgnore.contains(convertEntryToString(entry))) 141 .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); 84 142 } 85 143 … … 87 145 System.out.println(invalidManifestEntries.entrySet() 88 146 .stream() 89 .map(e -> e.getKey() + "=\"" + e.getValue() + "\"")147 .map(e -> convertEntryToString(e)) 90 148 .collect(Collectors.joining(", "))); 149 } 150 151 private static String convertEntryToString(Entry<String, ?> entry) { 152 return entry.getKey() + "=\"" + entry.getValue() + "\""; 91 153 } 92 154 … … 134 196 downloadPlugins(plugins); 135 197 198 loadPlugins(plugins); 199 } 200 201 static void loadPlugins(List<PluginInformation> plugins) { 136 202 // Load early plugins 137 203 PluginHandler.loadEarlyPlugins(null, plugins, null);
Note:
See TracChangeset
for help on using the changeset viewer.