1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.util.regex.Matcher;
|
---|
8 |
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
12 | import org.openstreetmap.josm.tools.Utils;
|
---|
13 |
|
---|
14 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Unit tests for class {@link TMSCachedTileLoaderJob}.
|
---|
18 | */
|
---|
19 | public 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 | }
|
---|