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.TreeSet;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.openstreetmap.josm.data.StructUtils;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||
|
@ -62,7 +63,16 @@ public class MapWithAILayerInfo {
|
|||
public static MapWithAILayerInfo getInstance() {
|
||||
synchronized (DEFAULT_LAYER_SITES) {
|
||||
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;
|
||||
|
@ -89,8 +99,8 @@ public class MapWithAILayerInfo {
|
|||
return Config.getPref().putList(CONFIG_PREFIX + "layers.sites", new ArrayList<>(sites));
|
||||
}
|
||||
|
||||
private MapWithAILayerInfo() {
|
||||
load(false);
|
||||
private MapWithAILayerInfo(FinishListener listener) {
|
||||
load(false, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class MapWithAIPluginTest {
|
||||
@Rule
|
||||
@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 MapWithAIPlugin plugin;
|
||||
|
|
|
@ -24,7 +24,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class DownloadMapWithAITaskTest {
|
||||
@Rule
|
||||
@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
|
||||
public void testDownloadOsmServerReaderDownloadParamsBoundsProgressMonitor()
|
||||
|
|
|
@ -37,7 +37,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class GetDataRunnableTest {
|
||||
@Rule
|
||||
@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) {
|
||||
return getDefaultMapWithAIAPIForTest(wireMock, url, "https://www.mapwith.ai");
|
||||
|
|
|
@ -32,7 +32,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class MapWithAIActionTest {
|
||||
@Rule
|
||||
@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;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MapWithAIAvailabilityTest {
|
|||
|
||||
@Rule
|
||||
@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
|
||||
public void setUp() {
|
||||
|
|
|
@ -58,8 +58,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class MapWithAILayerTest {
|
||||
@Rule
|
||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||
public JOSMTestRules test = new MapWithAITestRules().wiremock().preferences().main().projection().fakeAPI()
|
||||
.territories();
|
||||
public JOSMTestRules test = new MapWithAITestRules().sources().wiremock().preferences().main().projection()
|
||||
.fakeAPI().territories();
|
||||
|
||||
MapWithAILayer layer;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MapWithAIRemoteControlTest {
|
|||
*/
|
||||
@Rule
|
||||
@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 {
|
||||
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.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
@ -41,7 +42,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class MapWithAIUploadHookTest {
|
||||
@Rule
|
||||
@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 OsmDataLayer osmLayer;
|
||||
private MapWithAILayer aiLayer;
|
||||
|
|
|
@ -39,7 +39,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||
public class CreateConnectionsCommandTest {
|
||||
@Rule
|
||||
@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
|
||||
|
|
|
@ -52,7 +52,7 @@ public class MapWithAIAddComandTest {
|
|||
|
||||
@Rule
|
||||
@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
|
||||
public void setUp() {
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
|||
|
||||
public class ESRISourceReaderTest {
|
||||
@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
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.openstreetmap.josm.io.OsmApi;
|
|||
import org.openstreetmap.josm.io.OsmApiInitializationException;
|
||||
import org.openstreetmap.josm.io.OsmTransferCanceledException;
|
||||
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.data.mapwithai.MapWithAIInfo;
|
||||
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.verification.LoggedRequest;
|
||||
|
||||
import mockit.Mock;
|
||||
import mockit.MockUp;
|
||||
import mockit.integration.TestRunnerDecorator;
|
||||
|
||||
public class MapWithAITestRules extends JOSMTestRules {
|
||||
|
@ -89,8 +90,6 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")
|
||||
.extensions(new WireMockUrlTransformer()).dynamicPort());
|
||||
wireMock.start();
|
||||
resetMapWithAILayerInfo();
|
||||
setupMapWithAILayerInfo(wireMock);
|
||||
MapWithAIDataUtils.setPaintStyleUrl(MapWithAIDataUtils.getPaintStyleUrl()
|
||||
.replace(Config.getUrls().getJOSMWebsite(), wireMock.baseUrl()));
|
||||
currentReleaseUrl = DataAvailability.getReleaseUrl();
|
||||
|
@ -107,8 +106,6 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
}
|
||||
return null;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
MapWithAILayerInfo.getInstance().getLayers()
|
||||
.forEach(l -> l.setUrl(l.getUrl().replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/")));
|
||||
try {
|
||||
OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE);
|
||||
} catch (OsmTransferCanceledException | OsmApiInitializationException e) {
|
||||
|
@ -119,6 +116,15 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
AtomicBoolean finished = new AtomicBoolean();
|
||||
MapWithAILayerInfo.getInstance().load(false, () -> finished.set(true));
|
||||
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) {
|
||||
currentExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
|
@ -137,10 +143,10 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
List<LoggedRequest> requests = wireMock.findUnmatchedRequests().getRequests();
|
||||
requests.forEach(r -> Logging.error(r.getAbsoluteUrl()));
|
||||
assertTrue(requests.isEmpty());
|
||||
resetMapWithAILayerInfo();
|
||||
DataAvailability.setReleaseUrl(currentReleaseUrl);
|
||||
Config.getPref().put("osm-server.url", null);
|
||||
MapWithAILayerInfo.setImageryLayersSites(sourceSites);
|
||||
resetMapWithAILayerInfo();
|
||||
}
|
||||
if (workerExceptions) {
|
||||
Thread.setDefaultUncaughtExceptionHandler(currentExceptionHandler);
|
||||
|
@ -148,15 +154,6 @@ public class MapWithAITestRules extends JOSMTestRules {
|
|||
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() {
|
||||
synchronized (MapWithAILayerInfo.class) {
|
||||
MapWithAILayerInfo.getInstance().clear();
|
||||
|
|
Ładowanie…
Reference in New Issue