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.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.DataSourceChangeEvent;
|
||||
import org.openstreetmap.josm.data.osm.DataSourceListener;
|
||||
|
@ -23,6 +25,7 @@ import org.openstreetmap.josm.tools.Destroyable;
|
|||
public final class DownloadListener implements DataSourceListener, Destroyable {
|
||||
|
||||
final WeakReference<DataSet> ds;
|
||||
private double BBOX_SIMILARITY_DEGREES = 0.001;
|
||||
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
|
||||
|
||||
public DownloadListener(DataSet dataSet) {
|
||||
|
@ -43,6 +46,9 @@ public final class DownloadListener implements DataSourceListener, Destroyable {
|
|||
if (layer.downloadContinuous()) {
|
||||
MapWithAIDataUtils.getMapWithAIData(layer, event.getAdded().stream().map(ev -> ev.bounds)
|
||||
.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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,8 +84,8 @@ public class MapPaintUtils {
|
|||
"https://gitlab.com/(gokaart/JOSM_MapWithAI|smocktaylor/rapid)/raw/master/src/resources/styles/standard/(mapwithai|rapid).mapcss"),
|
||||
TEST_PATTERN, Pattern.compile("resource://styles/standard/mapwithai.mapcss"));
|
||||
new ArrayList<>(MapPaintStyles.getStyles().getStyleSources()).parallelStream()
|
||||
.filter(style -> oldUrls.stream().anyMatch(p -> p.matcher(style.url).matches()))
|
||||
.forEach(MapPaintStyles::removeStyle);
|
||||
.filter(style -> oldUrls.stream().anyMatch(p -> p.matcher(style.url).matches()))
|
||||
.forEach(MapPaintStyles::removeStyle);
|
||||
|
||||
if (!checkIfMapWithAIPaintStyleExists()) {
|
||||
final MapCSSStyleSource style = new MapCSSStyleSource(paintStyleResourceUrl, MapWithAIPlugin.NAME,
|
||||
|
@ -106,7 +106,7 @@ public class MapPaintUtils {
|
|||
public static void removeMapWithAIPaintStyles() {
|
||||
new ArrayList<>(MapPaintStyles.getStyles().getStyleSources()).parallelStream().filter(
|
||||
source -> paintStyleResourceUrl.equals(source.url) || TEST_PATTERN.matcher(source.url).matches())
|
||||
.forEach(style -> GuiHelper.runInEDT(() -> MapPaintStyles.removeStyle(style)));
|
||||
.forEach(style -> GuiHelper.runInEDT(() -> MapPaintStyles.removeStyle(style)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,15 +144,15 @@ public class MapPaintUtils {
|
|||
* @param ds The dataset to add sources to
|
||||
*/
|
||||
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)
|
||||
.distinct().collect(Collectors.toList());
|
||||
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()) {
|
||||
styleSource.loadStyleSource();
|
||||
}
|
||||
|
@ -257,8 +257,8 @@ public class MapPaintUtils {
|
|||
out.write(System.lineSeparator().getBytes());
|
||||
sb = new StringBuilder(
|
||||
"*[/^(source|mapwithai:source)$/][any(tag(\"source\"), tag(\"mapwithai:source\"))=\"")
|
||||
.append(source).append("\"]{set_color_programatic:setting(\"").append(simpleSource)
|
||||
.append("\");}");
|
||||
.append(source).append("\"]{set_color_programatic:setting(\"").append(simpleSource)
|
||||
.append("\");}");
|
||||
out.write(sb.toString().getBytes());
|
||||
}
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
|
|
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.stream.Collectors;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.Durations;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
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.gui.MainApplication;
|
||||
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.testutils.MapWithAITestRules;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.tools.MapPaintUtils;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
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");
|
||||
}
|
||||
|
||||
@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
|
||||
public void testMapWithAIURLPreferences() {
|
||||
final String fakeUrl = "https://fake.url";
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.openstreetmap.josm.tools.Logging;
|
|||
*/
|
||||
public class MapWithAIMenuTest {
|
||||
@RegisterExtension
|
||||
static JOSMTestRules rule = new MapWithAITestRules().wiremock().sources().projection().main();
|
||||
static JOSMTestRules rule = new MapWithAITestRules().wiremock().sources().territories().projection().main();
|
||||
private static MapWithAIMenu menu;
|
||||
|
||||
@BeforeAll
|
||||
|
|
|
@ -17,7 +17,9 @@ import java.util.stream.Collectors;
|
|||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.Durations;
|
||||
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.swing.ProgressMonitorExecutor;
|
||||
import org.openstreetmap.josm.io.OsmApi;
|
||||
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
||||
import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
||||
|
@ -52,6 +54,7 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
private String currentReleaseUrl;
|
||||
private Collection<String> sourceSites;
|
||||
private Runnable mapwithaiLayerInfoMocker;
|
||||
private boolean territories;
|
||||
|
||||
public MapWithAITestRules() {
|
||||
super();
|
||||
|
@ -79,9 +82,15 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapWithAITestRules territories() {
|
||||
this.territories = true;
|
||||
super.territories();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MapWithAITestRules wiremock() {
|
||||
this.wiremock = true;
|
||||
super.territories();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -157,6 +166,14 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
|
||||
@Override
|
||||
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();
|
||||
if (wiremock) {
|
||||
wireMock.stop();
|
||||
|
@ -182,12 +199,14 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
TestRunnerDecorator.cleanUpAllMocks();
|
||||
}
|
||||
|
||||
private static void resetMapWithAILayerInfo() {
|
||||
synchronized (MapWithAILayerInfo.class) {
|
||||
MapWithAILayerInfo.getInstance().clear();
|
||||
MapWithAILayerInfo.getInstance().getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry)
|
||||
.forEach(MapWithAILayerInfo.getInstance()::add);
|
||||
MapWithAILayerInfo.getInstance().save();
|
||||
private void resetMapWithAILayerInfo() {
|
||||
if (territories) {
|
||||
synchronized (MapWithAILayerInfo.class) {
|
||||
MapWithAILayerInfo.getInstance().clear();
|
||||
MapWithAILayerInfo.getInstance().getDefaultLayers().stream().filter(MapWithAIInfo::isDefaultEntry)
|
||||
.forEach(MapWithAILayerInfo.getInstance()::add);
|
||||
MapWithAILayerInfo.getInstance().save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,7 +250,8 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
|
||||
@Override
|
||||
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 newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/");
|
||||
return Response.Builder.like(response).but().body(newBody).build();
|
||||
|
|
Ładowanie…
Reference in New Issue