kopia lustrzana https://github.com/JOSM/MapWithAI
Add tests for zip file paint style and fiddle with other tests/problems
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
b6c1ff07e7
commit
51aa40925d
|
@ -4,10 +4,12 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.Bounds;
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
|
import org.openstreetmap.josm.data.DataSource;
|
||||||
import org.openstreetmap.josm.data.osm.DataSet;
|
import org.openstreetmap.josm.data.osm.DataSet;
|
||||||
import org.openstreetmap.josm.data.osm.DataSourceChangeEvent;
|
import org.openstreetmap.josm.data.osm.DataSourceChangeEvent;
|
||||||
import org.openstreetmap.josm.data.osm.DataSourceListener;
|
import org.openstreetmap.josm.data.osm.DataSourceListener;
|
||||||
|
@ -23,6 +25,7 @@ import org.openstreetmap.josm.tools.Destroyable;
|
||||||
public final class DownloadListener implements DataSourceListener, Destroyable {
|
public final class DownloadListener implements DataSourceListener, Destroyable {
|
||||||
|
|
||||||
final WeakReference<DataSet> ds;
|
final WeakReference<DataSet> ds;
|
||||||
|
private double BBOX_SIMILARITY_DEGREES = 0.001;
|
||||||
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
|
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
|
||||||
|
|
||||||
public DownloadListener(DataSet dataSet) {
|
public DownloadListener(DataSet dataSet) {
|
||||||
|
@ -43,6 +46,9 @@ public final class DownloadListener implements DataSourceListener, Destroyable {
|
||||||
if (layer.downloadContinuous()) {
|
if (layer.downloadContinuous()) {
|
||||||
MapWithAIDataUtils.getMapWithAIData(layer, event.getAdded().stream().map(ev -> ev.bounds)
|
MapWithAIDataUtils.getMapWithAIData(layer, event.getAdded().stream().map(ev -> ev.bounds)
|
||||||
.map(Bounds::toBBox).collect(Collectors.toList()));
|
.map(Bounds::toBBox).collect(Collectors.toList()));
|
||||||
|
List<Bounds> bounds = DataSource.getDataSourceBounds(event.getSource().getDataSources());
|
||||||
|
bounds.removeIf(a -> layer.getDataSet().getDataSourceBounds().stream().map(Bounds::toBBox)
|
||||||
|
.anyMatch(b -> b.bboxIsFunctionallyEqual(a.toBBox(), BBOX_SIMILARITY_DEGREES)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,15 +144,15 @@ public class MapPaintUtils {
|
||||||
* @param ds The dataset to add sources to
|
* @param ds The dataset to add sources to
|
||||||
*/
|
*/
|
||||||
public static synchronized void addSourcesToPaintStyle(DataSet ds) {
|
public static synchronized void addSourcesToPaintStyle(DataSet ds) {
|
||||||
/* TODO Depends upon JOSM-19547 */
|
|
||||||
if (Version.getInstance().getVersion() < 20_000
|
|
||||||
&& Version.getInstance().getVersion() == Version.JOSM_UNKNOWN_VERSION) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull)
|
List<String> sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull)
|
||||||
.distinct().collect(Collectors.toList());
|
.distinct().collect(Collectors.toList());
|
||||||
StyleSource styleSource = getMapWithAIPaintStyle();
|
StyleSource styleSource = getMapWithAIPaintStyle();
|
||||||
|
/* TODO Depends upon JOSM-19547 */
|
||||||
|
if (Version.getInstance().getVersion() < 20_000
|
||||||
|
&& Version.getInstance().getVersion() == Version.JOSM_UNKNOWN_VERSION || styleSource == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!styleSource.isLoaded()) {
|
if (!styleSource.isLoaded()) {
|
||||||
styleSource.loadStyleSource();
|
styleSource.loadStyleSource();
|
||||||
}
|
}
|
||||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -1,26 +0,0 @@
|
||||||
{
|
|
||||||
"id" : "6eeb774c-de7d-4486-abc0-c06ace4916d0",
|
|
||||||
"name" : "josmfile",
|
|
||||||
"request" : {
|
|
||||||
"url" : "/josmfile?page=Styles/MapWithAI&zip=1",
|
|
||||||
"method" : "GET"
|
|
||||||
},
|
|
||||||
"response" : {
|
|
||||||
"status" : 200,
|
|
||||||
"base64Body" : "UEsDBBQAAAAIAOSAhU93j0zPDgIAAHYFAAAdAAAAU3R5bGVzX01hcFdpdGhBSS1zdHlsZS5tYXBjc3OlVE1v00AQvftXTA2HOMJ1EoEgRgi4ROJQhJQIDlWINvbY2XbtMTtrjIHy29mNnShtVClR97Sej/fm43kLNML744E9RhqFMfhXovomzebjJ//t1p4iJ1pWRlJpvV8l10LJ38J9A2WwD4dUGNHniNpsSNvwhWgVaZgXlNz2vp+oucMaX75eTUbjaTgeh6OXvbuQZXhDXIQHca8mk6l133leNDz/eDCEORq4LETV2FKFhMzWJJSC25Ka8kELjIbBJZ1/Iu8D11VF2iIMjhuxfbyZBtCN29IYWeYcx7yhZuWq6RzuKLFGFYPRA39uvVARs1wrPCiV1jeYGPaDbmx3djo9ZI9YYtMjmrayi10TKRRlF35A8BmbHUiKmaiVcfYaO1Ouqa7sDnZFbtdwn6igVGYS05PYrvrgI8pMKD6dk9RpdF80hvhLsks9mzIawmIjGTT+qKVGhn65IEswG4RK1bm9Dhppl6dRpHCL7VZbe6U5zSXMcV9fbCjPFa6cc6VEizoAq5p9b0fuk5pcbLOgErI0bFp7pTKiLAOHA1ucx3q3v1Qj2mumWif47l/0ffBeBla6iSamzPxNZS6NULmiNQbPo+V1X+rA363BD5YXsdXaRbzTwYsnQZZOjkuH+DScYi+0ZfxAoXzvMdgN4eB56MISUu4N25ufzWaj0Wx2HB8nihjTSZ+XWTmEjycDeP8BUEsBAhQAFAAAAAgA5ICFT3ePTM8OAgAAdgUAAB0AAAAAAAAAAAAAAIABAAAAAFN0eWxlc19NYXBXaXRoQUktc3R5bGUubWFwY3NzUEsFBgAAAAABAAEASwAAAEkCAAAAAA==",
|
|
||||||
"headers" : {
|
|
||||||
"Date" : "Thu, 05 Dec 2019 15:07:08 GMT",
|
|
||||||
"Server" : "Apache/2.4.29 (Ubuntu)",
|
|
||||||
"X-Clacks-Overhead" : "GNU Terry Pratchett",
|
|
||||||
"Strict-Transport-Security" : "max-age=16070400; includeSubDomains",
|
|
||||||
"Content-Disposition" : "attachment; filename=\"Styles_MapWithAI.zip\"",
|
|
||||||
"Set-Cookie" : "trac_session=52872db4f9b904822ae80bba; expires=Wed, 04 Mar 2020 15:07:08 GMT; httponly; Path=/",
|
|
||||||
"Keep-Alive" : "timeout=5, max=100",
|
|
||||||
"Connection" : "Keep-Alive",
|
|
||||||
"Content-Type" : "application/zip"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uuid" : "6eeb774c-de7d-4486-abc0-c06ace4916d0",
|
|
||||||
"persistent" : true,
|
|
||||||
"insertionIndex" : 13
|
|
||||||
}
|
|
|
@ -14,8 +14,6 @@ import java.util.List;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.awaitility.Awaitility;
|
|
||||||
import org.awaitility.Durations;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openstreetmap.josm.TestUtils;
|
import org.openstreetmap.josm.TestUtils;
|
||||||
|
@ -30,11 +28,8 @@ import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
||||||
import org.openstreetmap.josm.data.osm.Way;
|
import org.openstreetmap.josm.data.osm.Way;
|
||||||
import org.openstreetmap.josm.gui.MainApplication;
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.gui.layer.GpxLayer;
|
import org.openstreetmap.josm.gui.layer.GpxLayer;
|
||||||
import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
|
||||||
import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.tools.MapPaintUtils;
|
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
|
|
||||||
|
@ -138,19 +133,6 @@ public class MapWithAIDataUtilsTest {
|
||||||
assertEquals(0, ds1.allPrimitives().size(), "All of the primitives should have been removed from the DataSet");
|
assertEquals(0, ds1.allPrimitives().size(), "All of the primitives should have been removed from the DataSet");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddPaintStyle() {
|
|
||||||
MapPaintUtils.removeMapWithAIPaintStyles();
|
|
||||||
Awaitility.await().atMost(Durations.TEN_SECONDS).until(() -> !MapPaintUtils.checkIfMapWithAIPaintStyleExists());
|
|
||||||
List<StyleSource> paintStyles = MapPaintStyles.getStyles().getStyleSources();
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
MapPaintUtils.addMapWithAIPaintStyles();
|
|
||||||
paintStyles = MapPaintStyles.getStyles().getStyleSources();
|
|
||||||
assertEquals(1, paintStyles.stream().filter(s -> s.title.contains("MapWithAI")).count(),
|
|
||||||
"The paintstyle should have been added, but only one of it");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapWithAIURLPreferences() {
|
public void testMapWithAIURLPreferences() {
|
||||||
final String fakeUrl = "https://fake.url";
|
final String fakeUrl = "https://fake.url";
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.openstreetmap.josm.tools.Logging;
|
||||||
*/
|
*/
|
||||||
public class MapWithAIMenuTest {
|
public class MapWithAIMenuTest {
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static JOSMTestRules rule = new MapWithAITestRules().wiremock().sources().projection().main();
|
static JOSMTestRules rule = new MapWithAITestRules().wiremock().sources().territories().projection().main();
|
||||||
private static MapWithAIMenu menu;
|
private static MapWithAIMenu menu;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
|
|
|
@ -17,7 +17,9 @@ import java.util.stream.Collectors;
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.awaitility.Durations;
|
import org.awaitility.Durations;
|
||||||
import org.junit.runners.model.InitializationError;
|
import org.junit.runners.model.InitializationError;
|
||||||
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
||||||
|
import org.openstreetmap.josm.gui.progress.swing.ProgressMonitorExecutor;
|
||||||
import org.openstreetmap.josm.io.OsmApi;
|
import org.openstreetmap.josm.io.OsmApi;
|
||||||
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
||||||
import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
||||||
|
@ -52,6 +54,7 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
private String currentReleaseUrl;
|
private String currentReleaseUrl;
|
||||||
private Collection<String> sourceSites;
|
private Collection<String> sourceSites;
|
||||||
private Runnable mapwithaiLayerInfoMocker;
|
private Runnable mapwithaiLayerInfoMocker;
|
||||||
|
private boolean territories;
|
||||||
|
|
||||||
public MapWithAITestRules() {
|
public MapWithAITestRules() {
|
||||||
super();
|
super();
|
||||||
|
@ -79,9 +82,15 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapWithAITestRules territories() {
|
||||||
|
this.territories = true;
|
||||||
|
super.territories();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MapWithAITestRules wiremock() {
|
public MapWithAITestRules wiremock() {
|
||||||
this.wiremock = true;
|
this.wiremock = true;
|
||||||
super.territories();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +166,14 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void after() throws ReflectiveOperationException {
|
protected void after() throws ReflectiveOperationException {
|
||||||
|
ProgressMonitorExecutor worker = (ProgressMonitorExecutor) MainApplication.worker;
|
||||||
|
while (worker.getActiveCount() > 0) {
|
||||||
|
try {
|
||||||
|
wait(20);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Logging.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
super.after();
|
super.after();
|
||||||
if (wiremock) {
|
if (wiremock) {
|
||||||
wireMock.stop();
|
wireMock.stop();
|
||||||
|
@ -182,7 +199,8 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
TestRunnerDecorator.cleanUpAllMocks();
|
TestRunnerDecorator.cleanUpAllMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resetMapWithAILayerInfo() {
|
private void resetMapWithAILayerInfo() {
|
||||||
|
if (territories) {
|
||||||
synchronized (MapWithAILayerInfo.class) {
|
synchronized (MapWithAILayerInfo.class) {
|
||||||
MapWithAILayerInfo.getInstance().clear();
|
MapWithAILayerInfo.getInstance().clear();
|
||||||
MapWithAILayerInfo.getInstance().getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry)
|
MapWithAILayerInfo.getInstance().getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry)
|
||||||
|
@ -190,6 +208,7 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
MapWithAILayerInfo.getInstance().save();
|
MapWithAILayerInfo.getInstance().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace URL servers with wiremock
|
* Replace URL servers with wiremock
|
||||||
|
@ -231,7 +250,8 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
|
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
|
||||||
if (wireMock != null && !request.getUrl().endsWith("/capabilities")) {
|
if (wireMock != null && !request.getUrl().endsWith("/capabilities")
|
||||||
|
&& (!response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip"))) {
|
||||||
String origBody = response.getBodyAsString();
|
String origBody = response.getBodyAsString();
|
||||||
String newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/");
|
String newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/");
|
||||||
return Response.Builder.like(response).but().body(newBody).build();
|
return Response.Builder.like(response).but().body(newBody).build();
|
||||||
|
|
Ładowanie…
Reference in New Issue