// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.io.remotecontrol.handler; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.openstreetmap.josm.JOSMFixture; import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; /** * Unit tests of {@link LoadAndZoomHandler} class. */ public class LoadAndZoomHandlerTest { /** * Rule used for tests throwing exceptions. */ @Rule public ExpectedException thrown = ExpectedException.none(); /** * Setup test. */ @BeforeClass public static void setUpBeforeClass() { JOSMFixture.createUnitTestFixture().init(true); } private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException { LoadAndZoomHandler req = new LoadAndZoomHandler(); if (url != null) req.setUrl(url); return req; } /** * Unit test for bad request - no param. * @throws Exception if any error occurs */ @Test public void testBadRequestNoParam() throws Exception { thrown.expect(RequestHandlerBadRequestException.class); thrown.expectMessage("NumberFormatException (empty String)"); newHandler(null).handle(); } /** * Unit test for bad request - invalid URL. * @throws Exception if any error occurs */ @Test public void testBadRequestInvalidUrl() throws Exception { thrown.expect(RequestHandlerBadRequestException.class); thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right"); newHandler("invalid_url").handle(); } /** * Unit test for bad request - incomplete URL. * @throws Exception if any error occurs */ @Test public void testBadRequestIncompleteUrl() throws Exception { thrown.expect(RequestHandlerBadRequestException.class); thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right"); newHandler("https://localhost").handle(); } /** * Unit test for nominal request - local data file. * @throws Exception if any error occurs */ @Test public void testNominalRequest() throws Exception { newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle(); } }