Changeset 18694 in josm
- Timestamp:
- 2023-03-16T22:09:01+01:00 (21 months ago)
- Location:
- trunk
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r18211 r18694 18 18 import java.util.Collection; 19 19 import java.util.Collections; 20 import java.util.HashSet; 20 21 import java.util.LinkedList; 21 22 import java.util.List; … … 432 433 return; 433 434 } 435 int toUpdateSize; 436 boolean refreshRequired = false; 437 do { 438 toUpdateSize = toUpdate.size(); 439 Set<PluginInformation> enabledPlugins = new HashSet<>(PluginHandler.getPlugins()); 440 enabledPlugins.addAll(toUpdate); 441 Set<PluginInformation> toAdd = new HashSet<>(); 442 for (PluginInformation pi : toUpdate) { 443 if (!PluginHandler.checkRequiredPluginsPreconditions(null, enabledPlugins, pi, false)) { 444 // Time to find the missing plugins... 445 toAdd.addAll(pi.getRequiredPlugins().stream().filter(plugin -> PluginHandler.getPlugin(plugin) == null) 446 .map(plugin -> model.getPluginInformation(plugin)) 447 .collect(Collectors.toSet())); 448 } 449 } 450 toAdd.forEach(plugin -> model.setPluginSelected(plugin.name, true)); 451 refreshRequired |= !toAdd.isEmpty(); // We need to force refresh the checkboxes if we are adding new plugins 452 toAdd.removeIf(plugin -> !plugin.isUpdateRequired()); // Avoid downloading plugins that already exist 453 toUpdate.addAll(toAdd); 454 } while (toUpdateSize != toUpdate.size()); 455 434 456 pluginDownloadTask.setPluginsToDownload(toUpdate); 435 457 MainApplication.worker.submit(pluginDownloadTask); 436 458 MainApplication.worker.submit(pluginDownloadContinuation); 459 if (refreshRequired) { 460 // Needed since we need to recreate the checkboxes to show the enabled dependent plugins that were not previously enabled 461 pnlPluginPreferences.resetDisplayedComponents(); 462 } 463 GuiHelper.runInEDT(pnlPluginPreferences::refreshView); 437 464 }; 438 465 -
trunk/test/data/META-INF/services/org.junit.jupiter.api.extension.Extension
r18672 r18694 1 # These are the default extensions to run (all tests with JOSMTestRules would have done these by default) 2 org.openstreetmap.josm.testutils.annotations.BasicPreferences$BasicPreferencesExtension 1 3 org.openstreetmap.josm.testutils.annotations.HTTP$HTTPExtension 4 org.openstreetmap.josm.testutils.annotations.I18n$I18nExtension 5 org.openstreetmap.josm.testutils.annotations.JosmDefaults$DefaultsExtension 2 6 org.openstreetmap.josm.testutils.annotations.LayerManager$LayerManagerExtension 7 org.openstreetmap.josm.testutils.annotations.Logging$LoggingExtension 8 org.openstreetmap.josm.testutils.annotations.Timezone$TimezoneExtension -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
r18690 r18694 30 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 31 31 import org.awaitility.Awaitility; 32 import org.junit.Before; 32 33 import org.junit.Rule; 33 34 import org.junit.Test; … … 35 36 import org.openstreetmap.josm.data.Bounds; 36 37 import org.openstreetmap.josm.data.DataSource; 38 import org.openstreetmap.josm.data.SystemOfMeasurement; 37 39 import org.openstreetmap.josm.data.imagery.ImageryInfo; 38 40 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; … … 63 65 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 64 66 public JOSMTestRules josmTestRules = new JOSMTestRules().main().projection().fakeImagery(); 67 68 @Before 69 public void beforeAll() { 70 // Needed since testShowDownloadedAreaLayerSwitching expects the measurement to be imperial 71 SystemOfMeasurement.setSystemOfMeasurement(SystemOfMeasurement.IMPERIAL); 72 } 65 73 66 74 /** -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceHighLevelTest.java
r18690 r18694 19 19 import javax.swing.JOptionPane; 20 20 21 import com.github.tomakehurst.wiremock.client.WireMock; 22 import com.github.tomakehurst.wiremock.junit5.WireMockExtension; 23 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 24 import mockit.MockUp; 21 25 import org.awaitility.Awaitility; 22 import org.junit. After;23 import org.junit. Before;24 import org.junit. Rule;25 import org.junit. Test;26 import org.junit.jupiter.api.AfterEach; 27 import org.junit.jupiter.api.BeforeEach; 28 import org.junit.jupiter.api.Test; 29 import org.junit.jupiter.api.extension.RegisterExtension; 26 30 import org.openstreetmap.josm.TestUtils; 27 31 import org.openstreetmap.josm.data.Preferences; … … 32 36 import org.openstreetmap.josm.plugins.PluginProxy; 33 37 import org.openstreetmap.josm.spi.preferences.Config; 34 import org.openstreetmap.josm.testutils.JOSMTestRules;35 38 import org.openstreetmap.josm.testutils.PluginServer; 39 import org.openstreetmap.josm.testutils.annotations.AssertionsInEDT; 40 import org.openstreetmap.josm.testutils.annotations.AssumeRevision; 41 import org.openstreetmap.josm.testutils.annotations.FullPreferences; 42 import org.openstreetmap.josm.testutils.annotations.Main; 36 43 import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker; 37 44 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 38 39 import com.github.tomakehurst.wiremock.client.WireMock;40 import com.github.tomakehurst.wiremock.junit.WireMockRule;41 42 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;43 import mockit.MockUp;44 45 45 46 /** 46 47 * Higher level tests of {@link PluginPreference} class. 47 48 */ 48 public class PluginPreferenceHighLevelTest { 49 /** 50 * Setup test. 51 */ 52 @Rule 53 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 54 public JOSMTestRules test = new JOSMTestRules().assumeRevision( 55 "Revision: 10000\n" 56 ).preferences().main().assertionsInEDT(); 57 49 @AssumeRevision("Revision: 10000\n") 50 @AssertionsInEDT 51 @FullPreferences 52 @Main 53 class PluginPreferenceHighLevelTest { 58 54 /** 59 55 * Plugin server mock. 60 56 */ 61 @R ule62 public WireMockRule pluginServerRule = new WireMockRule(63 options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())64 );57 @RegisterExtension 58 static WireMockExtension pluginServerRule = WireMockExtension.newInstance() 59 .options(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())) 60 .build(); 65 61 66 62 /** … … 68 64 * @throws ReflectiveOperationException never 69 65 */ 70 @Before 66 @BeforeEach 71 67 public void setUp() throws ReflectiveOperationException { 72 68 … … 88 84 Config.getPref().put("pluginmanager.lastupdate", "999"); 89 85 Config.getPref().putList("pluginmanager.sites", 90 Collections.singletonList( this.pluginServerRule.url("/plugins"))86 Collections.singletonList(pluginServerRule.url("/plugins")) 91 87 ); 92 88 … … 107 103 * @throws ReflectiveOperationException never 108 104 */ 109 @After 105 @AfterEach 110 106 public void tearDown() throws ReflectiveOperationException { 111 107 // restore actual PluginHandler#pluginList … … 136 132 */ 137 133 @Test 138 public void testInstallWithoutUpdate() throws Exception {134 void testInstallWithoutUpdate(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 139 135 final PluginServer pluginServer = new PluginServer( 140 136 new PluginServer.RemotePlugin(this.referenceDummyJarNew), … … 142 138 new PluginServer.RemotePlugin(null, Collections.singletonMap("Plugin-Version", "2"), "irrelevant_plugin") 143 139 ); 144 pluginServer.applyToWireMockServer( this.pluginServerRule);140 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 145 141 Config.getPref().putList("plugins", Collections.singletonList("dummy_plugin")); 146 142 … … 169 165 Awaitility.await().atMost(2000, MILLISECONDS).until(() -> Config.getPref().getInt("pluginmanager.version", 999) != 999); 170 166 171 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));172 WireMock.resetAllRequests();167 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 168 pluginServerRule.resetRequests(); 173 169 174 170 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( … … 183 179 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 184 180 185 assertEquals( 186 Arrays.asList("baz_plugin", "dummy_plugin", "irrelevant_plugin"), 187 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 188 ); 189 assertEquals( 190 Collections.singletonList("dummy_plugin"), 191 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 192 ); 193 assertEquals( 194 Arrays.asList("(null)", "31701", "(null)"), 195 model.getAvailablePlugins().stream().map( 196 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 197 ).collect(Collectors.toList()) 198 ); 199 assertEquals( 200 Arrays.asList("6", "31772", "2"), 201 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList()) 202 ); 181 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin", "irrelevant_plugin"), 182 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 183 assertEquals(Collections.singletonList("dummy_plugin"), 184 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 185 assertEquals(Arrays.asList("(null)", "31701", "(null)"), model.getAvailablePlugins().stream().map( 186 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 187 ).collect(Collectors.toList())); 188 assertEquals(Arrays.asList("6", "31772", "2"), 189 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList())); 203 190 204 191 // now we're going to choose to install baz_plugin 205 192 model.setPluginSelected("baz_plugin", true); 206 193 207 assertEquals( 208 Collections.singletonList("baz_plugin"), 209 model.getNewlyActivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 210 ); 211 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 212 assertEquals( 213 Collections.singletonList("baz_plugin"), 214 model.getPluginsScheduledForUpdateOrDownload().stream().map(PluginInformation::getName).collect(Collectors.toList()) 215 ); 194 assertEquals(Collections.singletonList("baz_plugin"), 195 model.getNewlyActivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 196 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 197 assertEquals(Collections.singletonList("baz_plugin"), 198 model.getPluginsScheduledForUpdateOrDownload().stream().map(PluginInformation::getName).collect(Collectors.toList())); 216 199 217 200 tabbedPane.savePreferences(); … … 233 216 assertFalse(targetBazJarNew.exists()); 234 217 235 // the adverti zed version of dummy_plugin shouldn't have been fetched236 this.pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));218 // the advertised version of dummy_plugin shouldn't have been fetched 219 pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 237 220 // but the advertized version of baz_plugin *should* have 238 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v6.jar")));221 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v6.jar"))); 239 222 240 223 // pluginmanager.version has been set to the current version … … 246 229 247 230 // baz_plugin should have been added to the plugins list 248 assertEquals( 249 Arrays.asList("baz_plugin", "dummy_plugin"), 250 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList()) 251 ); 231 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), 232 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList())); 252 233 } 253 234 … … 257 238 */ 258 239 @Test 259 public void testDisablePluginWithUpdatesAvailable() throws Exception {240 void testDisablePluginWithUpdatesAvailable(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 260 241 final PluginServer pluginServer = new PluginServer( 261 242 new PluginServer.RemotePlugin(this.referenceDummyJarNew), … … 263 244 new PluginServer.RemotePlugin(null, null, "irrelevant_plugin") 264 245 ); 265 pluginServer.applyToWireMockServer( this.pluginServerRule);246 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 266 247 Config.getPref().putList("plugins", Arrays.asList("baz_plugin", "dummy_plugin")); 267 248 … … 289 270 Awaitility.await().atMost(2000, MILLISECONDS).until(() -> Config.getPref().getInt("pluginmanager.version", 999) != 999); 290 271 291 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));292 WireMock.resetAllRequests();272 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 273 pluginServerRule.resetRequests(); 293 274 294 275 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( … … 303 284 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 304 285 305 assertEquals( 306 Arrays.asList("baz_plugin", "dummy_plugin", "irrelevant_plugin"), 307 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 308 ); 309 assertEquals( 310 Arrays.asList("baz_plugin", "dummy_plugin"), 311 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 312 ); 313 assertEquals( 314 Arrays.asList("6", "31701", "(null)"), 315 model.getAvailablePlugins().stream().map( 316 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 317 ).collect(Collectors.toList()) 318 ); 319 assertEquals( 320 Arrays.asList("7", "31772", "(null)"), 321 model.getAvailablePlugins().stream().map( 322 (pi) -> pi.version == null ? "(null)" : pi.version 323 ).collect(Collectors.toList()) 324 ); 286 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin", "irrelevant_plugin"), 287 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 288 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), 289 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 290 assertEquals(Arrays.asList("6", "31701", "(null)"), model.getAvailablePlugins().stream().map( 291 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 292 ).collect(Collectors.toList())); 293 assertEquals(Arrays.asList("7", "31772", "(null)"), model.getAvailablePlugins().stream().map( 294 (pi) -> pi.version == null ? "(null)" : pi.version 295 ).collect(Collectors.toList())); 325 296 326 297 // now we're going to choose to disable baz_plugin … … 328 299 329 300 assertTrue(model.getNewlyActivatedPlugins().isEmpty()); 330 assertEquals( 331 Collections.singletonList("baz_plugin"), 332 model.getNewlyDeactivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 333 ); 301 assertEquals(Collections.singletonList("baz_plugin"), 302 model.getNewlyDeactivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 334 303 // questionably correct 335 304 assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty()); … … 354 323 355 324 // neither of the new jars have been fetched 356 this.pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));357 this.pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v6.jar")));325 pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 326 pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v6.jar"))); 358 327 359 328 // pluginmanager.version has been set to the current version … … 365 334 366 335 // baz_plugin should have been removed from the installed plugins list 367 assertEquals( 368 Collections.singletonList("dummy_plugin"), 369 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList()) 370 ); 336 assertEquals(Collections.singletonList("dummy_plugin"), 337 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList())); 371 338 } 372 339 … … 379 346 */ 380 347 @Test 381 public void testUpdateOnlySelectedPlugin() throws Exception {348 void testUpdateOnlySelectedPlugin(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 382 349 TestUtils.assumeWorkingJMockit(); 383 350 final PluginServer pluginServer = new PluginServer( … … 385 352 new PluginServer.RemotePlugin(this.referenceBazJarNew) 386 353 ); 387 pluginServer.applyToWireMockServer( this.pluginServerRule);354 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 388 355 Config.getPref().putList("plugins", Arrays.asList("baz_plugin", "dummy_plugin")); 389 356 … … 406 373 TestUtils.syncEDTAndWorkerThreads(); 407 374 408 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));409 WireMock.resetAllRequests();375 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 376 pluginServerRule.resetRequests(); 410 377 411 378 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( … … 420 387 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 421 388 422 assertEquals( 423 Arrays.asList("baz_plugin", "dummy_plugin"), 424 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 425 ); 426 assertEquals( 427 Arrays.asList("baz_plugin", "dummy_plugin"), 428 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 429 ); 430 assertEquals( 431 Arrays.asList("6", "31701"), 432 model.getAvailablePlugins().stream().map( 433 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 434 ).collect(Collectors.toList()) 435 ); 436 assertEquals( 437 Arrays.asList("7", "31772"), 438 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList()) 439 ); 389 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), 390 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 391 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), 392 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList())); 393 assertEquals(Arrays.asList("6", "31701"), model.getAvailablePlugins().stream().map( 394 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 395 ).collect(Collectors.toList())); 396 assertEquals(Arrays.asList("7", "31772"), model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList())); 440 397 441 398 // now we're going to choose not to update baz_plugin … … 443 400 444 401 assertTrue(model.getNewlyActivatedPlugins().isEmpty()); 445 assertEquals( 446 Collections.singletonList("baz_plugin"), 447 model.getNewlyDeactivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 448 ); 402 assertEquals(Collections.singletonList("baz_plugin"), model.getNewlyDeactivatedPlugins().stream() 403 .map(PluginInformation::getName).collect(Collectors.toList())); 449 404 // questionably correct 450 405 assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty()); … … 481 436 // the plugin list was rechecked 482 437 // questionably necessary 483 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));438 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 484 439 // dummy_plugin has been fetched 485 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));440 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 486 441 // baz_plugin has not 487 this.pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar")));488 WireMock.resetAllRequests();442 pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar"))); 443 pluginServerRule.resetRequests(); 489 444 490 445 // pluginmanager.version has been set to the current version … … 496 451 497 452 // plugins list shouldn't have been altered, we haven't hit save yet 498 assertEquals( 499 Arrays.asList("baz_plugin", "dummy_plugin"), 500 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList()) 501 ); 453 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), 454 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList())); 502 455 503 456 // the model's selection state should be largely as before 504 457 assertTrue(model.getNewlyActivatedPlugins().isEmpty()); 505 assertEquals( 506 Collections.singletonList("baz_plugin"), 507 model.getNewlyDeactivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 508 ); 458 assertEquals(Collections.singletonList("baz_plugin"), model.getNewlyDeactivatedPlugins().stream() 459 .map(PluginInformation::getName).collect(Collectors.toList())); 509 460 assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty()); 510 461 … … 516 467 assertTrue(model.getNewlyActivatedPlugins().isEmpty()); 517 468 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 518 assertEquals( 519 Collections.singletonList("baz_plugin"), 520 model.getPluginsScheduledForUpdateOrDownload().stream().map(PluginInformation::getName).collect(Collectors.toList()) 521 ); 469 assertEquals(Collections.singletonList("baz_plugin"), model.getPluginsScheduledForUpdateOrDownload().stream() 470 .map(PluginInformation::getName).collect(Collectors.toList())); 522 471 523 472 // prepare jopsMocker to handle this message … … 552 501 553 502 // dummy_plugin was not fetched 554 this.pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));503 pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 555 504 // baz_plugin however was fetched 556 505 // questionably correct 557 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar")));506 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar"))); 558 507 559 508 assertEquals(10000, Config.getPref().getInt("pluginmanager.version", 111)); … … 567 516 */ 568 517 @Test 569 public void testUpdateWithNoAvailableUpdates() throws Exception {518 void testUpdateWithNoAvailableUpdates(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 570 519 TestUtils.assumeWorkingJMockit(); 571 520 final PluginServer pluginServer = new PluginServer( … … 574 523 new PluginServer.RemotePlugin(null, Collections.singletonMap("Plugin-Version", "123"), "irrelevant_plugin") 575 524 ); 576 pluginServer.applyToWireMockServer( this.pluginServerRule);525 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 577 526 Config.getPref().putList("plugins", Arrays.asList("baz_plugin", "dummy_plugin")); 578 527 … … 600 549 TestUtils.syncEDTAndWorkerThreads(); 601 550 602 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));603 WireMock.resetAllRequests();551 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 552 pluginServerRule.resetRequests(); 604 553 605 554 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( … … 613 562 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 614 563 615 assertEquals( 616 Arrays.asList("baz_plugin", "dummy_plugin", "irrelevant_plugin"), 617 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 618 ); 619 assertEquals( 620 Arrays.asList("baz_plugin", "dummy_plugin"), 621 model.getSelectedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 622 ); 623 assertEquals( 624 Arrays.asList("6", "31701", "(null)"), 625 model.getAvailablePlugins().stream().map( 626 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 627 ).collect(Collectors.toList()) 628 ); 629 assertEquals( 630 Arrays.asList("6", "31701", "123"), 631 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList()) 632 ); 564 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin", "irrelevant_plugin"), model.getAvailablePlugins().stream() 565 .map(PluginInformation::getName).collect(Collectors.toList())); 566 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), model.getSelectedPlugins().stream() 567 .map(PluginInformation::getName).collect(Collectors.toList())); 568 assertEquals(Arrays.asList("6", "31701", "(null)"), model.getAvailablePlugins().stream().map( 569 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 570 ).collect(Collectors.toList())); 571 assertEquals(Arrays.asList("6", "31701", "123"), model.getAvailablePlugins() 572 .stream().map((pi) -> pi.version).collect(Collectors.toList())); 633 573 634 574 GuiHelper.runInEDTAndWait( … … 654 594 // the plugin list was rechecked 655 595 // questionably necessary 656 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));596 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 657 597 // that should have been the only request to our PluginServer 658 assertEquals(1, this.pluginServerRule.getAllServeEvents().size());659 WireMock.resetAllRequests();598 assertEquals(1, pluginServerRule.getAllServeEvents().size()); 599 pluginServerRule.resetRequests(); 660 600 661 601 // pluginmanager.version has been set to the current version … … 666 606 667 607 // plugins list shouldn't have been altered 668 assertEquals( 669 Arrays.asList("baz_plugin", "dummy_plugin"), 670 Config.getPref().getList("plugins", null).stream().sorted().collect(Collectors.toList()) 671 ); 608 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), Config.getPref().getList("plugins", null) 609 .stream().sorted().collect(Collectors.toList())); 672 610 673 611 // the model's selection state should be largely as before … … 692 630 693 631 // none of PluginServer's URLs should have been touched 694 assertEquals(0, this.pluginServerRule.getAllServeEvents().size());632 assertEquals(0, pluginServerRule.getAllServeEvents().size()); 695 633 696 634 // pluginmanager.version has been set to the current version … … 706 644 */ 707 645 @Test 708 public void testInstallWithoutRestartRequired() throws Exception {646 void testInstallWithoutRestartRequired(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 709 647 TestUtils.assumeWorkingJMockit(); 710 648 final boolean[] loadPluginsCalled = new boolean[] {false}; … … 727 665 new PluginServer.RemotePlugin(this.referenceBazJarNew) 728 666 ); 729 pluginServer.applyToWireMockServer( this.pluginServerRule);667 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 730 668 Config.getPref().putList("plugins", Collections.emptyList()); 731 669 … … 749 687 TestUtils.syncEDTAndWorkerThreads(); 750 688 751 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));752 WireMock.resetAllRequests();689 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 690 pluginServerRule.resetRequests(); 753 691 754 692 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( … … 762 700 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 763 701 764 assertEquals( 765 Arrays.asList("baz_plugin", "dummy_plugin"), 766 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 767 ); 702 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), model.getAvailablePlugins().stream() 703 .map(PluginInformation::getName).collect(Collectors.toList())); 768 704 assertTrue(model.getSelectedPlugins().isEmpty()); 769 assertEquals( 770 Arrays.asList("(null)", "(null)"), 771 model.getAvailablePlugins().stream().map( 772 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 773 ).collect(Collectors.toList()) 774 ); 775 assertEquals( 776 Arrays.asList("7", "31772"), 777 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList()) 778 ); 705 assertEquals(Arrays.asList("(null)", "(null)"), model.getAvailablePlugins().stream().map( 706 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 707 ).collect(Collectors.toList())); 708 assertEquals(Arrays.asList("7", "31772"), model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList())); 779 709 780 710 // now we select dummy_plugin … … 782 712 783 713 // model should now reflect this 784 assertEquals( 785 Collections.singletonList("dummy_plugin"), 786 model.getNewlyActivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 787 ); 714 assertEquals(Collections.singletonList("dummy_plugin"), model.getNewlyActivatedPlugins().stream() 715 .map(PluginInformation::getName).collect(Collectors.toList())); 788 716 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 789 717 … … 804 732 805 733 // dummy_plugin was fetched 806 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));734 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 807 735 808 736 // the dummy_plugin jar has been installed … … 826 754 * @throws Exception on failure 827 755 */ 828 @ JOSMTestRules.OverrideAssumeRevision("Revision: 7000\n")756 @AssumeRevision("Revision: 7000\n") 829 757 @Test 830 public void testInstallMultiVersion() throws Exception {758 void testInstallMultiVersion(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 831 759 TestUtils.assumeWorkingJMockit(); 832 760 … … 835 763 new PluginServer.RemotePlugin(this.referenceDummyJarNew), 836 764 new PluginServer.RemotePlugin(this.referenceBazJarNew, Collections.singletonMap( 837 "6800_Plugin-Url", "6;" + this.pluginServerRule.url(bazOldServePath)765 "6800_Plugin-Url", "6;" + pluginServerRule.url(bazOldServePath) 838 766 )) 839 767 ); 840 pluginServer.applyToWireMockServer( this.pluginServerRule);768 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 841 769 // need to actually serve this older jar from somewhere 842 this.pluginServerRule.stubFor(770 pluginServerRule.stubFor( 843 771 WireMock.get(WireMock.urlEqualTo(bazOldServePath)).willReturn( 844 772 WireMock.aResponse().withStatus(200).withHeader("Content-Type", "application/java-archive").withBodyFile( … … 870 798 TestUtils.syncEDTAndWorkerThreads(); 871 799 872 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));873 WireMock.resetAllRequests();800 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 801 pluginServerRule.resetRequests(); 874 802 875 803 final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField( … … 883 811 assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins()); 884 812 885 assertEquals( 886 Arrays.asList("baz_plugin", "dummy_plugin"), 887 model.getAvailablePlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 888 ); 813 assertEquals(Arrays.asList("baz_plugin", "dummy_plugin"), model.getAvailablePlugins().stream() 814 .map(PluginInformation::getName).collect(Collectors.toList())); 889 815 assertTrue(model.getSelectedPlugins().isEmpty()); 890 assertEquals( 891 Arrays.asList("(null)", "(null)"), 892 model.getAvailablePlugins().stream().map( 893 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 894 ).collect(Collectors.toList()) 895 ); 896 assertEquals( 897 Arrays.asList("6", "31772"), 898 model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList()) 899 ); 816 assertEquals(Arrays.asList("(null)", "(null)"), model.getAvailablePlugins().stream().map( 817 (pi) -> pi.localversion == null ? "(null)" : pi.localversion 818 ).collect(Collectors.toList())); 819 assertEquals(Arrays.asList("6", "31772"), model.getAvailablePlugins().stream().map((pi) -> pi.version).collect(Collectors.toList())); 900 820 901 821 // now we select dummy_plugin … … 903 823 904 824 // model should now reflect this 905 assertEquals( 906 Collections.singletonList("baz_plugin"), 907 model.getNewlyActivatedPlugins().stream().map(PluginInformation::getName).collect(Collectors.toList()) 908 ); 825 assertEquals(Collections.singletonList("baz_plugin"), model.getNewlyActivatedPlugins().stream() 826 .map(PluginInformation::getName).collect(Collectors.toList())); 909 827 assertTrue(model.getNewlyDeactivatedPlugins().isEmpty()); 910 828 … … 925 843 926 844 // dummy_plugin was fetched 927 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(bazOldServePath)));845 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(bazOldServePath))); 928 846 929 847 // the "old" baz_plugin jar has been installed -
trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerJOSMTooOldTest.java
r18690 r18694 18 18 import java.util.stream.Collectors; 19 19 20 import org.junit.Before; 21 import org.junit.Rule; 22 import org.junit.Test; 20 import com.github.tomakehurst.wiremock.client.WireMock; 21 import com.github.tomakehurst.wiremock.junit5.WireMockExtension; 22 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 24 import org.junit.jupiter.api.BeforeEach; 25 import org.junit.jupiter.api.Test; 26 import org.junit.jupiter.api.extension.RegisterExtension; 23 27 import org.openstreetmap.josm.TestUtils; 24 28 import org.openstreetmap.josm.data.Preferences; … … 27 31 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 32 import org.openstreetmap.josm.testutils.PluginServer; 33 import org.openstreetmap.josm.testutils.annotations.AssumeRevision; 34 import org.openstreetmap.josm.testutils.annotations.FullPreferences; 29 35 import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker; 30 36 import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker; 31 32 import com.github.tomakehurst.wiremock.client.WireMock;33 import com.github.tomakehurst.wiremock.junit.WireMockRule;34 35 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;36 37 37 38 /** 38 39 * Test parts of {@link PluginHandler} class when the reported JOSM version is too old for the plugin. 39 40 */ 40 public class PluginHandlerJOSMTooOldTest { 41 @AssumeRevision("Revision: 6000\n") 42 @FullPreferences 43 class PluginHandlerJOSMTooOldTest { 41 44 /** 42 45 * Setup test. 43 46 */ 44 @R ule47 @RegisterExtension 45 48 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 46 public JOSMTestRules test = new JOSMTestRules().preferences().main().assumeRevision( 47 "Revision: 6000\n" 48 ); 49 static JOSMTestRules test = new JOSMTestRules().main(); 49 50 50 51 /** 51 52 * Plugin server mock. 52 53 */ 53 @R ule54 public WireMockRule pluginServerRule = new WireMockRule(54 @RegisterExtension 55 static WireMockExtension pluginServerRule = WireMockExtension.newInstance().options( 55 56 options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()) 56 ) ;57 ).build(); 57 58 58 59 /** 59 60 * Setup test. 60 61 */ 61 @Before 62 @BeforeEach 62 63 public void setUp() { 63 64 Config.getPref().putInt("pluginmanager.version", 999); 64 65 Config.getPref().put("pluginmanager.lastupdate", "999"); 65 66 Config.getPref().putList("pluginmanager.sites", 66 Collections.singletonList( this.pluginServerRule.url("/plugins"))67 Collections.singletonList(pluginServerRule.url("/plugins")) 67 68 ); 68 69 … … 115 116 */ 116 117 @Test 117 public void testUpdatePluginsDownloadBoth() throws IOException {118 void testUpdatePluginsDownloadBoth(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException { 118 119 TestUtils.assumeWorkingJMockit(); 119 120 final PluginServer pluginServer = new PluginServer( … … 121 122 new PluginServer.RemotePlugin(this.referenceBazJarNew) 122 123 ); 123 pluginServer.applyToWireMockServer( this.pluginServerRule);124 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 124 125 Config.getPref().putList("plugins", Arrays.asList("dummy_plugin", "baz_plugin")); 125 126 … … 162 163 TestUtils.assertFileContentsEqual(this.referenceBazJarNew, this.targetBazJar); 163 164 164 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));165 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));166 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar")));165 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 166 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 167 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar"))); 167 168 168 169 assertEquals(Config.getPref().getInt("pluginmanager.version", 111), 6000); … … 177 178 */ 178 179 @Test 179 public void testUpdatePluginsSkipOne() throws IOException {180 void testUpdatePluginsSkipOne(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException { 180 181 TestUtils.assumeWorkingJMockit(); 181 182 final PluginServer pluginServer = new PluginServer( … … 183 184 new PluginServer.RemotePlugin(this.referenceBazJarNew) 184 185 ); 185 pluginServer.applyToWireMockServer( this.pluginServerRule);186 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 186 187 Config.getPref().putList("plugins", Arrays.asList("dummy_plugin", "baz_plugin")); 187 188 … … 232 233 TestUtils.assertFileContentsEqual(this.referenceBazJarNew, this.targetBazJar); 233 234 234 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));235 this.pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar")));236 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar")));235 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 236 pluginServerRule.verify(0, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.v31772.jar"))); 237 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar"))); 237 238 238 239 // shouldn't have been updated … … 249 250 */ 250 251 @Test 251 public void testUpdatePluginsUnexpectedlyJOSMTooOld() throws IOException {252 void testUpdatePluginsUnexpectedlyJOSMTooOld(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException { 252 253 TestUtils.assumeWorkingJMockit(); 253 254 final PluginServer pluginServer = new PluginServer( … … 255 256 new PluginServer.RemotePlugin(this.referenceBazJarNew, Collections.singletonMap("Plugin-Mainversion", "5500")) 256 257 ); 257 pluginServer.applyToWireMockServer( this.pluginServerRule);258 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 258 259 Config.getPref().putList("plugins", Collections.singletonList("baz_plugin")); 259 260 … … 283 284 TestUtils.assertFileContentsEqual(this.referenceBazJarNew, this.targetBazJar); 284 285 285 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));286 // questionably correct 287 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar")));286 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 287 // questionably correct 288 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.v7.jar"))); 288 289 289 290 // should have been updated … … 303 304 */ 304 305 @Test 305 @ JOSMTestRules.OverrideAssumeRevision("Revision: 7200\n")306 public void testUpdatePluginsMultiVersionInsufficient() throws IOException {306 @AssumeRevision("Revision: 7200\n") 307 void testUpdatePluginsMultiVersionInsufficient(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException { 307 308 TestUtils.assumeWorkingJMockit(); 308 309 … … 310 311 new PluginServer.RemotePlugin(this.referenceBazJarOld), 311 312 new PluginServer.RemotePlugin(this.referenceQuxJarNewer, Collections.singletonMap( 312 "7499_Plugin-Url", "346;" + this.pluginServerRule.url("/dont/bother.jar")313 "7499_Plugin-Url", "346;" + pluginServerRule.url("/dont/bother.jar") 313 314 )) 314 315 ); 315 pluginServer.applyToWireMockServer( this.pluginServerRule);316 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 316 317 Config.getPref().putList("plugins", Arrays.asList("qux_plugin", "baz_plugin")); 317 318 … … 343 344 TestUtils.assertFileContentsEqual(this.referenceQuxJarNewer, this.targetQuxJar); 344 345 345 assertEquals(2, WireMock.getAllServeEvents().size());346 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));347 // questionably correct 348 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/qux_plugin.v432.jar")));346 assertEquals(2, pluginServerRule.getAllServeEvents().size()); 347 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 348 // questionably correct 349 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/qux_plugin.v432.jar"))); 349 350 350 351 assertEquals(7200, Config.getPref().getInt("pluginmanager.version", 111)); -
trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerMultiVersionTest.java
r18690 r18694 17 17 import java.util.stream.Collectors; 18 18 19 import org.junit.Before; 20 import org.junit.Rule; 21 import org.junit.Test; 19 import com.github.tomakehurst.wiremock.client.WireMock; 20 import com.github.tomakehurst.wiremock.junit5.WireMockExtension; 21 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 23 import org.junit.jupiter.api.BeforeEach; 24 import org.junit.jupiter.api.Test; 25 import org.junit.jupiter.api.extension.RegisterExtension; 22 26 import org.openstreetmap.josm.TestUtils; 23 27 import org.openstreetmap.josm.data.Preferences; … … 26 30 import org.openstreetmap.josm.testutils.JOSMTestRules; 27 31 import org.openstreetmap.josm.testutils.PluginServer; 32 import org.openstreetmap.josm.testutils.annotations.AssumeRevision; 33 import org.openstreetmap.josm.testutils.annotations.FullPreferences; 28 34 import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker; 29 30 import com.github.tomakehurst.wiremock.client.WireMock;31 import com.github.tomakehurst.wiremock.junit.WireMockRule;32 33 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;34 35 35 36 /** 36 37 * Test parts of {@link PluginHandler} class with plugins that advertise multiple versions for compatibility. 37 38 */ 38 public class PluginHandlerMultiVersionTest { 39 @FullPreferences 40 class PluginHandlerMultiVersionTest { 39 41 /** 40 42 * Setup test. 41 43 */ 42 @R ule44 @RegisterExtension 43 45 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 44 public JOSMTestRules test = new JOSMTestRules().preferences().main();46 static JOSMTestRules test = new JOSMTestRules().main(); 45 47 46 48 /** 47 49 * Plugin server mock. 48 50 */ 49 @Rule 50 public WireMockRule pluginServerRule = new WireMockRule( 51 options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()) 52 ); 51 @RegisterExtension 52 static WireMockExtension pluginServerRule = WireMockExtension.newInstance() 53 .options(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())).build(); 53 54 54 55 /** 55 56 * Setup test. 56 57 */ 57 @Before 58 publicvoid setUp() {58 @BeforeEach 59 void setUp() { 59 60 Config.getPref().putInt("pluginmanager.version", 999); 60 61 Config.getPref().put("pluginmanager.lastupdate", "999"); 61 62 Config.getPref().putList("pluginmanager.sites", 62 Collections.singletonList( this.pluginServerRule.url("/plugins"))63 Collections.singletonList(pluginServerRule.url("/plugins")) 63 64 ); 64 65 … … 94 95 * @throws Exception on failure 95 96 */ 96 @ JOSMTestRules.OverrideAssumeRevision("Revision: 7501\n")97 @AssumeRevision("Revision: 7501\n") 97 98 @Test 98 public void testUpdatePluginsOneMultiVersion() throws Exception {99 void testUpdatePluginsOneMultiVersion(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 99 100 TestUtils.assumeWorkingJMockit(); 100 101 … … 109 110 new PluginServer.RemotePlugin(this.referenceQuxJarNewest, attrOverrides) 110 111 ); 111 pluginServer.applyToWireMockServer( this.pluginServerRule);112 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 112 113 // need to actually serve this older jar from somewhere 113 this.pluginServerRule.stubFor(114 wireMockRuntimeInfo.getWireMock().register( 114 115 WireMock.get(WireMock.urlEqualTo(quxNewerServePath)).willReturn( 115 116 WireMock.aResponse().withStatus(200).withHeader("Content-Type", "application/java-archive").withBodyFile( … … 147 148 TestUtils.assertFileContentsEqual(this.referenceQuxJarNewer, this.targetQuxJar); 148 149 149 assertEquals(2, WireMock.getAllServeEvents().size());150 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));151 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(quxNewerServePath)));150 assertEquals(2, pluginServerRule.getAllServeEvents().size()); 151 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 152 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(quxNewerServePath))); 152 153 153 154 assertEquals(7501, Config.getPref().getInt("pluginmanager.version", 111)); … … 161 162 * @throws Exception on failure 162 163 */ 163 @ JOSMTestRules.OverrideAssumeRevision("Revision: 7000\n")164 @AssumeRevision("Revision: 7000\n") 164 165 @Test 165 public void testUpdatePluginsExistingVersionLatestPossible() throws Exception {166 void testUpdatePluginsExistingVersionLatestPossible(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 166 167 TestUtils.assumeWorkingJMockit(); 167 168 … … 175 176 new PluginServer.RemotePlugin(this.referenceQuxJarNewest, attrOverrides) 176 177 ); 177 pluginServer.applyToWireMockServer( this.pluginServerRule);178 pluginServer.applyToWireMockServer(wireMockRuntimeInfo); 178 179 Config.getPref().putList("plugins", Arrays.asList("qux_plugin", "baz_plugin")); 179 180 … … 207 208 208 209 // only the plugins list should have been downloaded 209 assertEquals(1, WireMock.getAllServeEvents().size());210 this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));210 assertEquals(1, pluginServerRule.getAllServeEvents().size()); 211 pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins"))); 211 212 212 213 assertEquals(7000, Config.getPref().getInt("pluginmanager.version", 111)); -
trunk/test/unit/org/openstreetmap/josm/testutils/PluginServer.java
r18690 r18694 16 16 import java.util.stream.StreamSupport; 17 17 18 import org.junit.runner.Description;19 import org.junit.runners.model.Statement;20 import org.openstreetmap.josm.TestUtils;21 import org.openstreetmap.josm.tools.Logging;22 23 import com.github.tomakehurst.wiremock.WireMockServer;24 18 import com.github.tomakehurst.wiremock.client.MappingBuilder; 25 19 import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; 26 20 import com.github.tomakehurst.wiremock.client.WireMock; 27 21 import com.github.tomakehurst.wiremock.core.Options; 28 import com.github.tomakehurst.wiremock.junit.WireMockRule; 22 import com.github.tomakehurst.wiremock.junit5.WireMockExtension; 23 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 24 import org.openstreetmap.josm.TestUtils; 25 import org.openstreetmap.josm.tools.Logging; 29 26 30 27 public class PluginServer { … … 138 135 } 139 136 140 public String getPluginURL(WireMock Server wireMockServer) {137 public String getPluginURL(WireMockRuntimeInfo wireMock) { 141 138 if (this.pluginURL != null) { 142 139 return this.pluginURL; 143 } else if (wireMock Server!= null && this.getJarPathBeneathFilesDir() != null) {144 return wireMock Server.url(this.getPluginURLPath());140 } else if (wireMock != null && this.getJarPathBeneathFilesDir() != null) { 141 return wireMock.getHttpBaseUrl() + this.getPluginURLPath(); 145 142 } 146 143 return "http://example.com" + this.getPluginURLPath(); … … 156 153 } 157 154 158 public String getRemotePluginsListSection(WireMock Server wireMockServer) {155 public String getRemotePluginsListSection(WireMockRuntimeInfo wireMock) { 159 156 return String.format( 160 157 "%s.jar;%s\n%s", 161 158 this.getName(), 162 this.getPluginURL(wireMock Server),159 this.getPluginURL(wireMock), 163 160 this.getRemotePluginsListManifestSection() 164 161 ); … … 192 189 } 193 190 194 public void applyToWireMockServer(WireMockServer wireMockServer) { 191 public void applyToWireMockServer(WireMockRuntimeInfo wireMock) { 192 final WireMock wireMockServer = wireMock.getWireMock(); 195 193 // first add the plugins list 196 wireMockServer. stubFor(194 wireMockServer.register( 197 195 WireMock.get(WireMock.urlEqualTo("/plugins")).willReturn( 198 196 WireMock.aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody( 199 197 this.pluginList.stream().map( 200 remotePlugin -> remotePlugin.getRemotePluginsListSection(wireMock Server)198 remotePlugin -> remotePlugin.getRemotePluginsListSection(wireMock) 201 199 ).collect(Collectors.joining()) 202 200 ) … … 210 208 211 209 if (mappingBuilder != null && responseDefinitionBuilder != null) { 212 wireMockServer. stubFor(210 wireMockServer.register( 213 211 remotePlugin.getMappingBuilder().willReturn(remotePlugin.getResponseDefinitionBuilder()) 214 212 ); … … 228 226 } 229 227 230 public class PluginServerRule extends WireMock Rule{228 public class PluginServerRule extends WireMockExtension { 231 229 public PluginServerRule(Options ruleOptions, boolean failOnUnmatchedRequests) { 232 super( ruleOptions, failOnUnmatchedRequests);230 super(extensionOptions().options(ruleOptions).failOnUnmatchedRequests(failOnUnmatchedRequests)); 233 231 } 234 232 … … 238 236 239 237 @Override 240 public Statement apply(Statement base, Description description) { 241 return super.apply(new Statement() { 242 @Override 243 public void evaluate() throws Throwable { 244 PluginServer.this.applyToWireMockServer(PluginServerRule.this); 245 base.evaluate(); 246 } 247 }, description); 238 protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) { 239 PluginServer.this.applyToWireMockServer(wireMockRuntimeInfo); 248 240 } 249 241 } -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/BasicPreferences.java
r18491 r18694 4 4 import java.lang.annotation.Documented; 5 5 import java.lang.annotation.ElementType; 6 import java.lang.annotation.Inherited; 6 7 import java.lang.annotation.Retention; 7 8 import java.lang.annotation.RetentionPolicy; 8 9 import java.lang.annotation.Target; 10 import java.util.Map; 9 11 10 12 import org.junit.jupiter.api.extension.AfterAllCallback; … … 15 17 import org.junit.jupiter.api.extension.ExtensionContext; 16 18 import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 19 import org.junit.platform.commons.support.AnnotationSupport; 20 import org.openstreetmap.josm.TestUtils; 17 21 import org.openstreetmap.josm.data.Preferences; 18 22 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 19 23 import org.openstreetmap.josm.data.preferences.JosmUrls; 20 24 import org.openstreetmap.josm.spi.preferences.Config; 25 import org.openstreetmap.josm.spi.preferences.Setting; 21 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 22 27 … … 32 37 @Retention(RetentionPolicy.RUNTIME) 33 38 @Target({ElementType.TYPE, ElementType.METHOD}) 39 @Inherited 34 40 @ExtendWith(BasicPreferences.BasicPreferencesExtension.class) 35 41 public @interface BasicPreferences { … … 47 53 @Override 48 54 public void afterEach(ExtensionContext context) throws Exception { 49 if ( context.getElement().isPresent() && context.getElement().get().isAnnotationPresent(BasicPreferences.class)) {55 if (AnnotationSupport.isAnnotated(context.getElement(), BasicPreferences.class)) { 50 56 this.afterAll(context); 51 57 } … … 57 63 // Disable saving on put, just to avoid overwriting pref files 58 64 pref.enableSaveOnPut(false); 59 pref.resetToDefault(); 65 pref.resetToInitialState(); 66 pref.enableSaveOnPut(false); 67 @SuppressWarnings("unchecked") 68 final Map<String, Setting<?>> defaultsMap = (Map<String, Setting<?>>) TestUtils.getPrivateField(pref, "defaultsMap"); 69 defaultsMap.clear(); 60 70 Config.setPreferencesInstance(pref); 61 71 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); … … 70 80 @Override 71 81 public void beforeEach(ExtensionContext context) throws Exception { 72 if (Annotation Utils.elementIsAnnotated(context.getElement(), BasicPreferences.class) || Config.getPref() == null) {82 if (AnnotationSupport.isAnnotated(context.getElement(), BasicPreferences.class) || Config.getPref() == null) { 73 83 this.beforeAll(context); 74 84 } -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/FullPreferences.java
r18037 r18694 7 7 import java.lang.annotation.RetentionPolicy; 8 8 import java.lang.annotation.Target; 9 import java.util.Map;10 9 11 import org.junit.jupiter.api.extension.BeforeAllCallback;12 10 import org.junit.jupiter.api.extension.BeforeEachCallback; 13 11 import org.junit.jupiter.api.extension.ExtendWith; 14 12 import org.junit.jupiter.api.extension.ExtensionContext; 15 13 import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 16 import org.openstreetmap.josm.TestUtils;17 14 import org.openstreetmap.josm.data.Preferences; 15 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 18 16 import org.openstreetmap.josm.spi.preferences.Config; 19 import org.openstreetmap.josm.spi.preferences.Setting;20 17 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 18 import org.openstreetmap.josm.testutils.annotations.BasicPreferences.BasicPreferencesExtension; … … 37 34 * Initialize preferences. 38 35 */ 39 class UsePreferencesExtension implements Before AllCallback, BeforeEachCallback {36 class UsePreferencesExtension implements BeforeEachCallback { 40 37 @Override 41 public void before All(ExtensionContext context) throws Exception {38 public void beforeEach(ExtensionContext context) throws Exception { 42 39 Preferences pref = context.getStore(Namespace.create(BasicPreferencesExtension.class)).get("preferences", Preferences.class); 43 @SuppressWarnings("unchecked") 44 final Map<String, Setting<?>> defaultsMap = (Map<String, Setting<?>>) TestUtils.getPrivateField(pref, "defaultsMap"); 45 defaultsMap.clear(); 40 if (pref.getDirs() instanceof JosmBaseDirectories) { 41 ((JosmBaseDirectories) pref.getDirs()).clearMemos(); 42 } 43 pref.enableSaveOnPut(false); 46 44 pref.resetToInitialState(); 47 45 pref.enableSaveOnPut(false); … … 50 48 Config.getPref().put("osm-server.url", "http://invalid"); 51 49 } 52 53 @Override54 public void beforeEach(ExtensionContext context) throws Exception {55 if (AnnotationUtils.elementIsAnnotated(context.getElement(), FullPreferences.class)) {56 this.beforeAll(context);57 }58 }59 50 } 60 51 } -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java
r18037 r18694 7 7 import java.lang.annotation.RetentionPolicy; 8 8 import java.lang.annotation.Target; 9 import java.util.Locale; 9 10 10 11 import org.junit.jupiter.api.extension.AfterEachCallback; … … 13 14 import org.junit.jupiter.api.extension.ExtensionContext; 14 15 import org.junit.platform.commons.support.AnnotationSupport; 16 import org.openstreetmap.josm.tools.LanguageInfo; 15 17 16 18 /** … … 41 43 public void beforeEach(ExtensionContext context) { 42 44 String language = AnnotationSupport.findAnnotation(context.getElement(), I18n.class).map(I18n::value).orElse("en"); 43 org.openstreetmap.josm.tools.I18n.set(language); 45 if (!Locale.getDefault().equals(LanguageInfo.getLocale(language, false))) { 46 org.openstreetmap.josm.tools.I18n.set(language); 47 } 44 48 } 45 49 46 50 @Override 47 51 public void afterEach(ExtensionContext context) { 48 org.openstreetmap.josm.tools.I18n.set("en"); 49 org.openstreetmap.josm.tools.I18n.set(org.openstreetmap.josm.tools.I18n.getOriginalLocale().getLanguage()); 52 if (!Locale.ENGLISH.equals(Locale.getDefault())) { 53 org.openstreetmap.josm.tools.I18n.set("en"); 54 org.openstreetmap.josm.tools.I18n.set(org.openstreetmap.josm.tools.I18n.getOriginalLocale().getLanguage()); 55 Locale.setDefault(Locale.ENGLISH); 56 } 50 57 } 51 58 } -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/JosmHome.java
r18037 r18694 16 16 import java.util.UUID; 17 17 18 import org.junit.jupiter.api.extension.After AllCallback;19 import org.junit.jupiter.api.extension.Before AllCallback;18 import org.junit.jupiter.api.extension.AfterEachCallback; 19 import org.junit.jupiter.api.extension.BeforeEachCallback; 20 20 import org.junit.jupiter.api.extension.ExtendWith; 21 21 import org.junit.jupiter.api.extension.ExtensionContext; … … 40 40 * @author Taylor Smock 41 41 */ 42 class JosmHomeExtension implements Before AllCallback, AfterAllCallback {42 class JosmHomeExtension implements BeforeEachCallback, AfterEachCallback { 43 43 @Override 44 public void after All(ExtensionContext context) throws Exception {44 public void afterEach(ExtensionContext context) throws Exception { 45 45 Path tempDir = context.getStore(Namespace.create(JosmHome.class)).get("home", Path.class); 46 46 Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() { … … 57 57 } 58 58 }); 59 System.clearProperty("josm.home"); 59 60 } 60 61 61 62 @Override 62 public void before All(ExtensionContext context) throws Exception {63 public void beforeEach(ExtensionContext context) throws Exception { 63 64 Path tempDir = Files.createTempDirectory(UUID.randomUUID().toString()); 64 65 context.getStore(Namespace.create(JosmHome.class)).put("home", tempDir);
Note:
See TracChangeset
for help on using the changeset viewer.