Skip to content

Commit 42c9653

Browse files
line-oadamretter
authored andcommitted
[test] refactor and improve UnknownAtomicTypeTest
1 parent d351838 commit 42c9653

File tree

1 file changed

+33
-48
lines changed

1 file changed

+33
-48
lines changed

exist-core/src/test/java/org/exist/xquery/UnknownAtomicTypeTest.java

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,81 +21,66 @@
2121
*/
2222
package org.exist.xquery;
2323

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;
2627
import org.junit.Test;
27-
import org.xmldb.api.base.XMLDBException;
28-
import org.xmldb.api.modules.XQueryService;
2928

30-
import static org.junit.Assert.*;
29+
import static org.exist.test.XQueryAssertions.assertXQStaticError;
3130

3231
/**
3332
* Ensure tests for unknown atomic types are reported with location information
3433
* https://github.com/eXist-db/exist/issues/3518
3534
*
3635
* @author <a href="mailto:[email protected]">Juri Leino</a>
3736
*/
38-
public class UnknownAtomicTypeTest {
39-
@ClassRule
40-
public static final ExistXmldbEmbeddedServer existEmbeddedServer = new ExistXmldbEmbeddedServer(true, true, true);
41-
37+
public class UnknownAtomicTypeTest extends XQueryCompilationTest {
4238
@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));
4743
}
4844

4945
@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));
5450
}
5551

5652
@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));
6157
}
6258

6359
@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));
6864
}
6965

7066
@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));
7571
}
7672

7773
@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));
8278
}
8379

8480
@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));
10085
}
10186
}

0 commit comments

Comments
 (0)