Apache Solr open-source search software
LUCENE-6945: factor out TestCorePlus(Queries|Extensions)Parser from TestParser
Christine Poerschke3064db4d7376
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 7d06b8a6922..629608a7393 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -190,6 +190,9 @@ Other* LUCENE-6925: add ForceMergePolicy class in test-framework(Christine Poerschke)+* LUCENE-6945: factor out TestCorePlus(Queries|Extensions)Parser from+ TestParser (Christine Poerschke)+======================= Lucene 5.4.0 =======================New Featuresdiff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCorePlusExtensionsParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCorePlusExtensionsParser.javanew file mode 100644index 00000000000..4af97bd4abf--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCorePlusExtensionsParser.java@@ -0,0 +1,47 @@+package org.apache.lucene.queryparser.xml;++/*+ * 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.+ */++import org.apache.lucene.search.Query;++public class TestCorePlusExtensionsParser extends TestCorePlusQueriesParser {++ private CoreParser corePlusExtensionsParser;++ public void testFuzzyLikeThisQueryXML() throws Exception {+ Query q = parse("FuzzyLikeThisQuery.xml");+ //show rewritten fuzzyLikeThisQuery - see what is being matched on+ if (VERBOSE) {+ System.out.println(rewrite(q));+ }+ dumpResults("FuzzyLikeThis", q, 5);+ }++ //================= Helper methods ===================================++ @Override+ protected CoreParser coreParser() {+ if (corePlusExtensionsParser == null) {+ corePlusExtensionsParser = new CorePlusExtensionsParser(+ super.defaultField(),+ super.analyzer());+ }+ return corePlusExtensionsParser;+ }++}diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCorePlusQueriesParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCorePlusQueriesParser.javanew file mode 100644index 00000000000..0aa16ed8cc2--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCorePlusQueriesParser.java@@ -0,0 +1,48 @@+package org.apache.lucene.queryparser.xml;++/*+ * 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.+ */++import org.apache.lucene.search.Query;++public class TestCorePlusQueriesParser extends TestParser {++ private CoreParser corePlusQueriesParser;++ public void testLikeThisQueryXML() throws Exception {+ Query q = parse("LikeThisQuery.xml");+ dumpResults("like this", q, 5);+ }++ public void testBoostingQueryXML() throws Exception {+ Query q = parse("BoostingQuery.xml");+ dumpResults("boosting ", q, 5);+ }++ //================= Helper methods ===================================++ @Override+ protected CoreParser coreParser() {+ if (corePlusQueriesParser == null) {+ corePlusQueriesParser = new CorePlusQueriesParser(+ super.defaultField(),+ super.analyzer());+ }+ return corePlusQueriesParser;+ }++}diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.javaindex 0c3f822dc92..ae19dc6ae3f 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java@@ -47,6 +47,7 @@ import java.nio.charset.StandardCharsets;public class TestParser extends LuceneTestCase {+ final private static String defaultField = "contents";private static Analyzer analyzer;private static CoreParser coreParser;private static Directory dir;@@ -58,7 +59,7 @@ public class TestParser extends LuceneTestCase {// TODO: rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);//initialize the parser- coreParser = new CorePlusExtensionsParser("contents", analyzer);+ coreParser = new CoreParser(defaultField, analyzer);BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));@@ -136,25 +137,6 @@ public class TestParser extends LuceneTestCase {assertEquals("UserInputQueryCustomField should produce 0 result ", 0, h);}- public void testLikeThisQueryXML() throws Exception {- Query q = parse("LikeThisQuery.xml");- dumpResults("like this", q, 5);- }-- public void testBoostingQueryXML() throws Exception {- Query q = parse("BoostingQuery.xml");- dumpResults("boosting ", q, 5);- }-- public void testFuzzyLikeThisQueryXML() throws Exception {- Query q = parse("FuzzyLikeThisQuery.xml");- //show rewritten fuzzyLikeThisQuery - see what is being matched on- if (VERBOSE) {- System.out.println(q.rewrite(reader));- }- dumpResults("FuzzyLikeThis", q, 5);- }-public void testBoostingTermQueryXML() throws Exception {Query q = parse("BoostingTermQuery.xml");dumpResults("BoostingTermQuery", q, 5);@@ -187,6 +169,10 @@ public class TestParser extends LuceneTestCase {//================= Helper methods ===================================+ protected String defaultField() {+ return defaultField;+ }+protected Analyzer analyzer() {return analyzer;}@@ -195,14 +181,18 @@ public class TestParser extends LuceneTestCase {return coreParser;}- private Query parse(String xmlFileName) throws ParserException, IOException {+ protected Query parse(String xmlFileName) throws ParserException, IOException {InputStream xmlStream = TestParser.class.getResourceAsStream(xmlFileName);Query result = coreParser().parse(xmlStream);xmlStream.close();return result;}- private void dumpResults(String qType, Query q, int numDocs) throws IOException {+ protected Query rewrite(Query q) throws IOException {+ return q.rewrite(reader);+ }++ protected void dumpResults(String qType, Query q, int numDocs) throws IOException {if (VERBOSE) {System.out.println("TEST: query=" + q);}