kopia lustrzana https://github.com/JOSM/MapWithAI
Add test for update prod
Also, fix an intermittent test issue Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
b3444c7254
commit
7830319fb1
|
@ -21,7 +21,13 @@ public final class UpdateProd {
|
|||
// Hide constructor
|
||||
}
|
||||
|
||||
public static void doProd(int nextMinVersion) {
|
||||
/**
|
||||
* Prod user to update JOSM
|
||||
*
|
||||
* @param nextMinVersion The next version of JOSM that is supported by MapWithAI
|
||||
* @return {@code true} if an update is needed
|
||||
*/
|
||||
public static boolean doProd(int nextMinVersion) {
|
||||
if (nextMinVersion > Version.getInstance().getVersion()) {
|
||||
int doUpdate = ConditionalOptionPaneUtil.showOptionDialog(
|
||||
MapWithAIPlugin.NAME.concat(".ignore_next_version"),
|
||||
|
@ -34,10 +40,10 @@ public final class UpdateProd {
|
|||
if (doUpdate == 0) {
|
||||
OpenBrowser.displayUrl("https://josm.openstreetmap.de");
|
||||
}
|
||||
} else {
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".ignore_next_version"), null);
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".ignore_next_version.value"), null);
|
||||
return true;
|
||||
}
|
||||
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".ignore_next_version"), null);
|
||||
Config.getPref().put(MapWithAIPlugin.NAME.concat(".ignore_next_version.value"), null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.openstreetmap.josm.data.osm.AbstractPrimitive;
|
||||
import org.openstreetmap.josm.data.osm.DataSet;
|
||||
import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
||||
import org.openstreetmap.josm.data.osm.PrimitiveData;
|
||||
|
@ -10,6 +11,7 @@ import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
|||
import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
||||
import org.openstreetmap.josm.io.IllegalDataException;
|
||||
import org.openstreetmap.josm.io.OsmReader;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
/**
|
||||
* TODO remove this class in January 2019 (if required patch is pulled)
|
||||
|
@ -36,7 +38,18 @@ public class OsmReaderCustom extends OsmReader {
|
|||
@Override
|
||||
protected OsmPrimitive buildPrimitive(PrimitiveData pd) {
|
||||
final Long serverId = pd.getUniqueId();
|
||||
final OsmPrimitive p = super.buildPrimitive(pd);
|
||||
if (AbstractPrimitive.currentUniqueId() < pd.getUniqueId()) {
|
||||
Logging.error("Current id: {0} (wants {1})", AbstractPrimitive.currentUniqueId(), pd.getUniqueId());
|
||||
}
|
||||
OsmPrimitive p;
|
||||
if (pd.getUniqueId() < AbstractPrimitive.currentUniqueId()) {
|
||||
p = pd.getType().newInstance(pd.getUniqueId(), true);
|
||||
} else {
|
||||
p = pd.getType().newVersionedInstance(pd.getId(), pd.getVersion());
|
||||
}
|
||||
p.setVisible(pd.isVisible());
|
||||
p.load(pd);
|
||||
externalIdMap.put(pd.getPrimitiveId(), p);
|
||||
p.put("server_id", Long.toString(serverId));
|
||||
return p;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,8 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -10,6 +12,7 @@ import javax.swing.JMenu;
|
|||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.Durations;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -20,6 +23,9 @@ import org.openstreetmap.josm.plugins.PluginInformation;
|
|||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
|
||||
import org.openstreetmap.josm.spi.preferences.Config;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
|
@ -35,15 +41,24 @@ public class MapWithAIPluginTest {
|
|||
public MapWithAIPlugin plugin;
|
||||
|
||||
private static final String VERSION = "no-such-version";
|
||||
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
wireMock.start();
|
||||
final InputStream in = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
|
||||
info = new PluginInformation(in, "MapWithAI", null);
|
||||
info.localversion = VERSION;
|
||||
MapWithAIDataUtils.setPaintStyleUrl(
|
||||
MapWithAIDataUtils.getPaintStyleUrl().replace(Config.getUrls().getJOSMWebsite(), wireMock.baseUrl()));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
wireMock.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,6 +79,7 @@ public class MapWithAIPluginTest {
|
|||
final int dataMenuSize = dataMenu.getMenuComponentCount();
|
||||
plugin = new MapWithAIPlugin(info);
|
||||
Assert.assertEquals(dataMenuSize + 4, dataMenu.getMenuComponentCount());
|
||||
MapPaintStyles.getStyles().getStyleSources().forEach(style -> Logging.error(style.toString()));
|
||||
Assert.assertEquals(1, MapPaintStyles.getStyles().getStyleSources().parallelStream()
|
||||
.filter(source -> source.url != null && source.name.contains("MapWithAI")).count());
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.openstreetmap.josm.spi.preferences.Config;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
|
||||
/**
|
||||
* Test the update prod
|
||||
*
|
||||
* @author Taylor Smock
|
||||
*/
|
||||
public class UpdateProdTest {
|
||||
@Rule
|
||||
public JOSMTestRules rule = new JOSMTestRules().preferences();
|
||||
|
||||
@Test
|
||||
public void testDoProd() {
|
||||
String booleanKey = "message.".concat(MapWithAIPlugin.NAME.concat(".ignore_next_version"));
|
||||
String intKey = "message.".concat(MapWithAIPlugin.NAME.concat(".ignore_next_version")).concat(".value"); // "message.MapWithAI.ignore_next_version.value";
|
||||
Config.getPref().putBoolean(booleanKey, false);
|
||||
Config.getPref().putInt(intKey,
|
||||
JOptionPane.YES_OPTION);
|
||||
assertTrue(UpdateProd.doProd(Integer.MAX_VALUE));
|
||||
Config.getPref().putInt(intKey,
|
||||
JOptionPane.NO_OPTION);
|
||||
assertTrue(UpdateProd.doProd(Integer.MAX_VALUE));
|
||||
assertFalse(UpdateProd.doProd(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
|
|||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
import org.awaitility.Durations;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -14,7 +15,7 @@ import org.openstreetmap.josm.data.osm.BBox;
|
|||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
import org.openstreetmap.josm.tools.Territories;
|
||||
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
|
@ -25,12 +26,12 @@ public class MapWithAIAvailabilityTest {
|
|||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||
public JOSMTestRules test = new JOSMTestRules().projection();
|
||||
|
||||
@Rule
|
||||
public WireMockRule wireMockRule = new WireMockRule(options().usingFilesUnderDirectory("test/resources/wiremock"));
|
||||
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MapWithAIAvailability.setReleaseUrl(wireMockRule.baseUrl()
|
||||
wireMock.start();
|
||||
MapWithAIAvailability.setReleaseUrl(wireMock.baseUrl()
|
||||
+ "/facebookmicrosites/Open-Mapping-At-Facebook/master/data/rapid_releases.geojson");
|
||||
Territories.initialize();
|
||||
instance = MapWithAIAvailability.getInstance();
|
||||
|
@ -38,6 +39,11 @@ public class MapWithAIAvailabilityTest {
|
|||
await().atMost(Durations.TEN_SECONDS).until(() -> Territories.isIso3166Code("US", temp));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
wireMock.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasDataBBox() {
|
||||
Assert.assertFalse(instance.hasData(new BBox(0, 0, 0.1, 0.1)));
|
||||
|
|
Ładowanie…
Reference in New Issue