source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java@ 13631

Last change on this file since 13631 was 13631, checked in by Don-vip, 6 years ago

see #16129 - better catch of WMS ServiceExceptions

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.util.regex.Matcher;
8
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.testutils.JOSMTestRules;
12import org.openstreetmap.josm.tools.Utils;
13
14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15
16/**
17 * Unit tests for class {@link TMSCachedTileLoaderJob}.
18 */
19public class TMSCachedTileLoaderJobTest {
20
21 /**
22 * Setup tests
23 */
24 @Rule
25 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
26 public JOSMTestRules test = new JOSMTestRules();
27
28 /**
29 * Tests that {@code TMSCachedTileLoaderJob#SERVICE_EXCEPTION_PATTERN} is correct.
30 */
31 @Test
32 public void testServiceExceptionPattern() {
33 test("missing parameters ['version', 'format']",
34 "<?xml version=\"1.0\"?>\n" +
35 "<!DOCTYPE ServiceExceptionReport SYSTEM \"http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd\">\n" +
36 "<ServiceExceptionReport version=\"1.1.1\">\n" +
37 " <ServiceException>missing parameters ['version', 'format']</ServiceException>\n" +
38 "</ServiceExceptionReport>");
39 test("Parameter 'layers' contains unacceptable layer names.",
40 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\r\n" +
41 "<!DOCTYPE ServiceExceptionReport SYSTEM \"http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd\">\r\n" +
42 "<ServiceExceptionReport version=\"1.1.1\">\r\n" +
43 " <ServiceException code=\"LayerNotDefined\">\r\n" +
44 "Parameter 'layers' contains unacceptable layer names.\r\n" +
45 " </ServiceException>\r\n" +
46 "</ServiceExceptionReport>\r\n" +
47 "");
48 }
49
50 private static void test(String expected, String xml) {
51 Matcher m = TMSCachedTileLoaderJob.SERVICE_EXCEPTION_PATTERN.matcher(xml);
52 assertTrue(xml, m.matches());
53 assertEquals(expected, Utils.strip(m.group(1)));
54 }
55}
Note: See TracBrowser for help on using the repository browser.