Fix a URL so that it catches other URL patterns

Also, make some modifications to rules so that a mocker can be used for
some classes, to reduce time running tests

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-24 15:58:16 -06:00
rodzic 3565fcb232
commit 60e3d8f74a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 40 dodań i 19 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
"id" : "23497750-675c-440a-986a-34dd14b047f8", "id" : "23497750-675c-440a-986a-34dd14b047f8",
"name" : "josm_mapwithai_json_sourcesjson", "name" : "josm_mapwithai_json_sourcesjson",
"request" : { "request" : {
"url" : "/gokaart/JOSM_MapWithAI/-/raw/pages/public/json/sources.json", "urlPattern" : "(\/gokaart)?\/JOSM_MapWithAI\/(-\/raw\/pages\/public\/)?json\/sources.json",
"method" : "GET" "method" : "GET"
}, },
"response" : { "response" : {
@ -21,4 +21,4 @@
"uuid" : "23497750-675c-440a-986a-34dd14b047f8", "uuid" : "23497750-675c-440a-986a-34dd14b047f8",
"persistent" : true, "persistent" : true,
"insertionIndex" : 1 "insertionIndex" : 1
} }

Wyświetl plik

@ -51,14 +51,32 @@ public class MapWithAITestRules extends JOSMTestRules {
private UncaughtExceptionHandler currentExceptionHandler; private UncaughtExceptionHandler currentExceptionHandler;
private String currentReleaseUrl; private String currentReleaseUrl;
private Collection<String> sourceSites; private Collection<String> sourceSites;
private Runnable mapwithaiLayerInfoMocker;
public MapWithAITestRules() { public MapWithAITestRules() {
super(); super();
super.assertionsInEDT(); super.assertionsInEDT();
} }
/**
* Use if a fully initialized {@link MapWithAILayerInfo} is required
*
* @return this, for easy chaining
*/
public MapWithAITestRules sources() { public MapWithAITestRules sources() {
return sources(null);
}
/**
* Use if you don't need all of {@link MapWithAILayerInfo}
*
* @param mapwithaiLayerInfoMocker A mocker so that MapWithAILayerInfo isn't
* fully instantiated
* @return this, for easy chaining
*/
public MapWithAITestRules sources(Runnable mapwithaiLayerInfoMocker) {
this.sources = true; this.sources = true;
this.mapwithaiLayerInfoMocker = mapwithaiLayerInfoMocker;
return this; return this;
} }
@ -87,6 +105,9 @@ public class MapWithAITestRules extends JOSMTestRules {
Logging.getLogger().setFilter(record -> record.getLevel().intValue() >= Level.WARNING.intValue() Logging.getLogger().setFilter(record -> record.getLevel().intValue() >= Level.WARNING.intValue()
|| record.getSourceClassName().startsWith("org.openstreetmap.josm.plugins.mapwithai")); || record.getSourceClassName().startsWith("org.openstreetmap.josm.plugins.mapwithai"));
if (mapwithaiLayerInfoMocker != null) {
mapwithaiLayerInfoMocker.run();
}
if (wiremock) { if (wiremock) {
wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock") wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")
.extensions(new WireMockUrlTransformer()).dynamicPort()); .extensions(new WireMockUrlTransformer()).dynamicPort());
@ -129,23 +150,6 @@ public class MapWithAITestRules extends JOSMTestRules {
} }
} }
/**
* Replace URL servers with wiremock
*
* @param wireMock The wiremock to point to
* @param url The URL to fix
* @return A url that points at the wiremock server
*/
private static String replaceUrl(WireMockServer wireMock, String url) {
try {
URL temp = new URL(url);
return wireMock.baseUrl() + temp.getFile();
} catch (MalformedURLException error) {
Logging.error(error);
}
return null;
}
@Override @Override
protected void after() throws ReflectiveOperationException { protected void after() throws ReflectiveOperationException {
super.after(); super.after();
@ -175,6 +179,23 @@ public class MapWithAITestRules extends JOSMTestRules {
} }
} }
/**
* Replace URL servers with wiremock
*
* @param wireMock The wiremock to point to
* @param url The URL to fix
* @return A url that points at the wiremock server
*/
private static String replaceUrl(WireMockServer wireMock, String url) {
try {
URL temp = new URL(url);
return wireMock.baseUrl() + temp.getFile();
} catch (MalformedURLException error) {
Logging.error(error);
}
return null;
}
/** /**
* Get the wiremock instance * Get the wiremock instance
* *