Changeset 10973 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-09-08T00:02:03+02:00 (8 years ago)
Author:
Don-vip
Message:

see #13564 - proper management of invalid URLs in remote control handlers + add unit test

Location:
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java

    r10436 r10973  
    3131    }
    3232
    33     private static AddNodeHandler newHandler(String url) {
     33    private static AddNodeHandler newHandler(String url) throws RequestHandlerBadRequestException {
    3434        AddNodeHandler req = new AddNodeHandler();
    3535        if (url != null)
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java

    r10436 r10973  
    3131    }
    3232
    33     private static AddWayHandler newHandler(String url) {
     33    private static AddWayHandler newHandler(String url) throws RequestHandlerBadRequestException {
    3434        AddWayHandler req = new AddWayHandler();
    3535        if (url != null)
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java

    r10116 r10973  
    2828    }
    2929
    30     private static ImageryHandler newHandler(String url) {
     30    private static ImageryHandler newHandler(String url) throws RequestHandlerBadRequestException {
    3131        ImageryHandler req = new ImageryHandler();
    3232        if (url != null)
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java

    r10436 r10973  
    3636    }
    3737
    38     private static ImportHandler newHandler(String url) {
     38    private static ImportHandler newHandler(String url) throws RequestHandlerBadRequestException {
    3939        ImportHandler req = new ImportHandler();
    4040        if (url != null)
     
    4545    /**
    4646     * Non-regression test for bug #7434.
     47     * @throws Exception if any error occurs
    4748     */
    4849    @Test
    49     public void testTicket7434() {
     50    public void testTicket7434() throws Exception {
    5051        ImportHandler req = newHandler("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive");
    5152        assertEquals("http://localhost:8888/relations?relations=19711&mode=recursive", req.args.get("url"));
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java

    r10116 r10973  
    2828    }
    2929
    30     private static LoadAndZoomHandler newHandler(String url) {
     30    private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException {
    3131        LoadAndZoomHandler req = new LoadAndZoomHandler();
    3232        if (url != null)
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java

    r10116 r10973  
    2828    }
    2929
    30     private static LoadObjectHandler newHandler(String url) {
     30    private static LoadObjectHandler newHandler(String url) throws RequestHandlerBadRequestException {
    3131        LoadObjectHandler req = new LoadObjectHandler();
    3232        if (url != null)
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandlerTest.java

    r8876 r10973  
    1010import org.junit.Test;
    1111import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
     12import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
    1213
    1314/**
     
    1617public class RequestHandlerTest {
    1718
    18     Map<String, String> getRequestParameter(String url) {
     19    Map<String, String> getRequestParameter(String url) throws RequestHandlerBadRequestException {
    1920        final RequestHandler req = new RequestHandler() {
    2021            @Override
     
    4748    /**
    4849     * Test request parameter - case 1
     50     * @throws RequestHandlerBadRequestException never
    4951     */
    5052    @Test
    51     public void testRequestParameter1() {
     53    public void testRequestParameter1() throws RequestHandlerBadRequestException {
    5254        final Map<String, String> expected = new HashMap<>();
    5355        expected.put("query", "a");
     
    5860    /**
    5961     * Test request parameter - case 2
     62     * @throws RequestHandlerBadRequestException never
    6063     */
    6164    @Test
    62     public void testRequestParameter2() {
     65    public void testRequestParameter2() throws RequestHandlerBadRequestException {
    6366        assertEquals(Collections.singletonMap("query", "a&b==c"),
    6467                getRequestParameter("http://example.com/?query=a%26b==c"));
     
    6770    /**
    6871     * Test request parameter - case 3
     72     * @throws RequestHandlerBadRequestException never
    6973     */
    7074    @Test
    71     public void testRequestParameter3() {
     75    public void testRequestParameter3() throws RequestHandlerBadRequestException {
    7276        assertEquals(Collections.singleton("blue+light blue"),
    7377                getRequestParameter("http://example.com/blue+light%20blue?blue%2Blight+blue").keySet());
     
    7882     * @see <a href="http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding">
    7983     *      What every web developer must know about URL encoding</a>
     84     * @throws RequestHandlerBadRequestException never
    8085     */
    8186    @Test
    82     public void testRequestParameter4() {
     87    public void testRequestParameter4() throws RequestHandlerBadRequestException {
    8388        assertEquals(Collections.singletonMap("/?:@-._~!$'()* ,;", "/?:@-._~!$'()* ,;=="), getRequestParameter(
    8489                // CHECKSTYLE.OFF: LineLength
     
    8994    /**
    9095     * Test request parameter - case 5
     96     * @throws RequestHandlerBadRequestException never
    9197     */
    9298    @Test
    93     public void testRequestParameter5() {
     99    public void testRequestParameter5() throws RequestHandlerBadRequestException {
    94100        final Map<String, String> expected = new HashMap<>();
    95101        expected.put("space", " ");
     
    97103        assertEquals(expected, getRequestParameter("http://example.com/?space=%20&tab=%09"));
    98104    }
     105
     106    /**
     107     * Test request parameter - invalid case
     108     * @throws RequestHandlerBadRequestException always
     109     */
     110    @Test(expected = RequestHandlerBadRequestException.class)
     111    public void testRequestParameterInvalid() throws RequestHandlerBadRequestException {
     112        getRequestParameter("http://localhost:8111/load_and_zoom"+
     113                "?addtags=wikipedia:de=Wei%C3%9Fe_Gasse|maxspeed=5"+
     114                "&select=way23071688,way23076176,way23076177,"+
     115                "&left=13.739727546842&right=13.740890970188&top=51.049987191025&bottom=51.048466954325");
     116    }
    99117}
Note: See TracChangeset for help on using the changeset viewer.