|
21 | 21 | */
|
22 | 22 | package org.exist.xquery;
|
23 | 23 |
|
24 |
| -import org.exist.test.ExistXmldbEmbeddedServer; |
25 |
| -import org.junit.ClassRule; |
| 24 | +import org.exist.EXistException; |
| 25 | +import org.exist.security.PermissionDeniedException; |
| 26 | +import org.exist.test.XQueryCompilationTest; |
26 | 27 | import org.junit.Test;
|
27 |
| -import org.xmldb.api.base.XMLDBException; |
28 |
| -import org.xmldb.api.modules.XQueryService; |
29 | 28 |
|
30 |
| -import static org.junit.Assert.*; |
| 29 | +import static org.exist.test.XQueryAssertions.assertXQStaticError; |
31 | 30 |
|
32 | 31 | /**
|
33 | 32 | * Ensure tests for unknown atomic types are reported with location information
|
34 | 33 | * https://github.com/eXist-db/exist/issues/3518
|
35 | 34 | *
|
36 | 35 | * @author <a href="mailto:[email protected]">Juri Leino</a>
|
37 | 36 | */
|
38 |
| -public class UnknownAtomicTypeTest { |
39 |
| - @ClassRule |
40 |
| - public static final ExistXmldbEmbeddedServer existEmbeddedServer = new ExistXmldbEmbeddedServer(true, true, true); |
41 |
| - |
| 37 | +public class UnknownAtomicTypeTest extends XQueryCompilationTest { |
42 | 38 | @Test
|
43 |
| - public void letVariable() throws XMLDBException { |
44 |
| - final String query = "let $x as y := 0 return $x"; |
45 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 11]"; |
46 |
| - assertCompilationError(query, error); |
| 39 | + public void letVariable() throws EXistException, PermissionDeniedException { |
| 40 | + final String query = "let $x as a := 0 return $x"; |
| 41 | + final String error = "Unknown simple type a"; |
| 42 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 11, error, compileQuery(query)); |
47 | 43 | }
|
48 | 44 |
|
49 | 45 | @Test
|
50 |
| - public void functionReturnType() throws XMLDBException { |
51 |
| - final String query = "function () as y { () }"; |
52 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 16]"; |
53 |
| - assertCompilationError(query, error); |
| 46 | + public void functionReturnType() throws EXistException, PermissionDeniedException { |
| 47 | + final String query = "function () as b { () }"; |
| 48 | + final String error = "Unknown simple type b"; |
| 49 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 16, error, compileQuery(query)); |
54 | 50 | }
|
55 | 51 |
|
56 | 52 | @Test
|
57 |
| - public void functionParameterType() throws XMLDBException { |
58 |
| - final String query = "function ($x as y) { $x }"; |
59 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 17]"; |
60 |
| - assertCompilationError(query, error); |
| 53 | + public void functionParameterType() throws EXistException, PermissionDeniedException { |
| 54 | + final String query = "function ($x as c) { $x }"; |
| 55 | + final String error = "Unknown simple type c"; |
| 56 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 17, error, compileQuery(query)); |
61 | 57 | }
|
62 | 58 |
|
63 | 59 | @Test
|
64 |
| - public void instanceOf() throws XMLDBException { |
65 |
| - final String query = "1 instance of y"; |
66 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 15]"; |
67 |
| - assertCompilationError(query, error); |
| 60 | + public void instanceOf() throws EXistException, PermissionDeniedException { |
| 61 | + final String query = "1 instance of d"; |
| 62 | + final String error = "Unknown simple type d"; |
| 63 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 15, error, compileQuery(query)); |
68 | 64 | }
|
69 | 65 |
|
70 | 66 | @Test
|
71 |
| - public void treatAs() throws XMLDBException { |
72 |
| - final String query = "1 treat as y"; |
73 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 12]"; |
74 |
| - assertCompilationError(query, error); |
| 67 | + public void treatAs() throws EXistException, PermissionDeniedException { |
| 68 | + final String query = "1 treat as e"; |
| 69 | + final String error = "Unknown simple type e"; |
| 70 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 12, error, compileQuery(query)); |
75 | 71 | }
|
76 | 72 |
|
77 | 73 | @Test
|
78 |
| - public void castAs() throws XMLDBException { |
79 |
| - final String query = "1 cast as y"; |
80 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 11]"; |
81 |
| - assertCompilationError(query, error); |
| 74 | + public void castAs() throws EXistException, PermissionDeniedException { |
| 75 | + final String query = "1 cast as f"; |
| 76 | + final String error = "Unknown simple type f"; |
| 77 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 11, error, compileQuery(query)); |
82 | 78 | }
|
83 | 79 |
|
84 | 80 | @Test
|
85 |
| - public void castableAs() throws XMLDBException { |
86 |
| - final String query = "1 castable as y"; |
87 |
| - final String error = "err:XPST0051 Unknown simple type y [at line 1, column 15]"; |
88 |
| - assertCompilationError(query, error); |
89 |
| - } |
90 |
| - |
91 |
| - private void assertCompilationError(final String query, final String error) throws XMLDBException { |
92 |
| - final XQueryService service = (XQueryService)existEmbeddedServer.getRoot().getService("XQueryService", "1.0"); |
93 |
| - |
94 |
| - try { |
95 |
| - service.compile(query); |
96 |
| - fail("no XMLDBException was thrown during compilation."); |
97 |
| - } catch (XMLDBException ex) { |
98 |
| - assertEquals( error, ex.getMessage() ); |
99 |
| - } |
| 81 | + public void castableAs() throws EXistException, PermissionDeniedException { |
| 82 | + final String query = "1 castable as g"; |
| 83 | + final String error = "Unknown simple type g"; |
| 84 | + assertXQStaticError(ErrorCodes.XPST0051, 1, 15, error, compileQuery(query)); |
100 | 85 | }
|
101 | 86 | }
|
0 commit comments