Ticket #16010: v1-0005-tests-add-PluginHandlerUpdatePluginsTest.patch

File v1-0005-tests-add-PluginHandlerUpdatePluginsTest.patch, 10.0 KB (added by ris, 20 months ago)
  • new file test/data/__files/plugin/MANIFEST.MF

    From 3519931dd4381beb80da80111bdaf421f4b8f268 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sat, 24 Feb 2018 11:48:11 +0000
    Subject: [PATCH v1 5/5] tests: add PluginHandlerUpdatePluginsTest
    
    ---
     test/data/__files/plugin/MANIFEST.MF               |  12 +++
     test/data/__files/plugin/baz_plugin.jar            | Bin 0 -> 2999 bytes
     test/data/plugin/remotePluginsList                 |  25 +++++
     .../plugins/PluginHandlerUpdatePluginsTest.java    | 114 +++++++++++++++++++++
     4 files changed, 151 insertions(+)
     create mode 100644 test/data/__files/plugin/MANIFEST.MF
     create mode 100644 test/data/__files/plugin/baz_plugin.jar
     create mode 100644 test/data/plugin/remotePluginsList
     create mode 100644 test/unit/org/openstreetmap/josm/plugins/PluginHandlerUpdatePluginsTest.java
    
    diff --git a/test/data/__files/plugin/MANIFEST.MF b/test/data/__files/plugin/MANIFEST.MF
    new file mode 100644
    index 000000000..fd0ed67e3
    - +  
     1Manifest-Version: 1.0
     2Ant-Version: Apache Ant 1.9.6
     3Created-By: 1.8.0_141-15 (Oracle Corporation)
     4Plugin-Mainversion: 8001
     5Plugin-Version: 7
     6Plugin-Class: org.openstreetmap.josm.plugins.baz.BazPlugin
     7Plugin-Description: A functionless example plugin
     8Plugin-Date: 2017-12-31T00:58:30.642
     9Author: Author A
     10Plugin-Link: https://example.com/author-a/josm-baz
     11Plugin-Icon: images/icons/24x24/baz.png
     12
  • new file test/data/__files/plugin/baz_plugin.jar

    diff --git a/test/data/__files/plugin/baz_plugin.jar b/test/data/__files/plugin/baz_plugin.jar
    new file mode 100644
    index 0000000000000000000000000000000000000000..e00bd97b820bfbc096eff5ab30b3b32cc98e1d02
    GIT binary patch
    literal 2999
    zcmWIWW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QeUwCP5dxp!KCx5+X9F(@u
    zS2}d9>I3`Ir3D^MiJbZ`f_H^76boO9RDIv@hw0|0XV?5U-2QWS`Q`JA?H0yeVoP(6
    zT=6jUT+lI*S4SL$6ROU9Z7u3bS$#h+L#%$mmnrM~Ql%~LKGOI&ab1^MTF0@wahK1U
    z-aK`2Ge0O5+>E&YYZ<T_3ugwU0!Ah-2HZ^uPzpi-cq;+YpkQPY0X80BO$y{164azX
    z0Bs->t`(_)fowT?xeKaE5ugm{TzI{Ta51_jP|b<}vk{tL^(=0!pqdr|j-hLX)w>7-
    z&~pu_=0$+-Km#E4Fm4^7niv5jfq4=$*C7WHx{aWU3jsW_>W9|TxE%qisS%(Kw;`~s
    zkIzM*ni~Oj6E+M|k0a6%C_<6zWz<yg2WTL)UI)1XmiR!LkV`gDm5l%%z*LUA0!KCn
    o6u!uL15^$ofHkl-$BZ9BrDA|LE2tH~zzc*4K$kcIo9YY<00j=C$p8QV
  • new file test/data/plugin/remotePluginsList

    literal 0
    HcmV?d00001
    
    diff --git a/test/data/plugin/remotePluginsList b/test/data/plugin/remotePluginsList
    new file mode 100644
    index 000000000..c2c2df93b
    - +  
     1dummy_plugin.jar;http://localhost:%1$s/plugin/dummy_plugin.jar
     2        Manifest-Version: 1.0
     3        Ant-Version: Apache Ant 1.9.6
     4        Author: Don-vip
     5        Created-By: 1.7.0_91-b02 (Oracle Corporation)
     6        Plugin-Canloadatruntime: true
     7        Plugin-Class: org.openstreetmap.josm.plugins.fr.epci.EpciPlugin
     8        Plugin-Date: 2015-11-19T08:21:07.645033Z
     9        Plugin-Description: Handling of French EPCIs (boundary=local_authority)
     10        Plugin-Early: true
     11        Plugin-Link: http://wiki.openstreetmap.org/wiki/FR:JOSM/Fr:Plugin/EPCI-fr
     12        Plugin-Mainversion: 7001
     13        Plugin-Version: 31772
     14baz_plugin.jar;http://localhost:%1$s/plugin/baz_plugin.jar
     15        Manifest-Version: 1.0
     16        Ant-Version: Apache Ant 1.9.6
     17        Created-By: 1.8.0_141-15 (Oracle Corporation)
     18        Plugin-Mainversion: 8001
     19        Plugin-Version: 7
     20        Plugin-Class: org.openstreetmap.josm.plugins.baz.BazPlugin
     21        Plugin-Description: A functionless example plugin
     22        Plugin-Date: 2017-12-31T00:58:30.642
     23        Author: Author A
     24        Plugin-Link: https://example.com/author-a/josm-baz
     25        Plugin-Icon: images/icons/24x24/baz.png
  • new file test/unit/org/openstreetmap/josm/plugins/PluginHandlerUpdatePluginsTest.java

    diff --git a/test/unit/org/openstreetmap/josm/plugins/PluginHandlerUpdatePluginsTest.java b/test/unit/org/openstreetmap/josm/plugins/PluginHandlerUpdatePluginsTest.java
    new file mode 100644
    index 000000000..92455363e
    - +  
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins;
     3
     4import static org.junit.Assert.assertEquals;
     5import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
     6
     7import java.io.File;
     8import java.io.FileReader;
     9import java.util.ArrayList;
     10
     11import org.junit.Before;
     12import org.junit.Rule;
     13import org.junit.Test;
     14import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.TestUtils;
     16import org.openstreetmap.josm.spi.preferences.Config;
     17import org.openstreetmap.josm.testutils.ExtendedDialogMocker;
     18import org.openstreetmap.josm.testutils.JOSMTestRules;
     19
     20import com.google.common.io.CharStreams;
     21import com.google.common.collect.ImmutableList;
     22import com.google.common.collect.ImmutableMap;
     23
     24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     25
     26import com.github.tomakehurst.wiremock.client.WireMock;
     27import com.github.tomakehurst.wiremock.junit.WireMockRule;
     28
     29/**
     30 * Further unit tests of {@link PluginHandler} class.
     31 */
     32public class PluginHandlerUpdatePluginsTest {
     33    /**
     34     * Setup test.
     35     */
     36    @Rule
     37    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     38    public JOSMTestRules test = new JOSMTestRules().preferences().main().assumeRevision(
     39        "Revision: 6000\n"
     40    );
     41
     42    /**
     43     * HTTP mock.
     44     */
     45    @Rule
     46    public WireMockRule wireMockRule = new WireMockRule(
     47        options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())
     48    );
     49
     50    @Before
     51    public void setUp() throws Exception {
     52        try (
     53            FileReader pluginListReader = new FileReader(
     54                new File(TestUtils.getTestDataRoot(), "plugin/remotePluginsList")
     55            );
     56        ) {
     57            final String pluginList = String.format(
     58                CharStreams.toString(pluginListReader),
     59                this.wireMockRule.port()
     60            );
     61
     62            this.wireMockRule.stubFor(
     63                WireMock.get(WireMock.urlEqualTo("/plugins")).willReturn(
     64                    WireMock.aResponse()
     65                    .withStatus(200)
     66                    .withHeader("Content-Type", "text/plain")
     67                    .withBody(pluginList)
     68                )
     69            );
     70            ImmutableList.of("dummy_plugin", "baz_plugin").forEach(plugin_name -> this.wireMockRule.stubFor(
     71                WireMock.get(WireMock.urlEqualTo("/plugin/" + plugin_name + ".jar")).willReturn(
     72                    WireMock.aResponse()
     73                    .withStatus(200)
     74                    .withHeader("Content-Type", "application/java-archive")
     75                    .withBodyFile("plugin/" + plugin_name + ".jar")
     76                )
     77            ));
     78        }
     79    }
     80
     81    /**
     82     * test update of plugins when those plugins turn out to require a higher JOSM version, but the
     83     * user chooses to update them anyway.
     84     */
     85    @Test
     86    public void testUpdatePlugins() {
     87        new ExtendedDialogMocker(ImmutableMap.<String, Object>builder()
     88            .put("JOSM version 8,001 required for plugin baz_plugin.", "Download Plugin")
     89            .put("JOSM version 7,001 required for plugin dummy_plugin.", "Download Plugin")
     90            .build()
     91        );
     92
     93        Config.getPref().putList("plugins", ImmutableList.of("dummy_plugin", "baz_plugin"));
     94        Config.getPref().putList("pluginmanager.sites",
     95            ImmutableList.of(String.format("http://localhost:%s/plugins", this.wireMockRule.port()))
     96        );
     97
     98        final ArrayList<PluginInformation> updatedPlugins = new ArrayList<>(PluginHandler.updatePlugins(Main.parent, null, null, false));
     99
     100        updatedPlugins.sort((a, b) -> a.name.compareTo(b.name));
     101
     102        assertEquals(2, updatedPlugins.size());
     103
     104        assertEquals(updatedPlugins.get(0).name, "baz_plugin");
     105        assertEquals("7", updatedPlugins.get(0).localversion);
     106
     107        assertEquals(updatedPlugins.get(1).name, "dummy_plugin");
     108        assertEquals("31772", updatedPlugins.get(1).localversion);
     109
     110        this.wireMockRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugins")));
     111        this.wireMockRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/dummy_plugin.jar")));
     112        this.wireMockRule.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/plugin/baz_plugin.jar")));
     113    }
     114}