Add exception tests
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java
index 92f74e5..bef19a1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java
@@ -55,7 +55,10 @@
}
@Override
- public void process(String query) throws QueryException {
+ public void process(String query) throws QueryException {
+ if ((query == null) || query.isEmpty())
+ throw new QueryException(27, "An empty query is unsupported.");
+
CQLNode cqlNode = parseQuerytoCQLNode(query);
parseCQLNode(cqlNode);
ObjectMapper mapper = new ObjectMapper();
diff --git a/src/test/java/CQLTest.java b/src/test/java/CQLTest.java
index df48e52..1f7a88b 100644
--- a/src/test/java/CQLTest.java
+++ b/src/test/java/CQLTest.java
@@ -13,6 +13,45 @@
String query;
String version ="1.2";
+
+ @Test
+ public void testExceptions() throws CQLParseException, IOException {
+ query = "(Kuh) prox (Germ) ";
+ try {
+ CQLTree cqlTree = new CQLTree(query, version);
+ } catch (QueryException e) {
+ assertEquals(48,e.getErrorCode());
+ }
+
+ query = "(Kuh) or/rel.combine=sum (Germ) ";
+ try {
+ CQLTree cqlTree = new CQLTree(query, version);
+ }catch (QueryException e) {
+ assertEquals(20,e.getErrorCode());
+ }
+
+ query = "dc.title any Germ ";
+ try {
+ CQLTree cqlTree = new CQLTree(query, version);
+ } catch (QueryException e) {
+ assertEquals(16,e.getErrorCode());
+ }
+
+ query = "cql.serverChoice any Germ ";
+ try {
+ CQLTree cqlTree = new CQLTree(query, version);
+ } catch (QueryException e) {
+ assertEquals(19,e.getErrorCode());
+ }
+
+ query = "";
+ try {
+ CQLTree cqlTree = new CQLTree(query, version);
+ } catch (QueryException e) {
+ assertEquals(27,e.getErrorCode());
+ }
+ }
+
@Test
public void testBooleanQuery() throws CQLParseException, IOException, QueryException{
query="((Sonne) or (Mond)) and (scheint)";