Changeset 14549 in josm for trunk/test/unit


Ignore:
Timestamp:
2018-12-10T22:37:27+01:00 (5 years ago)
Author:
Don-vip
Message:

see #16073 - support WMS_ENDPOINT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

    r14544 r14549  
    3030import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
    3131import org.openstreetmap.josm.TestUtils;
     32import org.openstreetmap.josm.actions.AddImageryLayerAction;
     33import org.openstreetmap.josm.actions.AddImageryLayerAction.LayerSelection;
    3234import org.openstreetmap.josm.data.Bounds;
    3335import org.openstreetmap.josm.data.coor.LatLon;
     
    3739import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    3840import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
     41import org.openstreetmap.josm.data.imagery.LayerDetails;
    3942import org.openstreetmap.josm.data.imagery.Shape;
    4043import org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob;
    4144import org.openstreetmap.josm.data.imagery.TemplatedWMSTileSource;
    4245import org.openstreetmap.josm.data.imagery.TileJobOptions;
    43 import org.openstreetmap.josm.data.imagery.WMSEndpointTileSource;
    4446import org.openstreetmap.josm.data.imagery.WMTSTileSource;
    4547import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException;
     
    4749import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    4850import org.openstreetmap.josm.data.projection.Projections;
     51import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    4952import org.openstreetmap.josm.testutils.JOSMTestRules;
    5053import org.openstreetmap.josm.tools.HttpClient;
     
    245248                checkTileUrl(info, tileSource, center, Utils.clamp(12, info.getMinZoom() + 1, info.getMaxZoom()));
    246249            }
    247         } catch (IOException | WMTSGetCapabilitiesException | IllegalArgumentException e) {
     250        } catch (IOException | RuntimeException | WMSGetCapabilitiesException | WMTSGetCapabilitiesException e) {
    248251            addError(info, info.getUrl() + " -> " + e.toString());
    249252        }
     
    264267    }
    265268
    266     private static AbstractTileSource getTileSource(ImageryInfo info) throws IOException, WMTSGetCapabilitiesException {
     269    private static AbstractTileSource getTileSource(ImageryInfo info)
     270            throws IOException, WMTSGetCapabilitiesException, WMSGetCapabilitiesException {
    267271        switch (info.getImageryType()) {
    268272            case BING:
     
    272276            case TMS:
    273277                return new TemplatedTMSTileSource(info);
     278            case WMS_ENDPOINT:
     279                info = convertWmsEndpointToWms(info); // fall-through
    274280            case WMS:
    275281                return new TemplatedWMSTileSource(info, getProjection(info));
    276             case WMS_ENDPOINT:
    277                 return new WMSEndpointTileSource(info, getProjection(info));
    278282            case WMTS:
    279283                return new WMTSTileSource(info, getProjection(info));
     
    281285                throw new UnsupportedOperationException(info.toString());
    282286        }
     287    }
     288
     289    private static ImageryInfo convertWmsEndpointToWms(ImageryInfo info) throws IOException, WMSGetCapabilitiesException {
     290        return AddImageryLayerAction.getWMSLayerInfo(
     291                info, wms -> new LayerSelection(firstLeafLayer(wms.getLayers()), wms.getPreferredFormat(), true));
     292    }
     293
     294    private static List<LayerDetails> firstLeafLayer(List<LayerDetails> layers) {
     295        for (LayerDetails layer : layers) {
     296            if (layer.getChildren().isEmpty()) {
     297                return Collections.singletonList(layer);
     298            } else {
     299                return firstLeafLayer(layer.getChildren());
     300            }
     301        }
     302        return Collections.emptyList();
    283303    }
    284304
Note: See TracChangeset for help on using the changeset viewer.