Porównaj commity

...

16 Commity
v823 ... master

Autor SHA1 Wiadomość Data
Dirk Stöcker f3659fc3ed fix JOSM repository access 2025-04-02 18:10:06 +02:00
Dirk Stöcker cdb1889864 drop deprecated isBlank usage 2025-04-02 17:44:19 +02:00
Taylor Smock 3bca38d512
Fix tests
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-11-11 08:27:09 -07:00
Taylor Smock 9b7d424f7b
Handle sources with . in name by replacing them with _
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-10-31 15:13:42 -06:00
Taylor Smock 551e26ef8e
Performance improvements
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-10-31 13:55:36 -06:00
Taylor Smock 87274baa62
Add overture data sources
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-10-31 12:07:05 -06:00
Taylor Smock 629e34f413
Fix #23971: Give a nicer error message when a server is down
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-10-21 07:28:26 -06:00
Taylor Smock 817b633660
Significantly improve performance for StreetAddressTest
This is mostly done by reducing the amount of garbage collection that
needs to occur.

Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-10-15 13:26:16 -06:00
Taylor Smock 5d9df1fba4
Update wiremock tests
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-10-15 13:13:39 -06:00
Taylor Smock cecb9f40be
Fix UI freeze during download of Esri layers
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-04-15 15:06:52 -06:00
Taylor Smock 7f725f7e4c
Update gradle build dependencies
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-03-12 08:00:47 -06:00
Taylor Smock f7c1d3d8b0
Fix #23529: JSON downloads may wait on EDT while EDT is waiting on downloads to finish
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-03-12 06:46:53 -06:00
Taylor Smock fbd3f10541
Use v2 JOSMPluginAction scripts
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-01-17 06:41:52 -07:00
Taylor Smock faa031e49c
Fix issue where the sources would not be updated
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-01-17 06:24:08 -07:00
Taylor Smock ca0b8e479f
Fix an issue where a custom source would have "&" for the first query parameter instead of "?"
Signed-off-by: Taylor Smock <tsmock@meta.com>
2024-01-17 06:24:08 -07:00
Taylor Smock ad6ec16acd
Don't download sources multiple times when user asks for refresh multiple times in different locations
Signed-off-by: Taylor Smock <smocktaylor@gmail.com>
2024-01-05 06:37:47 -07:00
97 zmienionych plików z 1337 dodań i 316 usunięć

Wyświetl plik

@ -10,20 +10,18 @@ on:
branches:
- master
- $default-branch
schedule:
- cron: "1 5 * * 6"
workflow_dispatch:
jobs:
call-workflow:
strategy:
matrix:
josm-revision: ["", "r18877"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
josm-revision: ["", "r19067"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v3
with:
java-version: 17
josm-revision: ${{ matrix.josm-revision }}
plugin-jar-name: 'mapwithai'
perform-revision-tagging: ${{ matrix.josm-revision == 'r18877' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
perform-revision-tagging: ${{ matrix.josm-revision == 'r19067' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
secrets: inherit

Wyświetl plik

@ -10,4 +10,4 @@ permissions:
jobs:
call-workflow:
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v1
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v3

Wyświetl plik

@ -1,9 +1,9 @@
import groovy.xml.XmlParser
plugins {
id "com.diffplug.spotless" version "6.20.0"
id "com.github.ben-manes.versions" version "0.47.0"
id "com.github.spotbugs" version "5.0.14"
id "com.diffplug.spotless" version "6.25.0"
id "com.github.ben-manes.versions" version "0.51.0"
id "com.github.spotbugs" version "6.0.8"
// id "de.aaschmid.cpd" version "3.3"
id "eclipse"
id "jacoco"
@ -12,7 +12,7 @@ plugins {
id "maven-publish"
id "net.ltgt.errorprone" version "3.1.0"
id "org.openstreetmap.josm" version "0.8.2"
id "org.sonarqube" version "4.2.1.3168"
id "org.sonarqube" version "4.4.1.3373"
id "pmd"
}
@ -29,15 +29,15 @@ repositories {
def versions = [
awaitility: "4.2.0",
equalsverifier: "3.15",
errorprone: "2.20.0",
findsecbugs: "1.12.0",
equalsverifier: "3.15.8",
errorprone: "2.26.0",
findsecbugs: "1.13.0",
jacoco: "0.8.10",
jmockit: "1.49.a",
josm: properties.get("plugin.compile.version"),
junit: "5.9.1",
junit: "5.10.2",
pmd: "6.20.0",
spotbugs: "4.7.3",
spotbugs: "4.8.3",
wiremock: "2.35.0",
]

Wyświetl plik

@ -1,9 +1,9 @@
# The minimum JOSM version this plugin is compatible with (can be any numeric version
plugin.main.version = 18877
plugin.main.version = 19067
# The JOSM version this plugin is currently compiled against
# Please make sure this version is available at https://josm.openstreetmap.de/download
# The special values "latest" and "tested" are also possible here, but not recommended.
plugin.compile.version = 18877
plugin.compile.version = 19067
plugin.canloadatruntime = true
plugin.author = Taylor Smock
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=03ec176d388f2aa99defcadc3ac6adf8dd2bce5145a129659537c0874dea5ad1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionSha256Sum=9631d53cf3e74bfa726893aee1f8994fee4e060c401335946dba2156f440f24c
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

16
gradlew vendored
Wyświetl plik

@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@ -133,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
@ -144,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -152,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in

193
pom.xml 100644
Wyświetl plik

@ -0,0 +1,193 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openstreetmap.josm.plugins</groupId>
<artifactId>MapWithAI</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jmockit.version>1.49.a</jmockit.version>
<pmd.version>7.5.0</pmd.version>
<jacoco.version>0.8.12</jacoco.version>
<checkstyle.version>10.18.1</checkstyle.version>
<spotbugs.version>4.8.6</spotbugs.version>
</properties>
<repositories>
<repository>
<id>JOSM-releases</id>
<url>https://josm.openstreetmap.de/repository/releases/</url>
</repository>
<repository>
<id>JOSM-snapshots</id>
<url>https://josm.openstreetmap.de/repository/snapshots/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.openstreetmap.josm</groupId>
<artifactId>josm</artifactId>
<version>1.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openstreetmap.josm.plugins</groupId>
<artifactId>pmtiles</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openstreetmap.josm.plugins</groupId>
<artifactId>utilsplugin2</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openstreetmap.josm</groupId>
<artifactId>josm-unittest</artifactId>
<version>1.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency> <!-- needed until JOSM core removes Junit4 support -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.49.a</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/unit</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<java>
<eclipse>
<version>4.21</version>
<file>${project.basedir}/../00_core_tools/eclipse/formatter.xml</file>
</eclipse>
<removeUnusedImports/>
<licenseHeader>
<content>// License: GPL. For details, see LICENSE file.</content>
</licenseHeader>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/unit/**/*.java</include>
<include>src/test/integration/**/*.java</include>
</includes>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.3</version>
</requireMavenVersion>
</rules>
</configuration>
</plugin>
<!-- Configure the test plugin, specifically enable autodetection of global extensions -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
<argLine>-javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
<properties>
<configurationParameters>
file.encoding = UTF-8
java.locale.providers = SPI,CLDR
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.execution.parallel.enabled = true
</configurationParameters>
</properties>
<systemPropertyVariables>
<josm.home>src/test/build/config/josm.home</josm.home>
<josm.test.data>src/test/resources</josm.test.data>
<java.awt.headless>true</java.awt.headless>
<glass.platform>Monocle</glass.platform>
<monocle.platform>Headless</monocle.platform>
<prism.order>sw</prism.order>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>

Wyświetl plik

@ -84,10 +84,17 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi
@Override
public void actionPerformed(ActionEvent e) {
if (!isEnabled()) {
return;
if (isEnabled()) {
MainApplication.worker.execute(() -> realRun(this.info));
}
}
/**
* Run the download tasks. This should be run off of the EDT, see #23529.
*
* @param info The external data to download
*/
private static void realRun(MapWithAIInfo info) {
MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
final DataSet ds;
final OsmData<?, ?, ?, ?> boundsSource;

Wyświetl plik

@ -23,6 +23,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -73,6 +74,7 @@ import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.HttpClient;
import org.openstreetmap.josm.tools.JosmRuntimeException;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils;
import jakarta.json.Json;
import jakarta.json.JsonValue;
@ -130,14 +132,20 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
final var tile = TileXYZ.tileFromBBox(lon1, lat1, lon2, lat2);
return getRequestForTile(tile);
}
return url.replace("{bbox}", Double.toString(lon1) + ',' + lat1 + ',' + lon2 + ',' + lat2)
var current = url.replace("{bbox}", Double.toString(lon1) + ',' + lat1 + ',' + lon2 + ',' + lat2)
.replace("{xmin}", Double.toString(lon1)).replace("{ymin}", Double.toString(lat1))
.replace("{xmax}", Double.toString(lon2)).replace("{ymax}", Double.toString(lat2))
+ (crop ? "&crop_bbox=" + DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox().toStringCSV(",")
: "")
+ (this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER && !this.info.isConflated()
? "&resultOffset=" + this.start
: "");
.replace("{xmax}", Double.toString(lon2)).replace("{ymax}", Double.toString(lat2));
boolean hasQuery = !Optional.ofNullable(URI.create(current).getRawQuery()).map(String::isEmpty).orElse(true);
if (crop) {
current += (hasQuery ? '&' : '?') + "crop_bbox="
+ DetectTaskingManagerUtils.getTaskingManagerBounds().toBBox().toStringCSV(",");
hasQuery = true;
}
if (this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER && !this.info.isConflated()) {
current += (hasQuery ? '&' : '?') + "resultOffset=" + this.start;
}
return current;
}
private String getRequestForTile(TileXYZ tile) {
@ -361,30 +369,33 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
}
final var ds = new DataSet();
final var primitiveMap = new HashMap<PrimitiveId, OsmPrimitive>(tile.getData().getAllPrimitives().size());
for (VectorPrimitive p : tile.getData().getAllPrimitives()) {
final OsmPrimitive osmPrimitive;
if (p instanceof VectorNode node) {
osmPrimitive = new Node(node.getCoor());
osmPrimitive.putAll(node.getKeys());
} else if (p instanceof VectorWay way) {
final var tWay = new Way();
for (VectorNode node : way.getNodes()) {
tWay.addNode((Node) primitiveMap.get(node));
for (Class<? extends VectorPrimitive> clazz : Arrays.asList(VectorNode.class, VectorWay.class,
VectorRelation.class)) {
for (VectorPrimitive p : Utils.filteredCollection(tile.getData().getAllPrimitives(), clazz)) {
final OsmPrimitive osmPrimitive;
if (p instanceof VectorNode node) {
osmPrimitive = new Node(node.getCoor());
osmPrimitive.putAll(node.getKeys());
} else if (p instanceof VectorWay way) {
final var tWay = new Way();
for (VectorNode node : way.getNodes()) {
tWay.addNode((Node) primitiveMap.get(node));
}
tWay.putAll(way.getKeys());
osmPrimitive = tWay;
} else if (p instanceof VectorRelation vectorRelation) {
final var tRelation = new Relation();
for (VectorRelationMember member : vectorRelation.getMembers()) {
tRelation.addMember(new RelationMember(member.getRole(), primitiveMap.get(member.getMember())));
}
tRelation.putAll(vectorRelation.getKeys());
osmPrimitive = tRelation;
} else {
throw new IllegalDataException("Unknown vector data type: " + p);
}
tWay.putAll(way.getKeys());
osmPrimitive = tWay;
} else if (p instanceof VectorRelation vectorRelation) {
final var tRelation = new Relation();
for (VectorRelationMember member : vectorRelation.getMembers()) {
tRelation.addMember(new RelationMember(member.getRole(), primitiveMap.get(member.getMember())));
}
tRelation.putAll(vectorRelation.getKeys());
osmPrimitive = tRelation;
} else {
throw new IllegalDataException("Unknown vector data type: " + p);
ds.addPrimitive(osmPrimitive);
primitiveMap.put(p, osmPrimitive);
}
ds.addPrimitive(osmPrimitive);
primitiveMap.put(p, osmPrimitive);
}
return ds;
}

Wyświetl plik

@ -68,7 +68,7 @@ public class DataConflationSender implements RunnableFuture<DataSet> {
@Override
public void run() {
String url = MapWithAIConflationCategory.conflationUrlFor(category);
if (!Utils.isBlank(url) && !NetworkManager.isOffline(url)) {
if (!Utils.isStripEmpty(url) && !NetworkManager.isOffline(url)) {
this.client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
try {
final var form = new TreeMap<String, String>();

Wyświetl plik

@ -403,7 +403,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
.map(entry -> new Pair<>(Tag.ofString(entry.getKey()), Tag.ofString(entry.getValue())))
.collect(Collectors.toMap(pair -> pair.a, pair -> pair.b));
MapWithAIPreferenceHelper.getReplacementTags().entrySet().stream()
.filter(entry -> !entry.getKey().equals(EQUALS) && Utils.isBlank(entry.getValue()))
.filter(entry -> !entry.getKey().equals(EQUALS) && Utils.isStripEmpty(entry.getValue()))
.map(entry -> new Tag(entry.getKey(), null)).forEach(tag -> replaceTags.put(tag, tag));
replaceTags(dataSet, replaceTags);
}
@ -417,7 +417,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
public static void replaceTags(DataSet dataSet, Map<Tag, Tag> replaceTags) {
replaceTags.forEach((orig, replace) -> dataSet.allNonDeletedPrimitives().stream()
.filter(prim -> prim.hasTag(orig.getKey(), orig.getValue())
|| (prim.hasKey(orig.getKey()) && Utils.isBlank(orig.getValue())))
|| (prim.hasKey(orig.getKey()) && Utils.isStripEmpty(orig.getValue())))
.forEach(prim -> prim.put(replace)));
}

Wyświetl plik

@ -18,6 +18,7 @@ import java.util.Optional;
import java.util.TreeSet;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import org.openstreetmap.josm.data.Bounds;
@ -127,7 +128,7 @@ public final class MapWithAIDataUtils {
realBounds.size() * urls.size());
for (var bound : realBounds) {
for (var url : urls) {
if (url.getUrl() != null && !Utils.isBlank(url.getUrl())) {
if (url.getUrl() != null && !Utils.isStripEmpty(url.getUrl())) {
final var ds = download(monitor, bound, url, maximumDimensions);
downloadedDataSets.add(ds);
MapWithAIDataUtils.getForkJoinPool().execute(ds);
@ -197,9 +198,14 @@ public final class MapWithAIDataUtils {
original.mergeFrom(ds.join());
} catch (RuntimeException e) {
final String notificationMessage;
final var cause = e.getCause();
if (cause instanceof IllegalDataException illegalDataException) {
notificationMessage = ExceptionUtil.explainException(illegalDataException);
Throwable cause = e.getCause();
if (cause != null) {
while (cause.getCause() != null && RuntimeException.class.equals(cause.getClass())) {
cause = cause.getCause();
}
}
if (cause instanceof IllegalDataException) {
notificationMessage = ExceptionUtil.explainException((Exception) cause);
Logging.trace(e);
final var notification = new Notification();
GuiHelper.runInEDT(() -> notification.setContent(notificationMessage));
@ -213,37 +219,26 @@ public final class MapWithAIDataUtils {
}
}
private static boolean confirmBigDownload(List<Bounds> realBounds) {
final var confirmation = new ConfirmBigDownload(realBounds);
GuiHelper.runInEDTAndWait(confirmation);
return confirmation.confirmed();
}
private static class ConfirmBigDownload implements Runnable {
Boolean bool;
final List<?> realBounds;
public ConfirmBigDownload(List<?> realBounds) {
this.realBounds = realBounds;
}
@Override
public void run() {
bool = ConditionalOptionPaneUtil.showConfirmationDialog(MapWithAIPlugin.NAME.concat(".alwaysdownload"),
null,
/**
* Confirm a large download
*
* @param realBounds The list of bounds that will be downloaded
* @return {@code true} if the user still wants to download data
*/
private static synchronized boolean confirmBigDownload(List<Bounds> realBounds) {
final var confirmation = new AtomicBoolean(false);
// This is not a separate class since we don't want to show multiple
// confirmation dialogs
// which is why this method is synchronized.
GuiHelper.runInEDTAndWait(() -> {
final var confirmed = ConditionalOptionPaneUtil.showConfirmationDialog(
MapWithAIPlugin.NAME.concat(".alwaysdownload"), null,
tr("You are going to make {0} requests to the MapWithAI server. This may take some time. <br /> Continue?",
realBounds.size()),
null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION);
}
/**
* Check if the user confirmed the download
*
* @return {@code true} if the user wants to continue
*/
public boolean confirmed() {
return bool;
}
confirmation.set(confirmed);
});
return confirmation.get();
}
/**

Wyświetl plik

@ -41,6 +41,7 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.ESRISourceReader;
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.MapWithAISourceReader;
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.OvertureSourceReader;
import org.openstreetmap.josm.plugins.mapwithai.spi.preferences.MapWithAIConfig;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.ListenerList;
@ -213,9 +214,13 @@ public class MapWithAILayerInfo {
if (this.finishListenerListenerList == null) {
this.finishListenerListenerList = ListenerList.create();
}
boolean running = this.finishListenerListenerList.hasListeners();
if (listener != null) {
this.finishListenerListenerList.addListener(listener);
}
if (running) {
return;
}
if (worker == null) {
final var pleaseWaitRunnable = new PleaseWaitRunnable(tr("Update default entries")) {
@Override
@ -329,6 +334,7 @@ public class MapWithAILayerInfo {
// This is called here to "pre-cache" the layer information, to avoid blocking
// the EDT
this.updateEsriLayers(result);
this.updateOvertureLayers(result);
newLayers.addAll(result);
} catch (IOException ex) {
loadError = true;
@ -342,11 +348,12 @@ public class MapWithAILayerInfo {
* @param layers The layers to update
*/
private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
final var esriInfo = new ArrayList<MapWithAIInfo>(300);
for (var layer : layers) {
if (MapWithAIType.ESRI == layer.getSourceType()) {
for (var future : parseEsri(layer)) {
try {
allDefaultLayers.add(future.get());
esriInfo.add(future.get());
} catch (InterruptedException e) {
Logging.error(e);
Thread.currentThread().interrupt();
@ -354,10 +361,27 @@ public class MapWithAILayerInfo {
Logging.error(e);
}
}
} else {
allDefaultLayers.add(layer);
}
}
layers.addAll(esriInfo);
}
/**
* Update the overture layers
* @param layers The layers to iterate through and modify
* @throws IOException If something happens while parsing overture layers
*/
private void updateOvertureLayers(@Nonnull final Collection<MapWithAIInfo> layers) throws IOException {
final var overtureLayers = new ArrayList<MapWithAIInfo>(4);
for (var layer : layers) {
if (MapWithAIType.OVERTURE == layer.getSourceType()) {
try (var reader = new OvertureSourceReader(layer)) {
reader.parse().ifPresent(overtureLayers::addAll);
}
}
}
layers.removeIf(layer -> MapWithAIType.OVERTURE == layer.getSourceType());
layers.addAll(overtureLayers);
}
protected void finish() {
@ -365,7 +389,7 @@ public class MapWithAILayerInfo {
synchronized (allDefaultLayers) {
allDefaultLayers.clear();
defaultLayers.addAll(newLayers);
this.updateEsriLayers(newLayers);
allDefaultLayers.addAll(newLayers);
allDefaultLayers.sort(new MapWithAIInfo.MapWithAIInfoCategoryComparator());
allDefaultLayers.sort(Comparator.comparing(TileSourceInfo::getName));
allDefaultLayers.sort(Comparator.comparing(info -> info.getCategory().getDescription()));
@ -501,7 +525,7 @@ public class MapWithAILayerInfo {
}
if (changed) {
save();
MainApplication.worker.execute(this::save);
}
}

Wyświetl plik

@ -12,7 +12,7 @@ import jakarta.annotation.Nonnull;
*/
public enum MapWithAIType implements ISourceType<MapWithAIType> {
FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER(
"esriFeatureServer"), MAPBOX_VECTOR_TILE("mvt"), PMTILES("pmtiles");
"esriFeatureServer"), MAPBOX_VECTOR_TILE("mvt"), PMTILES("pmtiles"), OVERTURE("overture");
private final String typeString;

Wyświetl plik

@ -44,8 +44,8 @@ public class StreetAddressTest extends Test {
public static final double BBOX_EXPANSION = 0.002;
private static final String ADDR_STREET = "addr:street";
private final Set<OsmPrimitive> namePrimitiveMap = new HashSet<>();
private final Map<Point2D, Set<String>> nameMap = new HashMap<>();
private final Map<Point2D, List<OsmPrimitive>> primitiveCellMap = new HashMap<>();
private final Map<Point, Set<String>> nameMap = new HashMap<>();
private final Map<Point, List<OsmPrimitive>> primitiveCellMap = new HashMap<>();
/**
* Classified highways. This uses a {@link Set} instead of a {@link List} since
* the MapWithAI code doesn't care about order.
@ -146,7 +146,8 @@ public class StreetAddressTest extends Test {
final var n1 = nodes.get(i);
final var n2 = nodes.get(i + 1);
for (Point2D cell : ValUtil.getSegmentCells(n1, n2, gridDetail)) {
this.nameMap.computeIfAbsent(cell, k -> new HashSet<>()).addAll(names);
this.nameMap.computeIfAbsent(new Point(cell.getX(), cell.getY()), k -> new HashSet<>())
.addAll(names);
}
}
} else if (hasStreetAddressTags(primitive) && !primitive.isOutsideDownloadArea()) {
@ -159,7 +160,7 @@ public class StreetAddressTest extends Test {
if (en != null) {
long x = (long) Math.floor(en.getX() * gridDetail);
long y = (long) Math.floor(en.getY() * gridDetail);
final var point = new Point2D.Double(x, y);
final var point = new Point(x, y);
primitiveCellMap.computeIfAbsent(point, p -> new ArrayList<>()).add(primitive);
}
}
@ -174,7 +175,7 @@ public class StreetAddressTest extends Test {
.filter(s -> !s.isEmpty()).collect(Collectors.toSet());
}
private Collection<String> getSurroundingHighwayNames(Point2D point2D) {
private Collection<String> getSurroundingHighwayNames(Point point2D) {
if (this.nameMap.isEmpty()) {
return Collections.emptySet();
}
@ -183,8 +184,9 @@ public class StreetAddressTest extends Test {
while (surroundingWays.isEmpty()) {
for (int x = -surrounding; x <= surrounding; x++) {
for (int y = -surrounding; y <= surrounding; y++) {
final var key = new Point2D.Double((long) Math.floor(point2D.getX() + x),
(long) Math.floor(point2D.getY() + y));
final var xPoint = (long) Math.floor(point2D.x() + x);
final var yPoint = (long) Math.floor(point2D.y() + y);
final var key = new Point(xPoint, yPoint);
if (this.nameMap.containsKey(key)) {
surroundingWays.addAll(this.nameMap.get(key));
}
@ -303,4 +305,20 @@ public class StreetAddressTest extends Test {
bbox.add(bbox.getTopLeftLon() - degree, bbox.getTopLeftLat() + degree);
return bbox;
}
}
private record Point(double x, double y) implements Comparable<Point> {
@Override
public int compareTo(Point other) {
if (other.x == this.x && other.y == this.y) {
return 0;
}
if (other.x < this.x) {
return -1;
}
if (other.x > this.x) {
return 1;
}
return Double.compare(other.y, this.y);
}
}}

Wyświetl plik

@ -51,6 +51,7 @@ class MapWithAIDefaultLayerTableModel extends DefaultTableModel {
columnDataRetrieval.add(info -> Optional.ofNullable(info.getTermsOfUseURL()).orElse(""));
columnDataRetrieval.add(i -> MapWithAILayerInfo.getInstance().getLayers().contains(i));
MapWithAILayerInfo.getInstance().addFinishListener(() -> GuiHelper.runInEDT(this::fireTableDataChanged));
MapWithAILayerInfo.SHOW_PREVIEW.addWeakListener(l -> GuiHelper.runInEDT(this::fireTableDataChanged));
}
/**
@ -60,10 +61,11 @@ class MapWithAIDefaultLayerTableModel extends DefaultTableModel {
* @return The imagery info at the given row number
*/
public static MapWithAIInfo getRow(int row) {
if (row == 0 && MapWithAILayerInfo.getInstance().getAllDefaultLayers().isEmpty()) {
final var layers = MapWithAILayerInfo.getInstance().getAllDefaultLayers();
if (row == 0 && layers.isEmpty()) {
return new MapWithAIInfo(tr("Loading"), "");
}
return MapWithAILayerInfo.getInstance().getAllDefaultLayers().get(row);
return layers.get(row);
}
@Override

Wyświetl plik

@ -6,13 +6,12 @@ import java.util.Optional;
import org.openstreetmap.josm.io.CachedFile;
import org.openstreetmap.josm.tools.HttpClient;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.JsonStructure;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParsingException;
/**
* Read sources for MapWithAI
@ -42,24 +41,26 @@ public abstract class CommonSourceReader<T> implements AutoCloseable {
this.cachedFile = new CachedFile(this.source);
}
this.cachedFile.setFastFail(this.fastFail);
try (JsonReader reader = Json.createReader(cachedFile.setMaxAge(CachedFile.DAYS)
try (JsonParser reader = Json.createParser(cachedFile.setMaxAge(CachedFile.DAYS)
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
JsonStructure struct = reader.read();
if (JsonValue.ValueType.OBJECT == struct.getValueType()) {
final var jsonObject = struct.asJsonObject();
return Optional.ofNullable(this.parseJson(jsonObject));
while (reader.hasNext()) {
if (reader.hasNext() && reader.next() == JsonParser.Event.START_OBJECT) {
return Optional.ofNullable(this.parseJson(reader));
}
}
return Optional.empty();
} catch (JsonParsingException jsonParsingException) {
Logging.error(jsonParsingException);
}
return Optional.empty();
}
/**
* Parses MapWithAI entry sources
*
* @param jsonObject The json of the data sources
* @param parser The json of the data sources. This will be in the {@link JsonParser.Event#START_OBJECT} state.
* @return The parsed entries
*/
public abstract T parseJson(JsonObject jsonObject);
public abstract T parseJson(JsonParser parser);
/**
* Sets whether opening HTTP connections should fail fast, i.e., whether a

Wyświetl plik

@ -10,9 +10,9 @@ import java.util.stream.Collectors;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
import org.openstreetmap.josm.tools.Pair;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
/**
* Read conflation entries from JSON
@ -44,12 +44,12 @@ public class ConflationSourceReader extends CommonSourceReader<Map<MapWithAICate
/**
* Parses MapWithAI entry sources
*
* @param jsonObject The json of the data sources
* @param parser The json of the data sources
* @return The parsed entries
*/
@Override
public Map<MapWithAICategory, List<String>> parseJson(JsonObject jsonObject) {
return jsonObject.entrySet().stream().flatMap(i -> parse(i).stream())
public Map<MapWithAICategory, List<String>> parseJson(JsonParser parser) {
return parser.getObjectStream().flatMap(i -> parse(i).stream())
.collect(Collectors.groupingBy(p -> p.a, Collectors.mapping(p -> p.b, Collectors.toList())));
}

Wyświetl plik

@ -164,7 +164,7 @@ public class ESRISourceReader {
newInfo.setName(feature.getString("title", feature.getString("name")));
final var extent = feature.getJsonArray("extent").getValuesAs(JsonArray.class).stream()
.flatMap(array -> array.getValuesAs(JsonNumber.class).stream()).map(JsonNumber::doubleValue)
.map(Object::toString).toArray(String[]::new);
.map(d -> Double.toString(d)).toArray(String[]::new);
final var imageryBounds = new ImageryBounds(String.join(",", extent[1], extent[0], extent[3], extent[2]), ",");
newInfo.setBounds(imageryBounds);
newInfo.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);

Wyświetl plik

@ -17,9 +17,9 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.tools.Territories;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
/**
* Reader to parse the list of available MapWithAI servers from an JSON
@ -54,12 +54,12 @@ public class MapWithAISourceReader extends CommonSourceReader<List<MapWithAIInfo
/**
* Parses MapWithAI entry sources
*
* @param jsonObject The json of the data sources
* @param parser The json of the data sources
* @return The parsed entries
*/
@Override
public List<MapWithAIInfo> parseJson(JsonObject jsonObject) {
return jsonObject.entrySet().stream().map(MapWithAISourceReader::parse).collect(Collectors.toList());
public List<MapWithAIInfo> parseJson(JsonParser parser) {
return parser.getObjectStream().map(MapWithAISourceReader::parse).collect(Collectors.toList());
}
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {

Wyświetl plik

@ -0,0 +1,146 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.imagery.ImageryInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.plugins.pmtiles.lib.PMTiles;
import org.openstreetmap.josm.tools.Logging;
import jakarta.annotation.Nullable;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
/**
* Read data from overture sources
*/
public class OvertureSourceReader extends CommonSourceReader<List<MapWithAIInfo>> implements Closeable {
private final MapWithAIInfo source;
public OvertureSourceReader(MapWithAIInfo source) {
super(source.getUrl());
this.source = source;
}
@Override
public List<MapWithAIInfo> parseJson(JsonParser jsonParser) {
final var jsonObject = jsonParser.getObject();
if (jsonObject.containsKey("releases")) {
return parseRoot(jsonObject);
}
return Collections.emptyList();
}
private List<MapWithAIInfo> parseRoot(JsonObject jsonObject) {
final var info = new ArrayList<MapWithAIInfo>(6 * 4);
final var releases = jsonObject.get("releases");
final var baseUri = URI.create(this.source.getUrl()).resolve("./"); // safe since we created an URI from the source to get to this point
if (releases instanceof JsonArray rArray) {
rArray.parallelStream().flatMap(value -> parseReleases(baseUri, value)).filter(Objects::nonNull)
.forEachOrdered(info::add);
}
info.trimToSize();
return info;
}
private Stream<MapWithAIInfo> parseReleases(URI baseUri, JsonValue value) {
if (value instanceof JsonObject release && release.containsKey("release_id") && release.containsKey("files")) {
final var id = release.get("release_id");
final var files = release.get("files");
if (id instanceof JsonString sId && files instanceof JsonArray fArray) {
final String releaseId = sId.getString();
return fArray.parallelStream().map(file -> parseFile(baseUri, releaseId, file));
}
}
return Stream.empty();
}
/**
* Parse the individual file from the files array
* @param baseUri The base URI (if the href is relative)
* @param releaseId The release id to differentiate it from other releases with the same theme
* @param file The file object
* @return The info, if it was parsed. Otherwise {@code null}.
*/
@Nullable
private MapWithAIInfo parseFile(URI baseUri, String releaseId, JsonValue file) {
if (file instanceof JsonObject fObj && fObj.containsKey("theme") && fObj.containsKey("href")) {
final JsonValue vTheme = fObj.get("theme");
final JsonValue vHref = fObj.get("href");
try {
if (vTheme instanceof JsonString sTheme && vHref instanceof JsonString href) {
final var theme = sTheme.getString();
final URI uri;
if (href.getString().startsWith("./") || href.getString().startsWith("../")) {
uri = baseUri.resolve(href.getString());
} else {
uri = new URI(href.getString());
}
return buildSource(uri, releaseId, theme);
}
} catch (URISyntaxException uriSyntaxException) {
Logging.debug(uriSyntaxException);
}
}
return null;
}
private MapWithAIInfo buildSource(URI uri, String releaseId, String theme) {
final var info = new MapWithAIInfo(this.source);
info.setUrl(uri.toString());
info.setName(this.source.getName() + ": " + theme + " - " + releaseId);
if ("addresses".equals(theme)) {
info.setCategory(MapWithAICategory.ADDRESS);
} else if ("buildings".equals(theme)) {
info.setCategory(MapWithAICategory.BUILDING);
} else {
info.setCategory(MapWithAICategory.OTHER);
}
// Addresses and places are "interesting". Only removing "transportation" since that currently causes crashes.
if ("transportation".equals(theme)) {
return null;
}
final var categories = EnumSet.of(this.source.getCategory(),
this.source.getAdditionalCategories().toArray(MapWithAICategory[]::new));
categories.removeIf(MapWithAICategory.OTHER::equals);
info.setAdditionalCategories(new ArrayList<>(categories));
info.setId(info.getName());
if (uri.getPath().endsWith(".pmtiles")) {
info.setSourceType(MapWithAIType.PMTILES);
// Set additional information
try {
final var header = PMTiles.readHeader(uri);
final var metadata = PMTiles.readMetadata(header);
final var bounds = new Bounds(header.minLatitude(), header.minLongitude(), header.maxLatitude(),
header.maxLongitude());
info.setBounds(new ImageryInfo.ImageryBounds(bounds.encodeAsString(","), ","));
if (metadata.containsKey("name") && metadata.get("name")instanceof JsonString name) {
info.setName(name.getString() + " - " + releaseId);
}
if (metadata.containsKey("description")
&& metadata.get("description")instanceof JsonString description) {
info.setDescription(description.getString());
}
} catch (IOException ioException) {
Logging.error(ioException);
}
}
return info;
}
}

Wyświetl plik

@ -160,7 +160,7 @@ public final class MapPaintUtils {
return;
}
List<String> sources = ds.allPrimitives().stream().map(MapPaintUtils::getSourceValue).filter(Objects::nonNull)
.distinct().collect(Collectors.toList());
.map(s -> s.replace('.', '_')).distinct().collect(Collectors.toList());
if (!styleSource.isLoaded()) {
styleSource.loadStyleSource();
}

1
src/test/data 120000
Wyświetl plik

@ -0,0 +1 @@
resources

Wyświetl plik

@ -7,7 +7,20 @@
},
"response" : {
"status" : 200,
"body" : "{\n \"Taylor's Address Conflation Server\" : {\n \"categories\" : [\n \"addresses\"\n ],\n \"description\" : \"Originally developed for use with local datasets, it now accepts external datasets for conflation purposes. In the event of a failure, the plugin will use the original dataset.\",\n \"license\" : \"AGPL\",\n \"source\" : \"https://gitlab.com/smocktaylor/serve_osm_files/\",\n \"url\" : \"https://importdata.riverviewtechnologies.com/conflate\"\n }\n}\n",
"jsonBody": {
"Taylor's Address Conflation Server": {
"categories": [
"addresses"
],
"description": "Originally developed for use with local datasets, it now accepts external datasets for conflation purposes. In the event of a failure, the plugin will use the original dataset.",
"license": "AGPL",
"source": "{{ request.baseUrl }}/smocktaylor/serve_osm_files/",
"url": "{{ request.baseUrl }}/conflate"
}
},
"transformers": [
"response-template"
],
"headers" : {
"Accept-Ranges" : "bytes",
"Cache-Control" : "max-age=600",

Wyświetl plik

@ -0,0 +1,641 @@
{
"id" : "23497750-675c-440a-986a-34dd14b047f8",
"name" : "josm_mapwithai_json_sourcesjson",
"request" : {
"urlPattern" : "\/MapWithAI\/?json\/sources.json",
"method" : "GET"
},
"response" : {
"status" : 200,
"jsonBody": {
"Statewide Aggregate Addresses in Colorado 2019 (Public)": {
"countries": {
"US-CO": [
"addr:housenumber"
]
},
"license": "Public Domain",
"osm_compatible": "yes",
"parameters": [],
"permission_url": "{{ request.baseUrl }}/wiki/Import/Colorado_Addresses",
"url": "{{ request.baseUrl }}/coloradoAddresses/map?bbox={bbox}"
},
"MapWithAI": {
"countries": {
"AE": [
"highway"
],
"AF": [
"highway"
],
"AG": [
"highway"
],
"AI": [
"highway"
],
"AL": [
"highway"
],
"AM": [
"highway"
],
"AO": [
"highway"
],
"AR": [
"highway"
],
"AT": [
"highway"
],
"AU": [
"highway"
],
"AZ": [
"highway"
],
"BA": [
"highway"
],
"BB": [
"highway"
],
"BD": [
"highway"
],
"BE": [
"highway"
],
"BF": [
"highway"
],
"BG": [
"highway"
],
"BI": [
"highway"
],
"BJ": [
"highway"
],
"BL": [
"highway"
],
"BN": [
"highway"
],
"BO": [
"highway"
],
"BR": [
"highway"
],
"BS": [
"highway"
],
"BT": [
"highway"
],
"BW": [
"highway"
],
"BY": [
"highway"
],
"BZ": [
"highway"
],
"CA": [
"building",
"highway"
],
"CD": [
"highway"
],
"CF": [
"highway"
],
"CG": [
"highway"
],
"CH": [
"highway"
],
"CI": [
"highway"
],
"CL": [
"highway"
],
"CM": [
"highway"
],
"CN": [
"highway"
],
"CO": [
"highway"
],
"CR": [
"highway"
],
"CU": [
"highway"
],
"CY": [
"highway"
],
"CZ": [
"highway"
],
"DE": [
"highway"
],
"DJ": [
"highway"
],
"DK": [
"highway"
],
"DM": [
"highway"
],
"DO": [
"highway"
],
"DZ": [
"highway"
],
"EC": [
"highway"
],
"EE": [
"highway"
],
"EG": [
"highway"
],
"EH": [
"highway"
],
"ER": [
"highway"
],
"ES": [
"highway"
],
"ET": [
"highway"
],
"FK": [
"highway"
],
"FI": [
"highway"
],
"FJ": [
"highway"
],
"FR": [
"highway"
],
"GA": [
"highway"
],
"GB": [
"highway"
],
"GD": [
"highway"
],
"GE": [
"highway"
],
"GF": [
"highway"
],
"GH": [
"highway"
],
"GM": [
"highway"
],
"GN": [
"highway"
],
"GP": [
"highway"
],
"GQ": [
"highway"
],
"GR": [
"highway"
],
"GT": [
"highway"
],
"GW": [
"highway"
],
"GY": [
"highway"
],
"HN": [
"highway"
],
"HR": [
"highway"
],
"HT": [
"highway"
],
"HU": [
"highway"
],
"ID": [
"highway"
],
"IE": [
"highway"
],
"IL": [
"highway"
],
"IN": [
"highway"
],
"IQ": [
"highway"
],
"IS": [
"highway"
],
"IT": [
"highway"
],
"JM": [
"highway"
],
"JO": [
"highway"
],
"JP": [
"highway"
],
"KE": [
"highway"
],
"KG": [
"highway"
],
"KH": [
"highway"
],
"KN": [
"highway"
],
"KY": [
"highway"
],
"KR": [
"highway"
],
"KW": [
"highway"
],
"KZ": [
"highway"
],
"LA": [
"highway"
],
"LB": [
"highway"
],
"LC": [
"highway"
],
"LK": [
"highway"
],
"LR": [
"highway"
],
"LS": [
"highway"
],
"LT": [
"highway"
],
"LU": [
"highway"
],
"LV": [
"highway"
],
"LY": [
"highway"
],
"MA": [
"highway"
],
"MD": [
"highway"
],
"ME": [
"highway"
],
"MF": [
"highway"
],
"MG": [
"highway"
],
"MK": [
"highway"
],
"ML": [
"highway"
],
"MM": [
"highway"
],
"MN": [
"highway"
],
"MQ": [
"highway"
],
"MR": [
"highway"
],
"MS": [
"highway"
],
"MW": [
"highway"
],
"MX": [
"highway"
],
"MY": [
"highway"
],
"MZ": [
"highway"
],
"NA": [
"highway"
],
"NE": [
"highway"
],
"NG": [
"highway"
],
"NI": [
"highway"
],
"NL": [
"highway"
],
"NL-BQ2": [
"highway"
],
"NL-BQ3": [
"highway"
],
"NO": [
"highway"
],
"NP": [
"highway"
],
"NZ": [
"highway"
],
"OM": [
"highway"
],
"PA": [
"highway"
],
"PE": [
"highway"
],
"PF": [
"highway"
],
"PG": [
"highway"
],
"PH": [
"highway"
],
"PK": [
"highway"
],
"PL": [
"highway"
],
"PR": [
"highway"
],
"PS": [
"highway"
],
"PT": [
"highway"
],
"PY": [
"highway"
],
"QA": [
"highway"
],
"RO": [
"highway"
],
"RS": [
"highway"
],
"RS-KM": [
"highway"
],
"RU": [
"highway"
],
"RW": [
"highway"
],
"SA": [
"highway"
],
"SB": [
"highway"
],
"SD": [
"highway"
],
"SE": [
"highway"
],
"SG": [
"highway"
],
"SI": [
"highway"
],
"SK": [
"highway"
],
"SL": [
"highway"
],
"SN": [
"highway"
],
"SO": [
"highway"
],
"SR": [
"highway"
],
"SS": [
"highway"
],
"ST": [
"highway"
],
"SV": [
"highway"
],
"SX": [
"highway"
],
"SZ": [
"highway"
],
"TC": [
"highway"
],
"TD": [
"highway"
],
"TG": [
"highway"
],
"TH": [
"highway"
],
"TJ": [
"highway"
],
"TL": [
"highway"
],
"TM": [
"highway"
],
"TN": [
"highway"
],
"TR": [
"highway"
],
"TT": [
"highway"
],
"TW": [
"highway"
],
"TZ": [
"building",
"highway"
],
"UA": [
"highway"
],
"UG": [
"building",
"highway"
],
"US": [
"building",
"highway"
],
"US-AK": [
"building"
],
"US-HI": [
"building"
],
"UY": [
"highway"
],
"UZ": [
"highway"
],
"VC": [
"highway"
],
"VE": [
"highway"
],
"VG": [
"highway"
],
"VN": [
"highway"
],
"VU": [
"highway"
],
"YE": [
"highway"
],
"ZA": [
"highway"
],
"ZM": [
"highway"
],
"ZW": [
"highway"
]
},
"default": true,
"license": "ODBL",
"osm_compatible": "yes",
"parameters": [
{
"description": "buildings",
"enabled": true,
"parameter": "result_type=road_building_vector_xml"
}
],
"permission_url": "{{ request.baseUrl }}/facebookmicrosites/Open-Mapping-At-Facebook/wiki/FAQ",
"terms_of_use_url": "{{ request.baseUrl }}/doc/license/MapWithAILicense.pdf",
"privacy_policy_url": "{{ request.baseUrl }}/doc/license/MapWithAIPrivacyPolicy.pdf#page=3",
"url": "{{ request.baseUrl }}/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=josm&token=ASb3N5o9HbX8QWn8G_NtHIRQaYv3nuG2r7_f3vnGld3KhZNCxg57IsaQyssIaEw5rfRNsPpMwg4TsnrSJtIJms5m&hash=ASawRla3rBcwEjY4HIY&bbox={bbox}"
}
},
"transformers": [
"response-template"
],
"headers" : {
"Accept-Ranges" : "bytes",
"Cache-Control" : "max-age=600",
"Content-Type" : "application/json",
"Expires" : "Tue, 21 Apr 2020 19:51:40 UTC",
"Last-Modified" : "Tue, 21 Apr 2020 17:34:08 GMT",
"Vary" : "Origin",
"Date" : "Tue, 21 Apr 2020 19:41:40 GMT"
}
},
"uuid" : "23497750-675c-440a-986a-34dd14b047f8",
"persistent" : true,
"insertionIndex" : 1
}

Wyświetl plik

@ -24,6 +24,7 @@ import javax.imageio.ImageIO;
import javax.swing.Action;
import javax.swing.ImageIcon;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@ -40,13 +41,11 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.testutils.annotations.ThreadSync;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.matching.AnythingPattern;
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
@ -74,14 +73,11 @@ class AddMapWithAILayerActionTest {
@RegisterExtension
static ThreadSyncMWAI threadSync = new ThreadSyncMWAI();
@BasicWiremock
WireMockServer wireMockServer;
private static MapWithAIInfo info;
private static MapWithAIInfo backupInfo;
@BeforeEach
void setup() {
void setup(WireMockRuntimeInfo wireMockRuntimeInfo) {
final Map<String, StringValuePattern> parameterMap = new HashMap<>();
final AnythingPattern anythingPattern = new AnythingPattern();
parameterMap.put("geometryType", anythingPattern);
@ -91,8 +87,9 @@ class AddMapWithAILayerActionTest {
parameterMap.put("outfields", new EqualToPattern("*"));
parameterMap.put("result_type", new EqualToPattern("road_building_vector_xml"));
parameterMap.put("resultOffset", anythingPattern);
wireMockServer.stubFor(
WireMock.get(new UrlPathPattern(new EqualToPattern("/query"), false)).withQueryParams(parameterMap)
wireMockRuntimeInfo.getWireMock()
.register(WireMock.get(new UrlPathPattern(new EqualToPattern("/query"), false))
.withQueryParams(parameterMap)
.willReturn(WireMock.aResponse()
.withBody(Json.createObjectBuilder().add("type", "FeatureCollection")
.add("features", Json.createArrayBuilder().build()).build().toString()))
@ -142,7 +139,7 @@ class AddMapWithAILayerActionTest {
}
@Test
void testRemoteIcon() throws IOException {
void testRemoteIcon(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
final ImageIcon blankImage = ImageProvider.createBlankIcon(ImageProvider.ImageSizes.LARGEICON);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// BufferedImage is what the current implementation uses. Otherwise, we will
@ -150,10 +147,10 @@ class AddMapWithAILayerActionTest {
final BufferedImage bi = assertInstanceOf(BufferedImage.class, blankImage.getImage());
ImageIO.write(bi, "png", byteArrayOutputStream);
byte[] originalImage = byteArrayOutputStream.toByteArray();
wireMockServer.addStubMapping(
wireMockServer.stubFor(WireMock.get("/icon").willReturn(WireMock.aResponse().withBody(originalImage))));
wireMockRuntimeInfo.getWireMock()
.register(WireMock.get("/icon").willReturn(WireMock.aResponse().withBody(originalImage)));
final MapWithAIInfo remoteInfo = new MapWithAIInfo(info);
remoteInfo.setIcon(wireMockServer.baseUrl() + "/icon");
remoteInfo.setIcon(wireMockRuntimeInfo.getHttpBaseUrl() + "/icon");
final AddMapWithAILayerAction action = new AddMapWithAILayerAction(remoteInfo);
threadSync.threadSync();
final Object image = action.getValue(Action.LARGE_ICON_KEY);
@ -166,7 +163,7 @@ class AddMapWithAILayerActionTest {
}
@Test
void testNonRegression22683() {
void testNonRegression22683(WireMockRuntimeInfo wireMockRuntimeInfo) {
final OsmDataLayer layer = new OsmDataLayer(new DataSet(), "testNonRegression22683", null);
layer.getDataSet().addDataSource(new DataSource(new Bounds(0, 0, 0.001, 0.001), "Area 1"));
layer.getDataSet().addDataSource(new DataSource(new Bounds(-0.001, -0.001, 0, 0), "Area 2"));
@ -190,7 +187,7 @@ class AddMapWithAILayerActionTest {
};
Logging.getLogger().addHandler(testHandler);
try {
info.setUrl(wireMockServer.baseUrl());
info.setUrl(wireMockRuntimeInfo.getHttpBaseUrl());
info.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);
final AddMapWithAILayerAction action = new AddMapWithAILayerAction(info);
Logging.clearLastErrorAndWarnings();

Wyświetl plik

@ -5,8 +5,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.List;
import java.util.stream.Collectors;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.osm.DataSet;
@ -17,12 +20,9 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.HTTP;
import org.openstreetmap.josm.testutils.annotations.OsmApi;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult;
import com.github.tomakehurst.wiremock.admin.model.ServeEventQuery;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.http.Request;
@ -46,35 +46,32 @@ import com.github.tomakehurst.wiremock.verification.LoggedRequest;
class BoundingBoxMapWithAIDownloaderTest {
private static final String TEST_DATA = "<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/><node id=\"2\" lat=\"1\" lon=\"1\" version=\"1\"/></osm>";
@BasicWiremock
public WireMockServer wireMockServer;
@Test
void testThirdPartyConflation() {
void testThirdPartyConflation(WireMockRuntimeInfo wireMockRuntimeInfo) {
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
final MapWithAIInfo info = new MapWithAIInfo("testThirdPartyConflation",
this.wireMockServer.baseUrl() + "/testThirdPartyConflation");
wireMockRuntimeInfo.getHttpBaseUrl() + "/testThirdPartyConflation");
// ADDRESS has a default /conflate endpoint from a mocked copy of conflation
// servers.
info.setCategory(MapWithAICategory.ADDRESS);
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
downloadBounds, info, false);
this.wireMockServer.stubFor(
wireMockRuntimeInfo.getWireMock().register(
WireMock.get("/testThirdPartyConflation").willReturn(WireMock.aResponse().withBody(TEST_DATA)));
final StubMapping conflationStub = this.wireMockServer
.stubFor(WireMock.post("/conflate").willReturn(WireMock.aResponse()
final StubMapping conflationStub = wireMockRuntimeInfo.getWireMock()
.register(WireMock.post("/conflate").willReturn(WireMock.aResponse()
.withBody("<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/></osm>")));
final DataSet ds = assertDoesNotThrow(
() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
assertEquals(1, ds.allPrimitives().size());
assertEquals(1L, ds.allPrimitives().iterator().next().getPrimitiveId().getUniqueId());
final GetServeEventsResult serveEvents = this.wireMockServer
final List<ServeEvent> serveEvents = wireMockRuntimeInfo.getWireMock()
.getServeEvents(ServeEventQuery.forStubMapping(conflationStub));
assertEquals(1, serveEvents.getRequests().size());
final LoggedRequest request = serveEvents.getRequests().get(0).getRequest();
assertEquals(1, serveEvents.size());
final LoggedRequest request = serveEvents.get(0).getRequest();
assertEquals(1, request.getParts().size(),
request.getParts().stream().map(Request.Part::getName).collect(Collectors.joining(",")));
assertNotNull(request.getPart("external"));
@ -85,29 +82,35 @@ class BoundingBoxMapWithAIDownloaderTest {
* MapWithAI servers
*/
@Test
void testNonRegression22624() {
void testNonRegression22624(WireMockRuntimeInfo wireMockRuntimeInfo) {
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
MapWithAIInfo info = new MapWithAIInfo("testNonRegression22624",
this.wireMockServer.baseUrl() + "/no-conflation?bbox={bbox}",
wireMockRuntimeInfo.getHttpBaseUrl() + "/no-conflation?bbox={bbox}",
MapWithAIType.ESRI_FEATURE_SERVER.getTypeString(), null, "testNonRegression22624");
info.setConflationUrl(this.wireMockServer.baseUrl() + "/conflation?bbox={bbox}");
info.setConflationUrl(wireMockRuntimeInfo.getHttpBaseUrl() + "/conflation?bbox={bbox}");
info.setConflation(true);
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
downloadBounds, info, false);
StubMapping noConflation = this.wireMockServer
.stubFor(WireMock.get("/no-conflation").willReturn(WireMock.badRequest()));
StubMapping resultOffset = this.wireMockServer.stubFor(
WireMock.get(WireMock.urlPathEqualTo("/conflation")).withQueryParam("bbox", new AnythingPattern())
StubMapping noConflation = wireMockRuntimeInfo.getWireMock()
.register(WireMock.get("/no-conflation").willReturn(WireMock.badRequest()));
StubMapping resultOffset = wireMockRuntimeInfo.getWireMock()
.register(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
.withQueryParam("bbox", new AnythingPattern())
.withQueryParam("resultOffset", new EqualToPattern("0")).willReturn(WireMock.badRequest()));
StubMapping noResultOffset = this.wireMockServer.stubFor(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
.withQueryParam("bbox", new AnythingPattern()).withQueryParam("resultOffset", AbsentPattern.ABSENT)
.willReturn(WireMock.aResponse().withBody(TEST_DATA)));
StubMapping noResultOffset = wireMockRuntimeInfo.getWireMock()
.register(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
.withQueryParam("bbox", new AnythingPattern())
.withQueryParam("resultOffset", AbsentPattern.ABSENT)
.willReturn(WireMock.aResponse().withBody(TEST_DATA)));
assertDoesNotThrow(() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
this.wireMockServer.verify(0, RequestPatternBuilder.forCustomMatcher(noConflation.getRequest()));
this.wireMockServer.verify(0, RequestPatternBuilder.forCustomMatcher(resultOffset.getRequest()));
this.wireMockServer.verify(1, RequestPatternBuilder.forCustomMatcher(noResultOffset.getRequest()));
wireMockRuntimeInfo.getWireMock().verifyThat(0,
RequestPatternBuilder.forCustomMatcher(noConflation.getRequest()));
wireMockRuntimeInfo.getWireMock().verifyThat(0,
RequestPatternBuilder.forCustomMatcher(resultOffset.getRequest()));
wireMockRuntimeInfo.getWireMock().verifyThat(1,
RequestPatternBuilder.forCustomMatcher(noResultOffset.getRequest()));
}
}

Wyświetl plik

@ -9,6 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.ThrowingSupplier;
@ -24,10 +26,8 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIConflati
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.HTTP;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
@ -46,9 +46,6 @@ import mockit.MockUp;
@Wiremock
@MapWithAISources
class DataConflationSenderTest {
@BasicWiremock
WireMockServer wireMockServer;
static class MapWithAIConflationCategoryMock extends MockUp<MapWithAIConflationCategory> {
static String url;
@ -81,10 +78,10 @@ class DataConflationSenderTest {
}
@Test
void testWorkingUrl() {
MapWithAIConflationCategoryMock.url = wireMockServer.baseUrl() + "/conflate";
final StubMapping stubMapping = wireMockServer
.stubFor(WireMock.post("/conflate").willReturn(WireMock.aResponse().withBody(
void testWorkingUrl(WireMockRuntimeInfo wireMockRuntimeInfo) {
MapWithAIConflationCategoryMock.url = wireMockRuntimeInfo.getHttpBaseUrl() + "/conflate";
final StubMapping stubMapping = wireMockRuntimeInfo.getWireMock()
.register(WireMock.post("/conflate").willReturn(WireMock.aResponse().withBody(
"<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' generator='DataConflationSenderTest#testWorkingUrl'><node id='1' version='1' visible='true' lat='89.0' lon='0.1' /></osm>")));
new MapWithAIConflationCategoryMock();
@ -99,15 +96,14 @@ class DataConflationSenderTest {
assertEquals(1, conflated.getNodes().size());
final Node conflatedNode = conflated.getNodes().iterator().next();
assertEquals(new LatLon(89, 0.1), conflatedNode.getCoor());
assertEquals(1, wireMockServer.getAllServeEvents().stream()
.filter(serveEvent -> stubMapping.equals(serveEvent.getStubMapping())).count());
wireMockRuntimeInfo.getWireMock().verifyThat(1, RequestPatternBuilder.like(stubMapping.getRequest()));
}
@Test
void testWorkingUrlTimeout() {
MapWithAIConflationCategoryMock.url = wireMockServer.baseUrl() + "/conflate";
final StubMapping stubMapping = wireMockServer.stubFor(WireMock.post("/conflate")
.willReturn(WireMock.aResponse().withBody(
void testWorkingUrlTimeout(WireMockRuntimeInfo wireMockRuntimeInfo) {
MapWithAIConflationCategoryMock.url = wireMockRuntimeInfo.getHttpBaseUrl() + "/conflate";
final StubMapping stubMapping = wireMockRuntimeInfo.getWireMock()
.register(WireMock.post("/conflate").willReturn(WireMock.aResponse().withBody(
"<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' generator='DataConflationSenderTest#testWorkingUrl'><node id='1' version='1' visible='true' lat='89.0' lon='0.1' /></osm>")
.withFixedDelay(500)));
new MapWithAIConflationCategoryMock();
@ -123,8 +119,7 @@ class DataConflationSenderTest {
assertEquals(1, conflated.getNodes().size());
final Node conflatedNode = conflated.getNodes().iterator().next();
assertEquals(new LatLon(89, 0.1), conflatedNode.getCoor());
assertEquals(1, wireMockServer.getAllServeEvents().stream()
.filter(serveEvent -> stubMapping.equals(serveEvent.getStubMapping())).count());
wireMockRuntimeInfo.getWireMock().verifyThat(1, RequestPatternBuilder.like(stubMapping.getRequest()));
}
static Stream<Arguments> testNonWorkingUrl() {
@ -135,9 +130,10 @@ class DataConflationSenderTest {
@ParameterizedTest
@MethodSource
void testNonWorkingUrl(final ResponseDefinitionBuilder response) {
MapWithAIConflationCategoryMock.url = wireMockServer.baseUrl() + "/conflate";
final StubMapping stubMapping = wireMockServer.stubFor(WireMock.post("/conflate").willReturn(response));
void testNonWorkingUrl(final ResponseDefinitionBuilder response, final WireMockRuntimeInfo wireMockRuntimeInfo) {
MapWithAIConflationCategoryMock.url = wireMockRuntimeInfo.getHttpBaseUrl() + "/conflate";
final StubMapping stubMapping = wireMockRuntimeInfo.getWireMock()
.register(WireMock.post("/conflate").willReturn(response));
new MapWithAIConflationCategoryMock();
final DataSet external = new DataSet(new Node(LatLon.NORTH_POLE));
@ -147,7 +143,6 @@ class DataConflationSenderTest {
dataConflationSender.run();
final DataSet conflated = assertDoesNotThrow((ThrowingSupplier<DataSet>) dataConflationSender::get);
assertNull(conflated);
assertEquals(1, wireMockServer.getAllServeEvents().stream()
.filter(serveEvent -> stubMapping.equals(serveEvent.getStubMapping())).count());
wireMockRuntimeInfo.getWireMock().verifyThat(1, RequestPatternBuilder.like(stubMapping.getRequest()));
}
}

Wyświetl plik

@ -10,8 +10,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.junit.jupiter.api.AfterEach;
@ -21,19 +21,13 @@ import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.tools.JosmRuntimeException;
import com.github.tomakehurst.wiremock.WireMockServer;
@Projection
@Wiremock
class ESRISourceReaderTest {
@BasicWiremock
public WireMockServer wireMockServer;
@BeforeEach
void setUp() {
ESRISourceReader.SOURCE_CACHE.clear();
@ -51,11 +45,11 @@ class ESRISourceReaderTest {
* file/wiremocked file
*/
@Test
void testAddEsriLayer() throws IOException {
void testAddEsriLayer(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
// TODO wiremock
MapWithAIInfo info = new MapWithAIInfo("TEST", "test_url", "bdf6c800b3ae453b9db239e03d7c1727");
info.setSourceType(MapWithAIType.ESRI);
String tUrl = wireMockServer.url("/sharing/rest");
String tUrl = wireMockRuntimeInfo.getHttpBaseUrl() + "/sharing/rest";
for (String url : Arrays.asList(tUrl, tUrl + "/")) {
info.setUrl(url);
final ESRISourceReader reader = new ESRISourceReader(info);
@ -65,7 +59,7 @@ class ESRISourceReaderTest {
} catch (ExecutionException | InterruptedException e) {
throw new JosmRuntimeException(e);
}
}).collect(Collectors.toList());
}).toList();
Future<?> workerQueue = MainApplication.worker.submit(() -> {
/* Sync threads */});
Awaitility.await().atMost(Durations.FIVE_SECONDS).until(workerQueue::isDone);

Wyświetl plik

@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
@ -20,6 +21,7 @@ import jakarta.json.Json;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
@BasicPreferences
@Territories
@ -29,8 +31,12 @@ class MapWithAISourceReaderTest {
void testParseSimple() throws IOException {
JsonObjectBuilder builder = Json.createObjectBuilder();
builder.add("nowhere", JsonValue.NULL);
try (var reader = new MapWithAISourceReader("")) {
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
final String json = builder.build().toString();
try (var reader = new MapWithAISourceReader("");
StringReader sr = new java.io.StringReader(json);
JsonParser parser = Json.createParser(sr)) {
parser.next();
List<MapWithAIInfo> infoList = reader.parseJson(parser);
assertEquals(1, infoList.size());
assertEquals("nowhere", infoList.get(0).getName());
}
@ -45,9 +51,12 @@ class MapWithAISourceReaderTest {
JsonArrayBuilder coCountriesArray = Json.createArrayBuilder(Collections.singleton("addr:housenumber"));
coCountries.add("US-CO", coCountriesArray.build());
co.add("countries", coCountries.build());
builder.add("Colorado", co);
try (var reader = new MapWithAISourceReader("")) {
List<MapWithAIInfo> infoList = reader.parseJson(builder.build());
String json = builder.add("Colorado", co).build().toString();
try (var reader = new MapWithAISourceReader("");
StringReader sr = new StringReader(json);
JsonParser parser = Json.createParser(sr)) {
parser.next();
List<MapWithAIInfo> infoList = reader.parseJson(parser);
assertEquals(1, infoList.size());
MapWithAIInfo info = infoList.stream().filter(i -> "Colorado".equals(i.getName())).findFirst().orElse(null);
assertNotNull(info);

Wyświetl plik

@ -8,14 +8,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.stream.Stream;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.openstreetmap.josm.plugins.mapwithai.spi.preferences.IMapWithAIUrls;
import com.github.tomakehurst.wiremock.WireMockServer;
/**
* Set the MapWithAI config for the test
*
@ -29,7 +28,7 @@ import com.github.tomakehurst.wiremock.WireMockServer;
public @interface MapWithAIConfig {
class MapWithAIConfigExtension extends Wiremock.WiremockExtension implements BeforeEachCallback, AfterEachCallback {
@Override
public void beforeEach(ExtensionContext context) throws Exception {
public void beforeEach(ExtensionContext context) {
org.openstreetmap.josm.plugins.mapwithai.spi.preferences.MapWithAIConfig
.setUrlsProvider(new WireMockMapWithAIUrls(getWiremock(context)));
}
@ -42,25 +41,25 @@ public @interface MapWithAIConfig {
}
private static final class WireMockMapWithAIUrls implements IMapWithAIUrls {
private final WireMockServer wireMockServer;
private final WireMockRuntimeInfo wireMockServer;
public WireMockMapWithAIUrls(final WireMockServer wireMockServer) {
public WireMockMapWithAIUrls(final WireMockRuntimeInfo wireMockServer) {
this.wireMockServer = wireMockServer;
}
@Override
public String getConflationServerJson() {
return this.wireMockServer.baseUrl() + "/MapWithAI/json/conflation_servers.json";
return this.wireMockServer.getHttpBaseUrl() + "/MapWithAI/json/conflation_servers.json";
}
@Override
public String getMapWithAISourcesJson() {
return this.wireMockServer.baseUrl() + "/MapWithAI/json/sources.json";
return this.wireMockServer.getHttpBaseUrl() + "/MapWithAI/json/sources.json";
}
@Override
public String getMapWithAIPaintStyle() {
return this.wireMockServer.baseUrl() + "/josmfile?page=Styles/MapWithAI&zip=1";
return this.wireMockServer.getHttpBaseUrl() + "/josmfile?page=Styles/MapWithAI&zip=1";
}
}

Wyświetl plik

@ -1,15 +1,25 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.testutils.annotations;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.commons.support.AnnotationSupport;
@ -29,11 +39,8 @@ import org.openstreetmap.josm.testutils.annotations.Territories;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.FileSource;
import com.github.tomakehurst.wiremock.extension.Parameters;
import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.Response;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.ReflectionUtils;
/**
* Test annotation to ensure that wiremock is used
@ -44,8 +51,8 @@ import com.github.tomakehurst.wiremock.http.Response;
@Target({ ElementType.PARAMETER, ElementType.TYPE, ElementType.METHOD })
@BasicPreferences
@HTTP
@BasicWiremock(value = "src/test/resources/wiremock")
@ExtendWith(Wiremock.TestMapWithAIUrls.class)
@BasicWiremock(value = "src/test/resources/wiremock", responseTransformers = Wiremock.WireMockUrlTransformer.class)
public @interface Wiremock {
/**
* Set to {@code false} to turn off wiremock (use only in integration tests)
@ -54,72 +61,34 @@ public @interface Wiremock {
*/
boolean value() default true;
/**
* Replace URL's with the wiremock URL
*
* @author Taylor Smock
*/
class WireMockUrlTransformer extends ResponseTransformer {
private final ExtensionContext context;
public WireMockUrlTransformer(ExtensionContext context) {
this.context = context;
}
@Override
public String getName() {
return "Convert urls in responses to wiremock url";
}
@Override
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
if (!request.getUrl().endsWith("/capabilities")
&& response.getHeaders().getContentTypeHeader().mimeTypePart() != null
&& !response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip")) {
String origBody = response.getBodyAsString();
String newBody = origBody.replaceAll("https?://.*?/",
WiremockExtension.getWiremock(context).baseUrl() + "/");
return Response.Builder.like(response).but().body(newBody).build();
}
return response;
}
}
/**
* This is the base wiremock extension class
*/
class WiremockExtension extends BasicWiremock.WireMockExtension {
class WiremockExtension {
/**
* Get the default wiremock server
*
* @param context The context to search
* @return The wiremock server
*/
public static WireMockServer getWiremock(ExtensionContext context) {
ExtensionContext.Namespace namespace = ExtensionContext.Namespace.create(BasicWiremock.class);
return context.getStore(namespace).get(WireMockServer.class, WireMockServer.class);
public static WireMockRuntimeInfo getWiremock(ExtensionContext context) {
return context.getStore(ExtensionContext.Namespace.create(BasicWiremock.WireMockExtension.class))
.get(BasicWiremock.WireMockExtension.class, BasicWiremock.WireMockExtension.class).getRuntimeInfo();
}
}
/**
* Extension for {@link MapWithAILayerInfo}
*/
class MapWithAILayerInfoExtension extends WiremockExtension {
private static int hashCode;
class MapWithAILayerInfoExtension extends WiremockExtension implements BeforeAllCallback, AfterAllCallback {
@Override
public void afterAll(ExtensionContext context) throws Exception {
try {
super.afterAll(context);
} finally {
resetMapWithAILayerInfo(context);
}
public void afterAll(ExtensionContext context) {
resetMapWithAILayerInfo(context);
}
@Override
public void beforeAll(ExtensionContext context) throws Exception {
super.beforeAll(context);
public void beforeAll(ExtensionContext context) {
MapWithAILayerInfo.setImageryLayersSites(null);
AtomicBoolean finished = new AtomicBoolean();
MapWithAILayerInfo.getInstance().clear();
@ -141,29 +110,49 @@ public @interface Wiremock {
}
class TestMapWithAIUrls extends WiremockExtension implements IMapWithAIUrls {
class TestMapWithAIUrls extends WiremockExtension
implements IMapWithAIUrls, BeforeAllCallback, BeforeEachCallback, AfterAllCallback, AfterEachCallback {
ExtensionContext context;
private static boolean conflationServerInitialized;
/**
* Replace URL servers with wiremock
*
* @param baseUrl The wiremock to point to
* @param url The URL to fix
* @return A url that points at the wiremock server
*/
public static String replaceUrl(String baseUrl, String url) {
try {
URL temp = new URL(url);
return baseUrl + temp.getFile();
} catch (MalformedURLException error) {
Logging.error(error);
}
return null;
}
@Override
public String getConflationServerJson() {
conflationServerInitialized = true;
return replaceUrl(getWiremock(this.context), MapWithAIUrls.getInstance().getConflationServerJson());
return replaceUrl(getWiremock(this.context).getHttpBaseUrl(),
MapWithAIUrls.getInstance().getConflationServerJson());
}
@Override
public String getMapWithAISourcesJson() {
return replaceUrl(getWiremock(this.context), MapWithAIUrls.getInstance().getMapWithAISourcesJson());
return replaceUrl(getWiremock(this.context).getHttpBaseUrl(),
MapWithAIUrls.getInstance().getMapWithAISourcesJson());
}
@Override
public String getMapWithAIPaintStyle() {
return replaceUrl(getWiremock(this.context), MapWithAIUrls.getInstance().getMapWithAIPaintStyle());
return replaceUrl(getWiremock(this.context).getHttpBaseUrl(),
MapWithAIUrls.getInstance().getMapWithAIPaintStyle());
}
@Override
public void beforeAll(ExtensionContext context) throws Exception {
super.beforeAll(context);
public void beforeAll(ExtensionContext context) {
final Optional<Wiremock> annotation = AnnotationUtils.findFirstParentAnnotation(context, Wiremock.class);
this.context = context;
if (Boolean.FALSE.equals(annotation.map(Wiremock::value).orElse(Boolean.TRUE))) {
@ -174,44 +163,48 @@ public @interface Wiremock {
if (conflationServerInitialized) {
MapWithAIConflationCategory.initialize();
}
AnnotationUtils.resetStaticClass(DataAvailability.class);
assertDoesNotThrow(() -> AnnotationUtils.resetStaticClass(DataAvailability.class));
}
@Override
public void beforeEach(ExtensionContext context) throws Exception {
public void beforeEach(ExtensionContext context) {
final Optional<Wiremock> annotation = AnnotationUtils.findFirstParentAnnotation(context, Wiremock.class);
this.context = context;
if (annotation.isPresent()) {
this.beforeAll(context);
}
final WireMockServer wireMockServer = getWiremock(context);
final WireMock wireMockServer = getWiremock(context).getWireMock();
super.beforeEach(context);
if (wireMockServer.getStubMappings().stream().filter(mapping -> mapping.getRequest().getUrl() != null)
.noneMatch(mapping -> mapping.getRequest().getUrl()
.equals("/MapWithAI/json/conflation_servers.json"))) {
wireMockServer.stubFor(WireMock.get("/MapWithAI/json/conflation_servers.json")
if (wireMockServer.allStubMappings().getMappings().stream()
.filter(mapping -> mapping.getRequest().getUrl() != null).noneMatch(mapping -> mapping.getRequest()
.getUrl().equals("/MapWithAI/json/conflation_servers.json"))) {
wireMockServer.register(WireMock.get("/MapWithAI/json/conflation_servers.json")
.willReturn(WireMock.aResponse().withBody("{}")).atPriority(-5));
}
}
@Override
public void afterAll(ExtensionContext context) throws Exception {
public void afterEach(ExtensionContext extensionContext) {
this.context = extensionContext;
}
@Override
public void afterAll(ExtensionContext context) {
this.context = context;
// @Wiremock stops the WireMockServer prior to this method being called
getWiremock(context).start();
MapPaintUtils.removeMapWithAIPaintStyles();
final WireMockServer wireMockServer = assertDoesNotThrow(() -> {
final Field serverField = WireMockRuntimeInfo.class.getDeclaredField("wireMockServer");
ReflectionUtils.setObjectsAccessible(serverField);
return (WireMockServer) serverField.get(getWiremock(context));
});
try {
// This stops the WireMockServer again.
super.afterAll(context);
wireMockServer.start();
MapPaintUtils.removeMapWithAIPaintStyles();
wireMockServer.stop();
} finally {
MapWithAIConfig.setUrlsProvider(new InvalidMapWithAIUrls());
}
}
public WireMockServer getWireMockServer() {
return getWiremock(context);
}
}
class InvalidMapWithAIUrls implements IMapWithAIUrls {