Changeset 18694 in josm


Ignore:
Timestamp:
2023-03-16T22:09:01+01:00 (21 months ago)
Author:
taylor.smock
Message:

Fix #22381: Try to automatically install newly required plugins on plugin update

This additionally updates the plugin tests to JUnit 5 (see #16567). Some tests
required fixing (for example, MinimapDialogTest fails if the system of
measurement is metric).

Location:
trunk
Files:
7 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r18211 r18694  
    1818import java.util.Collection;
    1919import java.util.Collections;
     20import java.util.HashSet;
    2021import java.util.LinkedList;
    2122import java.util.List;
     
    432433                    return;
    433434                }
     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
    434456                pluginDownloadTask.setPluginsToDownload(toUpdate);
    435457                MainApplication.worker.submit(pluginDownloadTask);
    436458                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);
    437464            };
    438465
  • 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)
     2org.openstreetmap.josm.testutils.annotations.BasicPreferences$BasicPreferencesExtension
    13org.openstreetmap.josm.testutils.annotations.HTTP$HTTPExtension
     4org.openstreetmap.josm.testutils.annotations.I18n$I18nExtension
     5org.openstreetmap.josm.testutils.annotations.JosmDefaults$DefaultsExtension
    26org.openstreetmap.josm.testutils.annotations.LayerManager$LayerManagerExtension
     7org.openstreetmap.josm.testutils.annotations.Logging$LoggingExtension
     8org.openstreetmap.josm.testutils.annotations.Timezone$TimezoneExtension
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java

    r18690 r18694  
    3030import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3131import org.awaitility.Awaitility;
     32import org.junit.Before;
    3233import org.junit.Rule;
    3334import org.junit.Test;
     
    3536import org.openstreetmap.josm.data.Bounds;
    3637import org.openstreetmap.josm.data.DataSource;
     38import org.openstreetmap.josm.data.SystemOfMeasurement;
    3739import org.openstreetmap.josm.data.imagery.ImageryInfo;
    3840import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
     
    6365    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    6466    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    }
    6573
    6674    /**
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceHighLevelTest.java

    r18690 r18694  
    1919import javax.swing.JOptionPane;
    2020
     21import com.github.tomakehurst.wiremock.client.WireMock;
     22import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
     23import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
     24import mockit.MockUp;
    2125import org.awaitility.Awaitility;
    22 import org.junit.After;
    23 import org.junit.Before;
    24 import org.junit.Rule;
    25 import org.junit.Test;
     26import org.junit.jupiter.api.AfterEach;
     27import org.junit.jupiter.api.BeforeEach;
     28import org.junit.jupiter.api.Test;
     29import org.junit.jupiter.api.extension.RegisterExtension;
    2630import org.openstreetmap.josm.TestUtils;
    2731import org.openstreetmap.josm.data.Preferences;
     
    3236import org.openstreetmap.josm.plugins.PluginProxy;
    3337import org.openstreetmap.josm.spi.preferences.Config;
    34 import org.openstreetmap.josm.testutils.JOSMTestRules;
    3538import org.openstreetmap.josm.testutils.PluginServer;
     39import org.openstreetmap.josm.testutils.annotations.AssertionsInEDT;
     40import org.openstreetmap.josm.testutils.annotations.AssumeRevision;
     41import org.openstreetmap.josm.testutils.annotations.FullPreferences;
     42import org.openstreetmap.josm.testutils.annotations.Main;
    3643import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
    3744import 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;
    4445
    4546/**
    4647 * Higher level tests of {@link PluginPreference} class.
    4748 */
    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
     53class PluginPreferenceHighLevelTest {
    5854    /**
    5955     * Plugin server mock.
    6056     */
    61     @Rule
    62     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();
    6561
    6662    /**
     
    6864     * @throws ReflectiveOperationException never
    6965     */
    70     @Before
     66    @BeforeEach
    7167    public void setUp() throws ReflectiveOperationException {
    7268
     
    8884        Config.getPref().put("pluginmanager.lastupdate", "999");
    8985        Config.getPref().putList("pluginmanager.sites",
    90             Collections.singletonList(this.pluginServerRule.url("/plugins"))
     86            Collections.singletonList(pluginServerRule.url("/plugins"))
    9187        );
    9288
     
    107103     * @throws ReflectiveOperationException never
    108104     */
    109     @After
     105    @AfterEach
    110106    public void tearDown() throws ReflectiveOperationException {
    111107        // restore actual PluginHandler#pluginList
     
    136132     */
    137133    @Test
    138     public void testInstallWithoutUpdate() throws Exception {
     134    void testInstallWithoutUpdate(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    139135        final PluginServer pluginServer = new PluginServer(
    140136            new PluginServer.RemotePlugin(this.referenceDummyJarNew),
     
    142138            new PluginServer.RemotePlugin(null, Collections.singletonMap("Plugin-Version", "2"), "irrelevant_plugin")
    143139        );
    144         pluginServer.applyToWireMockServer(this.pluginServerRule);
     140        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    145141        Config.getPref().putList("plugins", Collections.singletonList("dummy_plugin"));
    146142
     
    169165        Awaitility.await().atMost(2000, MILLISECONDS).until(() -> Config.getPref().getInt("pluginmanager.version", 999) != 999);
    170166
    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();
    173169
    174170        final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField(
     
    183179        assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins());
    184180
    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()));
    203190
    204191        // now we're going to choose to install baz_plugin
    205192        model.setPluginSelected("baz_plugin", true);
    206193
    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()));
    216199
    217200        tabbedPane.savePreferences();
     
    233216        assertFalse(targetBazJarNew.exists());
    234217
    235         // the advertized version of dummy_plugin shouldn't have been fetched
    236         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")));
    237220        // 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")));
    239222
    240223        // pluginmanager.version has been set to the current version
     
    246229
    247230        // 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()));
    252233    }
    253234
     
    257238     */
    258239    @Test
    259     public void testDisablePluginWithUpdatesAvailable() throws Exception {
     240    void testDisablePluginWithUpdatesAvailable(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    260241        final PluginServer pluginServer = new PluginServer(
    261242            new PluginServer.RemotePlugin(this.referenceDummyJarNew),
     
    263244            new PluginServer.RemotePlugin(null, null, "irrelevant_plugin")
    264245        );
    265         pluginServer.applyToWireMockServer(this.pluginServerRule);
     246        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    266247        Config.getPref().putList("plugins", Arrays.asList("baz_plugin", "dummy_plugin"));
    267248
     
    289270        Awaitility.await().atMost(2000, MILLISECONDS).until(() -> Config.getPref().getInt("pluginmanager.version", 999) != 999);
    290271
    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();
    293274
    294275        final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField(
     
    303284        assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins());
    304285
    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()));
    325296
    326297        // now we're going to choose to disable baz_plugin
     
    328299
    329300        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()));
    334303        // questionably correct
    335304        assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty());
     
    354323
    355324        // 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")));
    358327
    359328        // pluginmanager.version has been set to the current version
     
    365334
    366335        // 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()));
    371338    }
    372339
     
    379346     */
    380347    @Test
    381     public void testUpdateOnlySelectedPlugin() throws Exception {
     348    void testUpdateOnlySelectedPlugin(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    382349        TestUtils.assumeWorkingJMockit();
    383350        final PluginServer pluginServer = new PluginServer(
     
    385352            new PluginServer.RemotePlugin(this.referenceBazJarNew)
    386353        );
    387         pluginServer.applyToWireMockServer(this.pluginServerRule);
     354        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    388355        Config.getPref().putList("plugins", Arrays.asList("baz_plugin", "dummy_plugin"));
    389356
     
    406373        TestUtils.syncEDTAndWorkerThreads();
    407374
    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();
    410377
    411378        final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField(
     
    420387        assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins());
    421388
    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()));
    440397
    441398        // now we're going to choose not to update baz_plugin
     
    443400
    444401        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()));
    449404        // questionably correct
    450405        assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty());
     
    481436        // the plugin list was rechecked
    482437        // questionably necessary
    483         this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));
     438        pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));
    484439        // 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")));
    486441        // 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();
    489444
    490445        // pluginmanager.version has been set to the current version
     
    496451
    497452        // 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()));
    502455
    503456        // the model's selection state should be largely as before
    504457        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()));
    509460        assertTrue(model.getPluginsScheduledForUpdateOrDownload().isEmpty());
    510461
     
    516467        assertTrue(model.getNewlyActivatedPlugins().isEmpty());
    517468        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()));
    522471
    523472        // prepare jopsMocker to handle this message
     
    552501
    553502        // 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")));
    555504        // baz_plugin however was fetched
    556505        // 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")));
    558507
    559508        assertEquals(10000, Config.getPref().getInt("pluginmanager.version", 111));
     
    567516     */
    568517    @Test
    569     public void testUpdateWithNoAvailableUpdates() throws Exception {
     518    void testUpdateWithNoAvailableUpdates(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    570519        TestUtils.assumeWorkingJMockit();
    571520        final PluginServer pluginServer = new PluginServer(
     
    574523            new PluginServer.RemotePlugin(null, Collections.singletonMap("Plugin-Version", "123"), "irrelevant_plugin")
    575524        );
    576         pluginServer.applyToWireMockServer(this.pluginServerRule);
     525        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    577526        Config.getPref().putList("plugins", Arrays.asList("baz_plugin", "dummy_plugin"));
    578527
     
    600549        TestUtils.syncEDTAndWorkerThreads();
    601550
    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();
    604553
    605554        final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField(
     
    613562        assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins());
    614563
    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()));
    633573
    634574        GuiHelper.runInEDTAndWait(
     
    654594        // the plugin list was rechecked
    655595        // questionably necessary
    656         this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));
     596        pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));
    657597        // 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();
    660600
    661601        // pluginmanager.version has been set to the current version
     
    666606
    667607        // 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()));
    672610
    673611        // the model's selection state should be largely as before
     
    692630
    693631        // none of PluginServer's URLs should have been touched
    694         assertEquals(0, this.pluginServerRule.getAllServeEvents().size());
     632        assertEquals(0, pluginServerRule.getAllServeEvents().size());
    695633
    696634        // pluginmanager.version has been set to the current version
     
    706644     */
    707645    @Test
    708     public void testInstallWithoutRestartRequired() throws Exception {
     646    void testInstallWithoutRestartRequired(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    709647        TestUtils.assumeWorkingJMockit();
    710648        final boolean[] loadPluginsCalled = new boolean[] {false};
     
    727665            new PluginServer.RemotePlugin(this.referenceBazJarNew)
    728666        );
    729         pluginServer.applyToWireMockServer(this.pluginServerRule);
     667        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    730668        Config.getPref().putList("plugins", Collections.emptyList());
    731669
     
    749687        TestUtils.syncEDTAndWorkerThreads();
    750688
    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();
    753691
    754692        final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField(
     
    762700        assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins());
    763701
    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()));
    768704        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()));
    779709
    780710        // now we select dummy_plugin
     
    782712
    783713        // 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()));
    788716        assertTrue(model.getNewlyDeactivatedPlugins().isEmpty());
    789717
     
    804732
    805733        // 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")));
    807735
    808736        // the dummy_plugin jar has been installed
     
    826754     * @throws Exception on failure
    827755     */
    828     @JOSMTestRules.OverrideAssumeRevision("Revision: 7000\n")
     756    @AssumeRevision("Revision: 7000\n")
    829757    @Test
    830     public void testInstallMultiVersion() throws Exception {
     758    void testInstallMultiVersion(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    831759        TestUtils.assumeWorkingJMockit();
    832760
     
    835763            new PluginServer.RemotePlugin(this.referenceDummyJarNew),
    836764            new PluginServer.RemotePlugin(this.referenceBazJarNew, Collections.singletonMap(
    837                 "6800_Plugin-Url", "6;" + this.pluginServerRule.url(bazOldServePath)
     765                "6800_Plugin-Url", "6;" + pluginServerRule.url(bazOldServePath)
    838766            ))
    839767        );
    840         pluginServer.applyToWireMockServer(this.pluginServerRule);
     768        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    841769        // need to actually serve this older jar from somewhere
    842         this.pluginServerRule.stubFor(
     770        pluginServerRule.stubFor(
    843771            WireMock.get(WireMock.urlEqualTo(bazOldServePath)).willReturn(
    844772                WireMock.aResponse().withStatus(200).withHeader("Content-Type", "application/java-archive").withBodyFile(
     
    870798        TestUtils.syncEDTAndWorkerThreads();
    871799
    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();
    874802
    875803        final PluginPreferencesModel model = (PluginPreferencesModel) TestUtils.getPrivateField(
     
    883811        assertEquals(model.getDisplayedPlugins(), model.getAvailablePlugins());
    884812
    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()));
    889815        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()));
    900820
    901821        // now we select dummy_plugin
     
    903823
    904824        // 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()));
    909827        assertTrue(model.getNewlyDeactivatedPlugins().isEmpty());
    910828
     
    925843
    926844        // dummy_plugin was fetched
    927         this.pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(bazOldServePath)));
     845        pluginServerRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(bazOldServePath)));
    928846
    929847        // the "old" baz_plugin jar has been installed
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerJOSMTooOldTest.java

    r18690 r18694  
    1818import java.util.stream.Collectors;
    1919
    20 import org.junit.Before;
    21 import org.junit.Rule;
    22 import org.junit.Test;
     20import com.github.tomakehurst.wiremock.client.WireMock;
     21import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
     22import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
     23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     24import org.junit.jupiter.api.BeforeEach;
     25import org.junit.jupiter.api.Test;
     26import org.junit.jupiter.api.extension.RegisterExtension;
    2327import org.openstreetmap.josm.TestUtils;
    2428import org.openstreetmap.josm.data.Preferences;
     
    2731import org.openstreetmap.josm.testutils.JOSMTestRules;
    2832import org.openstreetmap.josm.testutils.PluginServer;
     33import org.openstreetmap.josm.testutils.annotations.AssumeRevision;
     34import org.openstreetmap.josm.testutils.annotations.FullPreferences;
    2935import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    3036import 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;
    3637
    3738/**
    3839 * Test parts of {@link PluginHandler} class when the reported JOSM version is too old for the plugin.
    3940 */
    40 public class PluginHandlerJOSMTooOldTest {
     41@AssumeRevision("Revision: 6000\n")
     42@FullPreferences
     43class PluginHandlerJOSMTooOldTest {
    4144    /**
    4245     * Setup test.
    4346     */
    44     @Rule
     47    @RegisterExtension
    4548    @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();
    4950
    5051    /**
    5152     * Plugin server mock.
    5253     */
    53     @Rule
    54     public WireMockRule pluginServerRule = new WireMockRule(
     54    @RegisterExtension
     55    static WireMockExtension pluginServerRule = WireMockExtension.newInstance().options(
    5556        options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())
    56     );
     57    ).build();
    5758
    5859    /**
    5960     * Setup test.
    6061     */
    61     @Before
     62    @BeforeEach
    6263    public void setUp() {
    6364        Config.getPref().putInt("pluginmanager.version", 999);
    6465        Config.getPref().put("pluginmanager.lastupdate", "999");
    6566        Config.getPref().putList("pluginmanager.sites",
    66                 Collections.singletonList(this.pluginServerRule.url("/plugins"))
     67                Collections.singletonList(pluginServerRule.url("/plugins"))
    6768        );
    6869
     
    115116     */
    116117    @Test
    117     public void testUpdatePluginsDownloadBoth() throws IOException {
     118    void testUpdatePluginsDownloadBoth(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
    118119        TestUtils.assumeWorkingJMockit();
    119120        final PluginServer pluginServer = new PluginServer(
     
    121122            new PluginServer.RemotePlugin(this.referenceBazJarNew)
    122123        );
    123         pluginServer.applyToWireMockServer(this.pluginServerRule);
     124        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    124125        Config.getPref().putList("plugins", Arrays.asList("dummy_plugin", "baz_plugin"));
    125126
     
    162163        TestUtils.assertFileContentsEqual(this.referenceBazJarNew, this.targetBazJar);
    163164
    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")));
    167168
    168169        assertEquals(Config.getPref().getInt("pluginmanager.version", 111), 6000);
     
    177178     */
    178179    @Test
    179     public void testUpdatePluginsSkipOne() throws IOException {
     180    void testUpdatePluginsSkipOne(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
    180181        TestUtils.assumeWorkingJMockit();
    181182        final PluginServer pluginServer = new PluginServer(
     
    183184            new PluginServer.RemotePlugin(this.referenceBazJarNew)
    184185        );
    185         pluginServer.applyToWireMockServer(this.pluginServerRule);
     186        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    186187        Config.getPref().putList("plugins", Arrays.asList("dummy_plugin", "baz_plugin"));
    187188
     
    232233        TestUtils.assertFileContentsEqual(this.referenceBazJarNew, this.targetBazJar);
    233234
    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")));
    237238
    238239        // shouldn't have been updated
     
    249250     */
    250251    @Test
    251     public void testUpdatePluginsUnexpectedlyJOSMTooOld() throws IOException {
     252    void testUpdatePluginsUnexpectedlyJOSMTooOld(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
    252253        TestUtils.assumeWorkingJMockit();
    253254        final PluginServer pluginServer = new PluginServer(
     
    255256            new PluginServer.RemotePlugin(this.referenceBazJarNew, Collections.singletonMap("Plugin-Mainversion", "5500"))
    256257        );
    257         pluginServer.applyToWireMockServer(this.pluginServerRule);
     258        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    258259        Config.getPref().putList("plugins", Collections.singletonList("baz_plugin"));
    259260
     
    283284        TestUtils.assertFileContentsEqual(this.referenceBazJarNew, this.targetBazJar);
    284285
    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")));
    288289
    289290        // should have been updated
     
    303304     */
    304305    @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 {
    307308        TestUtils.assumeWorkingJMockit();
    308309
     
    310311            new PluginServer.RemotePlugin(this.referenceBazJarOld),
    311312            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")
    313314            ))
    314315        );
    315         pluginServer.applyToWireMockServer(this.pluginServerRule);
     316        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    316317        Config.getPref().putList("plugins", Arrays.asList("qux_plugin", "baz_plugin"));
    317318
     
    343344        TestUtils.assertFileContentsEqual(this.referenceQuxJarNewer, this.targetQuxJar);
    344345
    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")));
    349350
    350351        assertEquals(7200, Config.getPref().getInt("pluginmanager.version", 111));
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerMultiVersionTest.java

    r18690 r18694  
    1717import java.util.stream.Collectors;
    1818
    19 import org.junit.Before;
    20 import org.junit.Rule;
    21 import org.junit.Test;
     19import com.github.tomakehurst.wiremock.client.WireMock;
     20import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
     21import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
     22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     23import org.junit.jupiter.api.BeforeEach;
     24import org.junit.jupiter.api.Test;
     25import org.junit.jupiter.api.extension.RegisterExtension;
    2226import org.openstreetmap.josm.TestUtils;
    2327import org.openstreetmap.josm.data.Preferences;
     
    2630import org.openstreetmap.josm.testutils.JOSMTestRules;
    2731import org.openstreetmap.josm.testutils.PluginServer;
     32import org.openstreetmap.josm.testutils.annotations.AssumeRevision;
     33import org.openstreetmap.josm.testutils.annotations.FullPreferences;
    2834import 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;
    3435
    3536/**
    3637 * Test parts of {@link PluginHandler} class with plugins that advertise multiple versions for compatibility.
    3738 */
    38 public class PluginHandlerMultiVersionTest {
     39@FullPreferences
     40class PluginHandlerMultiVersionTest {
    3941    /**
    4042     * Setup test.
    4143     */
    42     @Rule
     44    @RegisterExtension
    4345    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    44     public JOSMTestRules test = new JOSMTestRules().preferences().main();
     46    static JOSMTestRules test = new JOSMTestRules().main();
    4547
    4648    /**
    4749     * Plugin server mock.
    4850     */
    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();
    5354
    5455    /**
    5556     * Setup test.
    5657     */
    57     @Before
    58     public void setUp() {
     58    @BeforeEach
     59    void setUp() {
    5960        Config.getPref().putInt("pluginmanager.version", 999);
    6061        Config.getPref().put("pluginmanager.lastupdate", "999");
    6162        Config.getPref().putList("pluginmanager.sites",
    62                 Collections.singletonList(this.pluginServerRule.url("/plugins"))
     63                Collections.singletonList(pluginServerRule.url("/plugins"))
    6364        );
    6465
     
    9495     * @throws Exception on failure
    9596     */
    96     @JOSMTestRules.OverrideAssumeRevision("Revision: 7501\n")
     97    @AssumeRevision("Revision: 7501\n")
    9798    @Test
    98     public void testUpdatePluginsOneMultiVersion() throws Exception {
     99    void testUpdatePluginsOneMultiVersion(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    99100        TestUtils.assumeWorkingJMockit();
    100101
     
    109110            new PluginServer.RemotePlugin(this.referenceQuxJarNewest, attrOverrides)
    110111        );
    111         pluginServer.applyToWireMockServer(this.pluginServerRule);
     112        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    112113        // need to actually serve this older jar from somewhere
    113         this.pluginServerRule.stubFor(
     114        wireMockRuntimeInfo.getWireMock().register(
    114115            WireMock.get(WireMock.urlEqualTo(quxNewerServePath)).willReturn(
    115116                WireMock.aResponse().withStatus(200).withHeader("Content-Type", "application/java-archive").withBodyFile(
     
    147148        TestUtils.assertFileContentsEqual(this.referenceQuxJarNewer, this.targetQuxJar);
    148149
    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)));
    152153
    153154        assertEquals(7501, Config.getPref().getInt("pluginmanager.version", 111));
     
    161162     * @throws Exception on failure
    162163     */
    163     @JOSMTestRules.OverrideAssumeRevision("Revision: 7000\n")
     164    @AssumeRevision("Revision: 7000\n")
    164165    @Test
    165     public void testUpdatePluginsExistingVersionLatestPossible() throws Exception {
     166    void testUpdatePluginsExistingVersionLatestPossible(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
    166167        TestUtils.assumeWorkingJMockit();
    167168
     
    175176            new PluginServer.RemotePlugin(this.referenceQuxJarNewest, attrOverrides)
    176177        );
    177         pluginServer.applyToWireMockServer(this.pluginServerRule);
     178        pluginServer.applyToWireMockServer(wireMockRuntimeInfo);
    178179        Config.getPref().putList("plugins", Arrays.asList("qux_plugin", "baz_plugin"));
    179180
     
    207208
    208209        // 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")));
    211212
    212213        assertEquals(7000, Config.getPref().getInt("pluginmanager.version", 111));
  • trunk/test/unit/org/openstreetmap/josm/testutils/PluginServer.java

    r18690 r18694  
    1616import java.util.stream.StreamSupport;
    1717
    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;
    2418import com.github.tomakehurst.wiremock.client.MappingBuilder;
    2519import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
    2620import com.github.tomakehurst.wiremock.client.WireMock;
    2721import com.github.tomakehurst.wiremock.core.Options;
    28 import com.github.tomakehurst.wiremock.junit.WireMockRule;
     22import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
     23import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
     24import org.openstreetmap.josm.TestUtils;
     25import org.openstreetmap.josm.tools.Logging;
    2926
    3027public class PluginServer {
     
    138135        }
    139136
    140         public String getPluginURL(WireMockServer wireMockServer) {
     137        public String getPluginURL(WireMockRuntimeInfo wireMock) {
    141138            if (this.pluginURL != null) {
    142139                return this.pluginURL;
    143             } else if (wireMockServer != null && this.getJarPathBeneathFilesDir() != null) {
    144                 return wireMockServer.url(this.getPluginURLPath());
     140            } else if (wireMock != null && this.getJarPathBeneathFilesDir() != null) {
     141                return wireMock.getHttpBaseUrl() + this.getPluginURLPath();
    145142            }
    146143            return "http://example.com" + this.getPluginURLPath();
     
    156153        }
    157154
    158         public String getRemotePluginsListSection(WireMockServer wireMockServer) {
     155        public String getRemotePluginsListSection(WireMockRuntimeInfo wireMock) {
    159156            return String.format(
    160157                "%s.jar;%s\n%s",
    161158                this.getName(),
    162                 this.getPluginURL(wireMockServer),
     159                this.getPluginURL(wireMock),
    163160                this.getRemotePluginsListManifestSection()
    164161            );
     
    192189    }
    193190
    194     public void applyToWireMockServer(WireMockServer wireMockServer) {
     191    public void applyToWireMockServer(WireMockRuntimeInfo wireMock) {
     192        final WireMock wireMockServer = wireMock.getWireMock();
    195193        // first add the plugins list
    196         wireMockServer.stubFor(
     194        wireMockServer.register(
    197195            WireMock.get(WireMock.urlEqualTo("/plugins")).willReturn(
    198196                WireMock.aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody(
    199197                    this.pluginList.stream().map(
    200                         remotePlugin -> remotePlugin.getRemotePluginsListSection(wireMockServer)
     198                        remotePlugin -> remotePlugin.getRemotePluginsListSection(wireMock)
    201199                    ).collect(Collectors.joining())
    202200                )
     
    210208
    211209            if (mappingBuilder != null && responseDefinitionBuilder != null) {
    212                 wireMockServer.stubFor(
     210                wireMockServer.register(
    213211                    remotePlugin.getMappingBuilder().willReturn(remotePlugin.getResponseDefinitionBuilder())
    214212                );
     
    228226    }
    229227
    230     public class PluginServerRule extends WireMockRule {
     228    public class PluginServerRule extends WireMockExtension {
    231229        public PluginServerRule(Options ruleOptions, boolean failOnUnmatchedRequests) {
    232             super(ruleOptions, failOnUnmatchedRequests);
     230            super(extensionOptions().options(ruleOptions).failOnUnmatchedRequests(failOnUnmatchedRequests));
    233231        }
    234232
     
    238236
    239237        @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);
    248240        }
    249241    }
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/BasicPreferences.java

    r18491 r18694  
    44import java.lang.annotation.Documented;
    55import java.lang.annotation.ElementType;
     6import java.lang.annotation.Inherited;
    67import java.lang.annotation.Retention;
    78import java.lang.annotation.RetentionPolicy;
    89import java.lang.annotation.Target;
     10import java.util.Map;
    911
    1012import org.junit.jupiter.api.extension.AfterAllCallback;
     
    1517import org.junit.jupiter.api.extension.ExtensionContext;
    1618import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
     19import org.junit.platform.commons.support.AnnotationSupport;
     20import org.openstreetmap.josm.TestUtils;
    1721import org.openstreetmap.josm.data.Preferences;
    1822import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    1923import org.openstreetmap.josm.data.preferences.JosmUrls;
    2024import org.openstreetmap.josm.spi.preferences.Config;
     25import org.openstreetmap.josm.spi.preferences.Setting;
    2126import org.openstreetmap.josm.testutils.JOSMTestRules;
    2227
     
    3237@Retention(RetentionPolicy.RUNTIME)
    3338@Target({ElementType.TYPE, ElementType.METHOD})
     39@Inherited
    3440@ExtendWith(BasicPreferences.BasicPreferencesExtension.class)
    3541public @interface BasicPreferences {
     
    4753        @Override
    4854        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)) {
    5056                this.afterAll(context);
    5157            }
     
    5763            // Disable saving on put, just to avoid overwriting pref files
    5864            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();
    6070            Config.setPreferencesInstance(pref);
    6171            Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
     
    7080        @Override
    7181        public void beforeEach(ExtensionContext context) throws Exception {
    72             if (AnnotationUtils.elementIsAnnotated(context.getElement(), BasicPreferences.class) || Config.getPref() == null) {
     82            if (AnnotationSupport.isAnnotated(context.getElement(), BasicPreferences.class) || Config.getPref() == null) {
    7383                this.beforeAll(context);
    7484            }
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/FullPreferences.java

    r18037 r18694  
    77import java.lang.annotation.RetentionPolicy;
    88import java.lang.annotation.Target;
    9 import java.util.Map;
    109
    11 import org.junit.jupiter.api.extension.BeforeAllCallback;
    1210import org.junit.jupiter.api.extension.BeforeEachCallback;
    1311import org.junit.jupiter.api.extension.ExtendWith;
    1412import org.junit.jupiter.api.extension.ExtensionContext;
    1513import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
    16 import org.openstreetmap.josm.TestUtils;
    1714import org.openstreetmap.josm.data.Preferences;
     15import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    1816import org.openstreetmap.josm.spi.preferences.Config;
    19 import org.openstreetmap.josm.spi.preferences.Setting;
    2017import org.openstreetmap.josm.testutils.JOSMTestRules;
    2118import org.openstreetmap.josm.testutils.annotations.BasicPreferences.BasicPreferencesExtension;
     
    3734     * Initialize preferences.
    3835     */
    39     class UsePreferencesExtension implements BeforeAllCallback, BeforeEachCallback {
     36    class UsePreferencesExtension implements BeforeEachCallback {
    4037        @Override
    41         public void beforeAll(ExtensionContext context) throws Exception {
     38        public void beforeEach(ExtensionContext context) throws Exception {
    4239            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);
    4644            pref.resetToInitialState();
    4745            pref.enableSaveOnPut(false);
     
    5048            Config.getPref().put("osm-server.url", "http://invalid");
    5149        }
    52 
    53         @Override
    54         public void beforeEach(ExtensionContext context) throws Exception {
    55             if (AnnotationUtils.elementIsAnnotated(context.getElement(), FullPreferences.class)) {
    56                 this.beforeAll(context);
    57             }
    58         }
    5950    }
    6051}
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java

    r18037 r18694  
    77import java.lang.annotation.RetentionPolicy;
    88import java.lang.annotation.Target;
     9import java.util.Locale;
    910
    1011import org.junit.jupiter.api.extension.AfterEachCallback;
     
    1314import org.junit.jupiter.api.extension.ExtensionContext;
    1415import org.junit.platform.commons.support.AnnotationSupport;
     16import org.openstreetmap.josm.tools.LanguageInfo;
    1517
    1618/**
     
    4143        public void beforeEach(ExtensionContext context) {
    4244            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            }
    4448        }
    4549
    4650        @Override
    4751        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            }
    5057        }
    5158    }
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/JosmHome.java

    r18037 r18694  
    1616import java.util.UUID;
    1717
    18 import org.junit.jupiter.api.extension.AfterAllCallback;
    19 import org.junit.jupiter.api.extension.BeforeAllCallback;
     18import org.junit.jupiter.api.extension.AfterEachCallback;
     19import org.junit.jupiter.api.extension.BeforeEachCallback;
    2020import org.junit.jupiter.api.extension.ExtendWith;
    2121import org.junit.jupiter.api.extension.ExtensionContext;
     
    4040     * @author Taylor Smock
    4141     */
    42     class JosmHomeExtension implements BeforeAllCallback, AfterAllCallback {
     42    class JosmHomeExtension implements BeforeEachCallback, AfterEachCallback {
    4343        @Override
    44         public void afterAll(ExtensionContext context) throws Exception {
     44        public void afterEach(ExtensionContext context) throws Exception {
    4545            Path tempDir = context.getStore(Namespace.create(JosmHome.class)).get("home", Path.class);
    4646            Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
     
    5757                }
    5858            });
     59            System.clearProperty("josm.home");
    5960        }
    6061
    6162        @Override
    62         public void beforeAll(ExtensionContext context) throws Exception {
     63        public void beforeEach(ExtensionContext context) throws Exception {
    6364            Path tempDir = Files.createTempDirectory(UUID.randomUUID().toString());
    6465            context.getStore(Namespace.create(JosmHome.class)).put("home", tempDir);
Note: See TracChangeset for help on using the changeset viewer.