mkhludnev commented on code in PR #4582:
URL: https://github.com/apache/solr/pull/4582#discussion_r3518330995


##########
solr/core/src/test/org/apache/solr/search/TestIntervalsQParserPlugin.java:
##########
@@ -0,0 +1,578 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrException;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/** Tests for {@link IntervalsQParserPlugin}. */
+public class TestIntervalsQParserPlugin extends SolrTestCaseJ4 {
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    initCore("solrconfig.xml", "schema11.xml");
+  }
+
+  @Test
+  public void testIntervalsMissingQueryReferenceThrows() throws Exception {
+    assertU(adoc("id", "1", "v_t", "hello world"));
+    assertU(commit());
+
+    // Without a "$name" query string the parser must explain the required 
syntax
+    assertQEx(
+        "intervals qparser without a $name reference should throw BAD_REQUEST",
+        "Expected syntax",
+        req("q", "{!intervals df=v_t}"),
+        SolrException.ErrorCode.BAD_REQUEST);
+  }
+
+  @Test
+  public void testIntervalsMissingJsonBodyThrows() throws Exception {
+    assertU(adoc("id", "2", "v_t", "hello world"));
+    assertU(commit());
+
+    // With a $name reference but no JSON request body at all
+    assertQEx(
+        "intervals qparser without a JSON body should throw BAD_REQUEST",
+        "No JSON request body found",
+        req("q", "{!intervals df=v_t}$myQuery"),
+        SolrException.ErrorCode.BAD_REQUEST);
+  }
+
+  @Test
+  public void testIntervalsMissingJsonQueriesKeyThrows() throws Exception {
+    assertU(adoc("id", "3", "v_t", "hello world"));
+    assertU(commit());
+
+    // JSON body present, but no top-level "json_queries" map
+    assertQEx(
+        "intervals qparser without a json_queries map should throw 
BAD_REQUEST",
+        "No 'json_queries' map found",
+        req("q", "{!intervals df=v_t}$myQuery", "json", "{params:{}}"),
+        SolrException.ErrorCode.BAD_REQUEST);
+  }
+
+  @Test
+  public void testIntervalsMissingNamedQueryThrows() throws Exception {
+    assertU(adoc("id", "4", "v_t", "hello world"));
+    assertU(commit());
+
+    // json_queries map present, but it has no entry named "myQuery"
+    assertQEx(
+        "intervals qparser with an unresolved $name reference should throw 
BAD_REQUEST",
+        "Query 'myQuery' not found in 'json_queries'",
+        req(
+            "q",
+            "{!intervals df=v_t}$myQuery",
+            "json",
+            "{json_queries:{otherQuery:{match:{query:foo}}}}"),
+        SolrException.ErrorCode.BAD_REQUEST);
+  }
+
+  @Test
+  public void testIntervalsMatchRuleMatchesDocument() throws Exception {
+    assertU(adoc("id", "10", "v_t", "foo bar"));
+    assertU(adoc("id", "11", "v_t", "baz qux"));
+    assertU(commit());
+
+    // field specified via df local param; the named json_queries entry is the 
rule object directly
+    assertQ(
+        "intervals qparser with match rule should match documents containing 
the term",
+        req(
+            "q",
+            "{!intervals df=v_t}$myQuery",
+            "json",
+            "{json_queries:{myQuery:{match:{query:foo}}}}"),
+        "//result[@numFound='1']",
+        "//doc/str[@name='id'][.='10']");
+  }
+
+  @Test
+  public void testIntervalsAllOfAnyOfNamedQuery() throws Exception {
+    assertU(adoc("id", "30", "title_t", "alpha beta gamma delta"));
+    assertU(adoc("id", "31", "title_t", "alpha beta epsilon delta"));
+    assertU(adoc("id", "32", "title_t", "alpha zeta gamma delta"));
+    assertU(commit());
+
+    assertQ(
+        "intervals qparser should support all_of with nested any_of via df 
local param",
+        req(
+            "q",
+            "{!intervals df=title_t}$second_query",

Review Comment:
   would you like this style of requests across all tests? 
   
https://github.com/apache/solr/pull/4582/changes/c1b46353fd339781ccc4a2b5f79b0ca804d95969#diff-ec02755a65648a1393267be481208643fd7d1c60834284719565033b32ce7842R185



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to