add. test for %.
Change-Id: Ie58020266ceb558fab9a7d86ce816c294304dfb8
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
index 3fcfba3..b366594 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
@@ -514,23 +514,6 @@
@Test
public void testOPPROX () throws JsonProcessingException, IOException {
- // test unknown proximity options:
-
- query = "ab /+w1:2u,p cd";
- qs.setQuery(query, "cosmas2");
- res = mapper.readTree(qs.toJSON());
- //System.out.printf("Query '%s': returns: '%s'.\n", query, res.toPrettyString()) ;
- //System.out.printf("Query '%s': context: '%s'.\n", query, res.get("@context").toPrettyString()) ;
- //System.out.printf("Query '%s': errors : '%s'.\n", query, res.get("errors").toPrettyString()) ;
- System.out.printf("Query '%s': errorCode: '%s'.\n", query, res.get("errors").get(0).get(0).toPrettyString()) ;
- System.out.printf("Query '%s': errorText : '%s'.\n", query, res.get("errors").get(0).get(1).toPrettyString()) ;
- System.out.printf("Query '%s': errorPos : '%s'.\n", query, res.get("errors").get(0).get(2).toPrettyString()) ;
-
- assertTrue("Error code expected!",!res.get("errors").isNull());
- assertTrue("Error code expected!", res.get("errors").get(0).get(0).isInt());
- assertEquals(StatusCodes.ERR_PROX_WRONG_CHARS, res.get("errors").get(0).get(0).asInt());
-
-
query = "Sonne /+w1:4 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
@@ -648,31 +631,95 @@
.asText());
assertFalse(res.at("/query/inOrder").asBoolean());
- // 15.01.24/FB: checking syntax error detectiong:
+ // -- check exclude operator -- //
+
+ query = "Sonne %-w1:2 Sterne";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+
+ /*
+ System.out.printf("Query '%s': returns: '%s'.\n", query, res.toPrettyString()) ;
+ System.out.printf("[0]: '%s'.\n", res.at("/query/distances").get(0).get("boundary").toPrettyString());
+ System.out.printf("@type: '%s'.\n", res.at("/query/distances").get(0).get("@type").asText());
+ System.out.printf("exclude: '%s'.\n", res.at("/query/distances").get(0).get("exclude").asText());
+ System.out.printf("key: '%s'.\n", res.at("/query/distances").get(0).get("key").asText());
+ */
+
+ assertEquals("cosmas:distance", res.at("/query/distances").get(0).get("@type").asText());
+ assertTrue( res.at("/query/distances").get(0).get("exclude").asBoolean());
+ assertEquals("w", res.at("/query/distances").get(0).get("key").asText());
+
+ // 15.01.24/FB: checking syntax error:
query = "Sonne /+w Mond"; // distance value missing.
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertTrue(res.get("errors") != null);
+ //System.out.printf("Query '%s': errors : '%s'.\n", query, res.get("errors").toPrettyString()) ;
+ assertEquals(StatusCodes.ERR_PROX_VAL_NULL, res.get("errors").get(0).get(0).asInt());
query = "Sonne /+2sw Mond"; // 2 distance types instead of 1.
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
-
+
assertTrue(res.get("errors") != null);
+ //System.out.printf("Query '%s': errors : '%s'.\n", query, res.get("errors").toPrettyString()) ;
+ assertEquals(StatusCodes.ERR_PROX_MEAS_TOOGREAT, res.get("errors").get(0).get(0).asInt());
query = "Sonne /+2s- Mond"; // 2 distance directions instead of 1.
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertTrue(res.get("errors") != null);
-
+ //System.out.printf("Query '%s': errors : '%s'.\n", query, res.get("errors").toPrettyString()) ;
+ assertEquals(StatusCodes.ERR_PROX_DIR_TOOGREAT, res.get("errors").get(0).get(0).asInt());
+
query = "Sonne /+2s7 Mond"; // 2 distance values instead of 1.
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertTrue(res.get("errors") != null);
+ //System.out.printf("Query '%s': errors : '%s'.\n", query, res.get("errors").toPrettyString()) ;
+ assertEquals(StatusCodes.ERR_PROX_VAL_TOOGREAT, res.get("errors").get(0).get(0).asInt());
+
+ // tests for error messages for unknown proximity options:
+ // 29.05.24/FB
+
+ query = "ab /+w1:2u,p cd";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+
+ assertTrue("Error code expected!",!res.get("errors").isNull());
+ assertEquals(StatusCodes.ERR_PROX_WRONG_CHARS, res.get("errors").get(0).get(0).asInt());
+
+ query = "ab %-w1:2,2su cd";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+
+ assertTrue("Error code expected!",!res.get("errors").isNull());
+ assertEquals(StatusCodes.ERR_PROX_WRONG_CHARS, res.get("errors").get(0).get(0).asInt());
+
+ query = "ab /w1:2s cd";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+
+ //System.out.printf("Query '%s': context: '%s'.\n", query, res.get("@context").toPrettyString()) ;
+ //System.out.printf("Query '%s': errors : '%s'.\n", query, res.get("errors").toPrettyString()) ;
+ //System.out.printf("Query '%s': errorCode: '%s'.\n", query, res.get("errors").get(0).get(0).toPrettyString()) ;
+ //System.out.printf("Query '%s': errorText : '%s'.\n", query, res.get("errors").get(0).get(1).toPrettyString()) ;
+ //System.out.printf("Query '%s': errorPos : '%s'.\n", query, res.get("errors").get(0).get(2).toPrettyString()) ;
+
+ assertTrue("Error code expected!", res.get("errors") != null);
+ assertEquals(StatusCodes.ERR_PROX_MEAS_TOOGREAT, res.get("errors").get(0).get(0).asInt());
+
+ query = "Sonne %-w1:2,+2su Galaxien";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+
+ assertTrue("Error code expected!", res.get("errors") != null);
+ assertEquals(StatusCodes.ERR_PROX_WRONG_CHARS, res.get("errors").get(0).get(0).asInt());
+
}