kopia lustrzana https://github.com/JOSM/MapWithAI
MapWithAIRemoteControlTest: FIXUP sonar lint
Signed-off-by: Taylor Smock <tsmock@fb.com>pull/1/head
rodzic
e8b5a1cdad
commit
db4416ad60
|
@ -2,6 +2,7 @@
|
||||||
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
||||||
|
|
||||||
import static org.awaitility.Awaitility.await;
|
import static org.awaitility.Awaitility.await;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
@ -16,6 +17,7 @@ import org.openstreetmap.josm.data.osm.BBox;
|
||||||
import org.openstreetmap.josm.gui.MainApplication;
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
||||||
|
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.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
@ -50,8 +52,8 @@ public class MapWithAIRemoteControlTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBadRequestInvalidUrl() throws Exception {
|
public void testBadRequestInvalidUrl() throws Exception {
|
||||||
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
MapWithAIRemoteControl handler = assertDoesNotThrow(() -> newHandler("https://localhost?url=invalid_url"));
|
||||||
() -> newHandler("https://localhost?url=invalid_url").handle());
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class, handler::handle);
|
||||||
assertEquals("MalformedURLException: no protocol: invalid_url", exception.getMessage());
|
assertEquals("MalformedURLException: no protocol: invalid_url", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +89,12 @@ public class MapWithAIRemoteControlTest {
|
||||||
assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
|
assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
|
||||||
.anyMatch(map -> badUrl.equals(map.getUrl())));
|
.anyMatch(map -> badUrl.equals(map.getUrl())));
|
||||||
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
||||||
assertNotEquals(badUrl, MapWithAIPreferenceHelper.getMapWithAIUrl());
|
assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().stream().map(MapWithAIInfo::getUrl)
|
||||||
|
.noneMatch(badUrl::equals));
|
||||||
|
|
||||||
final String badUrl2 = "NothingToSeeHere";
|
final String badUrl2 = "NothingToSeeHere";
|
||||||
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
final MapWithAIRemoteControl handler = newHandler("https://localhost?url=" + Utils.encodeUrl(badUrl2));
|
||||||
() -> newHandler("https://localhost?url=" + Utils.encodeUrl(badUrl2)).handle());
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class, handler::handle);
|
||||||
assertEquals("MalformedURLException: no protocol: " + badUrl2, exception.getMessage());
|
assertEquals("MalformedURLException: no protocol: " + badUrl2, exception.getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -109,11 +112,9 @@ public class MapWithAIRemoteControlTest {
|
||||||
assertEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
|
assertEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
|
||||||
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
||||||
assertNotEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
|
assertNotEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
|
||||||
|
final MapWithAIRemoteControl handler = assertDoesNotThrow(() -> newHandler(
|
||||||
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
"http://127.0.0.1:8111/mapwithai?bbox=" + getTestBBox().toStringCSV(",") + "&max_obj=BAD_VALUE"));
|
||||||
() -> newHandler(
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class, handler::handle);
|
||||||
"http://127.0.0.1:8111/mapwithai?bbox=" + getTestBBox().toStringCSV(",") + "&max_obj=BAD_VALUE")
|
|
||||||
.handle());
|
|
||||||
assertEquals("NumberFormatException (For input string: \"BAD_VALUE\")", exception.getMessage());
|
assertEquals("NumberFormatException (For input string: \"BAD_VALUE\")", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +135,9 @@ public class MapWithAIRemoteControlTest {
|
||||||
|
|
||||||
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
||||||
BBox temp2 = new BBox(39.0621223, -108.4625421, 39.0633059, -108.4594728);
|
BBox temp2 = new BBox(39.0621223, -108.4625421, 39.0633059, -108.4594728);
|
||||||
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
final MapWithAIRemoteControl handler = assertDoesNotThrow(() -> newHandler(
|
||||||
() -> newHandler(
|
"http://127.0.0.1:8111/mapwithai?bbox={bbox}".replace("{bbox}", temp2.toStringCSV(","))));
|
||||||
"http://127.0.0.1:8111/mapwithai?bbox={bbox}".replace("{bbox}", temp2.toStringCSV(",")))
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class, handler::handle);
|
||||||
.handle());
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Bad bbox: 39.0621223,-108.4625421,39.0633059,-108.4594728 (converted to Bounds[-108.4625421,39.0621223,-108.4594728,39.0633059])",
|
"Bad bbox: 39.0621223,-108.4625421,39.0633059,-108.4594728 (converted to Bounds[-108.4625421,39.0621223,-108.4594728,39.0633059])",
|
||||||
exception.getMessage());
|
exception.getMessage());
|
||||||
|
|
Ładowanie…
Reference in New Issue