Changeset 17332 in josm for trunk


Ignore:
Timestamp:
2020-11-23T16:01:19+01:00 (5 months ago)
Author:
Don-vip
Message:

fix #20131 - fix unit tests and codestyle violations

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.java

    r17329 r17332  
    541541    // catch reordered arguments and switches to WMS version 1.3.0
    542542    String unifyWMS(String url) {
    543         String x[] = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x").replaceAll("(?i)SRS=", "CRS=").split("\\?");
    544         String a[] = x[1].split("&");
     543        String[] x = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x").replaceAll("(?i)SRS=", "CRS=").split("\\?");
     544        String[] a = x[1].split("&");
    545545        Arrays.sort(a);
    546         url = x[0]+"?"+String.join("&",a);
     546        url = x[0]+"?"+String.join("&", a);
    547547        return url;
    548548    }
     
    579579
    580580                        if (ide.equals(idj) && Objects.equals(getType(j), getType(e))) {
    581                             if(getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
     581                            if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
    582582                                myprintln("# WMS-URL for id "+idj+" modified: "+getDescription(j));
    583583                            } else {
     
    591591                            break;
    592592                        }
    593                         Collection<String> old = ((ImageryInfo)j).getOldIds();
    594                         if(old != null) {
     593                        Collection<String> old = j.getOldIds();
     594                        if (old != null) {
    595595                            for (String oidj : old) {
    596596                                if (ide.equals(oidj) && Objects.equals(getType(j), getType(e))) {
    597                                     if(getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
     597                                    if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
    598598                                        myprintln("# WMS-URL for oldid "+idj+" modified: "+getDescription(j));
    599599                                    } else {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java

    r17330 r17332  
    124124        // multiple error object? prepare a HTML list
    125125        //
    126         if (!errors.isEmpty() && !GraphicsEnvironment.isHeadless()) {
     126        final Collection<String> items = task.getErrorMessages();
     127        if (!items.isEmpty() && !GraphicsEnvironment.isHeadless()) {
    127128            SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(
    128129                    MainApplication.getMainFrame(),
    129                     "<html>"+Utils.joinAsHtmlUnorderedList(task.getErrorMessages())+"</html>",
     130                    "<html>"+Utils.joinAsHtmlUnorderedList(items)+"</html>",
    130131                    tr("Errors during download"),
    131132                    JOptionPane.ERROR_MESSAGE));
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r17283 r17332  
    765765        OsmPrimitive result = getPrimitiveById(primitiveId);
    766766        if (result == null && primitiveId != null) {
    767             Logging.warn(tr(
     767            Logging.error(new IllegalStateException(tr(
    768768                    "JOSM expected to find primitive [{0} {1}] in dataset but it is not there. Please report this "
    769769                            + "at {2}. This is not a critical error, it should be safe to continue in your work.",
    770                     primitiveId.getType(), Long.toString(primitiveId.getUniqueId()), Config.getUrls().getJOSMWebsite()));
    771             Logging.error(new Exception());
     770                    primitiveId.getType(), Long.toString(primitiveId.getUniqueId()), Config.getUrls().getJOSMWebsite())));
    772771        }
    773772
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesWithReferrersTask.java

    r16611 r17332  
    234234        }
    235235        List<PrimitiveId> downloaded = new ArrayList<>(ids);
    236         downloaded.removeAll(missingPrimitives);
     236        if (missingPrimitives != null) {
     237            downloaded.removeAll(missingPrimitives);
     238        }
    237239        return downloaded;
    238240    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r17314 r17332  
    171171
    172172        gc.anchor = GridBagConstraints.NORTHWEST;
    173         gc.fill = GridBagConstraints.HORIZONTAL;
     173        gc.fill = HORIZONTAL;
    174174        gc.weightx = 0.0;
    175175        gc.insets = new Insets(0, 0, 0, 3);
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java

    r17330 r17332  
    66import java.util.LinkedList;
    77import java.util.List;
     8import java.util.concurrent.ExecutionException;
     9import java.util.concurrent.TimeUnit;
     10import java.util.concurrent.TimeoutException;
    811import java.util.stream.Collectors;
    912
     
    6770            final DownloadPrimitivesWithReferrersTask task = new DownloadPrimitivesWithReferrersTask(
    6871                    newLayer, ps, referrers, relationMembers, args.get("layer_name"), null);
    69             MainApplication.worker.submit(task);
     72            try {
     73                MainApplication.worker.submit(task).get(OSM_DOWNLOAD_TIMEOUT.get(), TimeUnit.SECONDS);
     74            } catch (InterruptedException | ExecutionException | TimeoutException e) {
     75                Logging.error(e);
     76            }
    7077            MainApplication.worker.submit(() -> {
    7178                final List<PrimitiveId> downloaded = task.getDownloadedId();
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r17275 r17332  
    480480
    481481    /**
    482      * Return WireMock server serving files under ticker directory
     482     * Return WireMock server serving files under ticket directory
    483483     * @param ticketId Ticket numeric identifier
    484484     * @return WireMock HTTP server on dynamic port
     
    493493
    494494    /**
    495      * Return WireMock server serving files under ticker directory
     495     * Return WireMock server
    496496     * @return WireMock HTTP server on dynamic port
    497497     */
     
    499499            return new WireMockServer(
    500500                    WireMockConfiguration.options()
     501                        .withRootDirectory("test/data")
    501502                        .dynamicPort()
    502503                    );
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java

    r17275 r17332  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
     5import static com.github.tomakehurst.wiremock.client.WireMock.get;
     6import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
    47import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    58import static org.junit.jupiter.api.Assertions.assertEquals;
    69import static org.junit.jupiter.api.Assertions.assertThrows;
    710
     11import org.junit.jupiter.api.Test;
    812import org.junit.jupiter.api.extension.RegisterExtension;
    9 import org.junit.jupiter.api.Test;
     13import org.openstreetmap.josm.TestUtils;
    1014import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
     15import org.openstreetmap.josm.spi.preferences.Config;
    1116import org.openstreetmap.josm.testutils.JOSMTestRules;
     17
     18import com.github.tomakehurst.wiremock.WireMockServer;
    1219
    1320import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    3643    @Test
    3744    void testBadRequestNoParam() {
    38         assertDoesNotThrow(() -> newHandler(null).handle());
     45        Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
     46        assertEquals("No valid object identifier has been provided", e.getMessage());
    3947    }
    4048
     
    6270    @Test
    6371    void testNominalRequest() {
    64         assertDoesNotThrow(() -> newHandler("https://localhost?objects=foo,bar").handle());
     72        WireMockServer wiremock = TestUtils.getWireMockServer();
     73        wiremock.addStubMapping(get(urlEqualTo("/capabilities")).willReturn(aResponse().withStatusMessage("OK")
     74                .withBodyFile("api/capabilities")).build());
     75        String w1 = "<way id=\"1\" version=\"1\"><nd ref=\"1\"/><nd ref=\"2\"/></way>";
     76        String n1 = "<node id=\"1\" version=\"1\"/>";
     77        String n2 = "<node id=\"2\" version=\"1\"/>";
     78        wiremock.addStubMapping(get(urlEqualTo("/0.6/ways?ways=1")).willReturn(aResponse().withStatusMessage("OK")
     79                .withBody(osm(w1))).build());
     80        wiremock.addStubMapping(get(urlEqualTo("/0.6/nodes?nodes=1,2")).willReturn(aResponse().withStatusMessage("OK")
     81                .withBody(osm(n1 + n2))).build());
     82        wiremock.addStubMapping(get(urlEqualTo("/0.6/way/1/full")).willReturn(aResponse().withStatusMessage("OK")
     83                .withBody(osm(n1 + n2 + w1))).build());
     84        wiremock.start();
     85        Config.getPref().put("osm-server.url", wiremock.baseUrl());
     86        try {
     87            assertDoesNotThrow(() -> newHandler("https://localhost?objects=n1,w1").handle());
     88        } finally {
     89            wiremock.stop();
     90        }
     91    }
     92
     93    private static String osm(String xml) {
     94        return "<osm version=\"0.6\">" + xml + "</osm>";
    6595    }
    6696}
Note: See TracChangeset for help on using the changeset viewer.