kopia lustrzana https://github.com/JOSM/MapWithAI
Ensure that MapWithAILayerInfo is always called when test rules set it up
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
69d69e8df3
commit
5b4d06b96a
|
@ -16,6 +16,7 @@ import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.StructUtils;
|
import org.openstreetmap.josm.data.StructUtils;
|
||||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||||
|
@ -62,7 +63,16 @@ public class MapWithAILayerInfo {
|
||||||
public static MapWithAILayerInfo getInstance() {
|
public static MapWithAILayerInfo getInstance() {
|
||||||
synchronized (DEFAULT_LAYER_SITES) {
|
synchronized (DEFAULT_LAYER_SITES) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new MapWithAILayerInfo();
|
AtomicBoolean finished = new AtomicBoolean();
|
||||||
|
instance = new MapWithAILayerInfo(() -> finished.set(true));
|
||||||
|
while (!finished.get()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Logging.error(e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -89,8 +99,8 @@ public class MapWithAILayerInfo {
|
||||||
return Config.getPref().putList(CONFIG_PREFIX + "layers.sites", new ArrayList<>(sites));
|
return Config.getPref().putList(CONFIG_PREFIX + "layers.sites", new ArrayList<>(sites));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapWithAILayerInfo() {
|
private MapWithAILayerInfo(FinishListener listener) {
|
||||||
load(false);
|
load(false, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class MapWithAIPluginTest {
|
public class MapWithAIPluginTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().preferences().main();
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().preferences().main();
|
||||||
|
|
||||||
public PluginInformation info;
|
public PluginInformation info;
|
||||||
public MapWithAIPlugin plugin;
|
public MapWithAIPlugin plugin;
|
||||||
|
|
|
@ -24,7 +24,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class DownloadMapWithAITaskTest {
|
public class DownloadMapWithAITaskTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules rule = new MapWithAITestRules().wiremock().preferences().fakeAPI().projection().territories();
|
public JOSMTestRules rule = new MapWithAITestRules().sources().wiremock().preferences().fakeAPI().projection()
|
||||||
|
.territories();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDownloadOsmServerReaderDownloadParamsBoundsProgressMonitor()
|
public void testDownloadOsmServerReaderDownloadParamsBoundsProgressMonitor()
|
||||||
|
|
|
@ -37,7 +37,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class GetDataRunnableTest {
|
public class GetDataRunnableTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules rule = new MapWithAITestRules().wiremock().projection().fakeAPI().territories();
|
public JOSMTestRules rule = new MapWithAITestRules().sources().wiremock().projection().fakeAPI().territories();
|
||||||
|
|
||||||
public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url) {
|
public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url) {
|
||||||
return getDefaultMapWithAIAPIForTest(wireMock, url, "https://www.mapwith.ai");
|
return getDefaultMapWithAIAPIForTest(wireMock, url, "https://www.mapwith.ai");
|
||||||
|
|
|
@ -32,7 +32,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class MapWithAIActionTest {
|
public class MapWithAIActionTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().main().projection().territories().timeout(100000);
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().main().projection().territories()
|
||||||
|
.timeout(100000);
|
||||||
|
|
||||||
private MapWithAIAction action;
|
private MapWithAIAction action;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class MapWithAIAvailabilityTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().projection().territories();
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().projection().territories();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
|
@ -58,8 +58,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class MapWithAILayerTest {
|
public class MapWithAILayerTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().preferences().main().projection().fakeAPI()
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().preferences().main().projection()
|
||||||
.territories();
|
.fakeAPI().territories();
|
||||||
|
|
||||||
MapWithAILayer layer;
|
MapWithAILayer layer;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class MapWithAIRemoteControlTest {
|
||||||
*/
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().main().projection().territories();
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().main().projection().territories();
|
||||||
|
|
||||||
private static MapWithAIRemoteControl newHandler(String url) throws RequestHandlerBadRequestException {
|
private static MapWithAIRemoteControl newHandler(String url) throws RequestHandlerBadRequestException {
|
||||||
final MapWithAIRemoteControl req = new MapWithAIRemoteControl();
|
final MapWithAIRemoteControl req = new MapWithAIRemoteControl();
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.openstreetmap.josm.plugins.PluginException;
|
||||||
import org.openstreetmap.josm.plugins.PluginInformation;
|
import org.openstreetmap.josm.plugins.PluginInformation;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
@ -41,7 +42,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class MapWithAIUploadHookTest {
|
public class MapWithAIUploadHookTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new JOSMTestRules().main().projection().preferences().territories();
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().main().projection().preferences()
|
||||||
|
.territories();
|
||||||
private PluginInformation info;
|
private PluginInformation info;
|
||||||
private OsmDataLayer osmLayer;
|
private OsmDataLayer osmLayer;
|
||||||
private MapWithAILayer aiLayer;
|
private MapWithAILayer aiLayer;
|
||||||
|
|
|
@ -39,7 +39,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
public class CreateConnectionsCommandTest {
|
public class CreateConnectionsCommandTest {
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().projection();
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().projection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class MapWithAIAddComandTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().projection().assertionsInEDT().main();
|
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().projection().assertionsInEDT().main();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||||
|
|
||||||
public class ESRISourceReaderTest {
|
public class ESRISourceReaderTest {
|
||||||
@Rule
|
@Rule
|
||||||
public MapWithAITestRules rule = (MapWithAITestRules) new MapWithAITestRules().wiremock().projection();
|
public MapWithAITestRules rule = (MapWithAITestRules) new MapWithAITestRules().sources().wiremock().projection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that ESRI servers are properly added
|
* Test that ESRI servers are properly added
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.openstreetmap.josm.io.OsmApi;
|
||||||
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
||||||
import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability;
|
import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.backend.GetDataRunnableTest;
|
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
|
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
||||||
|
@ -38,6 +37,8 @@ import com.github.tomakehurst.wiremock.http.Request;
|
||||||
import com.github.tomakehurst.wiremock.http.Response;
|
import com.github.tomakehurst.wiremock.http.Response;
|
||||||
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
|
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
|
||||||
|
|
||||||
|
import mockit.Mock;
|
||||||
|
import mockit.MockUp;
|
||||||
import mockit.integration.TestRunnerDecorator;
|
import mockit.integration.TestRunnerDecorator;
|
||||||
|
|
||||||
public class MapWithAITestRules extends JOSMTestRules {
|
public class MapWithAITestRules extends JOSMTestRules {
|
||||||
|
@ -89,8 +90,6 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")
|
wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")
|
||||||
.extensions(new WireMockUrlTransformer()).dynamicPort());
|
.extensions(new WireMockUrlTransformer()).dynamicPort());
|
||||||
wireMock.start();
|
wireMock.start();
|
||||||
resetMapWithAILayerInfo();
|
|
||||||
setupMapWithAILayerInfo(wireMock);
|
|
||||||
MapWithAIDataUtils.setPaintStyleUrl(MapWithAIDataUtils.getPaintStyleUrl()
|
MapWithAIDataUtils.setPaintStyleUrl(MapWithAIDataUtils.getPaintStyleUrl()
|
||||||
.replace(Config.getUrls().getJOSMWebsite(), wireMock.baseUrl()));
|
.replace(Config.getUrls().getJOSMWebsite(), wireMock.baseUrl()));
|
||||||
currentReleaseUrl = DataAvailability.getReleaseUrl();
|
currentReleaseUrl = DataAvailability.getReleaseUrl();
|
||||||
|
@ -107,8 +106,6 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||||
MapWithAILayerInfo.getInstance().getLayers()
|
|
||||||
.forEach(l -> l.setUrl(l.getUrl().replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/")));
|
|
||||||
try {
|
try {
|
||||||
OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE);
|
OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE);
|
||||||
} catch (OsmTransferCanceledException | OsmApiInitializationException e) {
|
} catch (OsmTransferCanceledException | OsmApiInitializationException e) {
|
||||||
|
@ -119,6 +116,15 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
AtomicBoolean finished = new AtomicBoolean();
|
AtomicBoolean finished = new AtomicBoolean();
|
||||||
MapWithAILayerInfo.getInstance().load(false, () -> finished.set(true));
|
MapWithAILayerInfo.getInstance().load(false, () -> finished.set(true));
|
||||||
Awaitility.await().atMost(Durations.TEN_SECONDS).until(finished::get);
|
Awaitility.await().atMost(Durations.TEN_SECONDS).until(finished::get);
|
||||||
|
} else {
|
||||||
|
// This only exists to ensure that if MapWithAILayerInfo is called, things
|
||||||
|
// happen...
|
||||||
|
new MockUp<MapWithAILayerInfo>() {
|
||||||
|
@Mock
|
||||||
|
public MapWithAILayerInfo getInstance() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (workerExceptions) {
|
if (workerExceptions) {
|
||||||
currentExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
currentExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||||
|
@ -137,10 +143,10 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
List<LoggedRequest> requests = wireMock.findUnmatchedRequests().getRequests();
|
List<LoggedRequest> requests = wireMock.findUnmatchedRequests().getRequests();
|
||||||
requests.forEach(r -> Logging.error(r.getAbsoluteUrl()));
|
requests.forEach(r -> Logging.error(r.getAbsoluteUrl()));
|
||||||
assertTrue(requests.isEmpty());
|
assertTrue(requests.isEmpty());
|
||||||
resetMapWithAILayerInfo();
|
|
||||||
DataAvailability.setReleaseUrl(currentReleaseUrl);
|
DataAvailability.setReleaseUrl(currentReleaseUrl);
|
||||||
Config.getPref().put("osm-server.url", null);
|
Config.getPref().put("osm-server.url", null);
|
||||||
MapWithAILayerInfo.setImageryLayersSites(sourceSites);
|
MapWithAILayerInfo.setImageryLayersSites(sourceSites);
|
||||||
|
resetMapWithAILayerInfo();
|
||||||
}
|
}
|
||||||
if (workerExceptions) {
|
if (workerExceptions) {
|
||||||
Thread.setDefaultUncaughtExceptionHandler(currentExceptionHandler);
|
Thread.setDefaultUncaughtExceptionHandler(currentExceptionHandler);
|
||||||
|
@ -148,15 +154,6 @@ public class MapWithAITestRules extends JOSMTestRules {
|
||||||
TestRunnerDecorator.cleanUpAllMocks();
|
TestRunnerDecorator.cleanUpAllMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupMapWithAILayerInfo(WireMockServer wireMockServer) {
|
|
||||||
synchronized (MapWithAITestRules.class) {
|
|
||||||
resetMapWithAILayerInfo();
|
|
||||||
MapWithAILayerInfo.getInstance().getLayers().stream().forEach(
|
|
||||||
i -> i.setUrl(GetDataRunnableTest.getDefaultMapWithAIAPIForTest(wireMockServer, i.getUrl())));
|
|
||||||
MapWithAILayerInfo.getInstance().save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetMapWithAILayerInfo() {
|
private static void resetMapWithAILayerInfo() {
|
||||||
synchronized (MapWithAILayerInfo.class) {
|
synchronized (MapWithAILayerInfo.class) {
|
||||||
MapWithAILayerInfo.getInstance().clear();
|
MapWithAILayerInfo.getInstance().clear();
|
||||||
|
|
Ładowanie…
Reference in New Issue