LUCENE-6907: make TestParser extendable, rename lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/NumericRangeQueryQuery.xml to NumericRangeQuery.xml

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1718427 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christine Poerschke 2015-12-07 17:23:40 +00:00
parent 933a753aca
commit 5ee9dd5b7d
3 changed files with 21 additions and 7 deletions

View File

@ -146,6 +146,10 @@ Other
* LUCENE-6923: Fix RamUsageEstimator to access private fields inside
AccessController block for computing size. (Robert Muir)
* LUCENE-6907: make TestParser extendable, rename test/.../xml/
NumericRangeQueryQuery.xml to NumericRangeQuery.xml
(Christine Poerschke)
======================= Lucene 5.4.0 =======================
New Features

View File

@ -50,7 +50,8 @@ import java.util.List;
public class TestParser extends LuceneTestCase {
private static CoreParser builder;
private static Analyzer analyzer;
private static CoreParser coreParser;
private static Directory dir;
private static IndexReader reader;
private static IndexSearcher searcher;
@ -58,9 +59,9 @@ public class TestParser extends LuceneTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
// TODO: rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):
Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
//initialize the parser
builder = new CorePlusExtensionsParser("contents", analyzer);
coreParser = new CorePlusExtensionsParser("contents", analyzer);
BufferedReader d = new BufferedReader(new InputStreamReader(
TestParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));
@ -92,7 +93,8 @@ public class TestParser extends LuceneTestCase {
reader = null;
searcher = null;
dir = null;
builder = null;
coreParser = null;
analyzer = null;
}
public void testSimpleXML() throws ParserException, IOException {
@ -181,16 +183,24 @@ public class TestParser extends LuceneTestCase {
dumpResults("Nested Boolean query", q, 5);
}
public void testNumericRangeQueryQueryXML() throws ParserException, IOException {
Query q = parse("NumericRangeQueryQuery.xml");
public void testNumericRangeQueryXML() throws ParserException, IOException {
Query q = parse("NumericRangeQuery.xml");
dumpResults("NumericRangeQuery", q, 5);
}
//================= Helper methods ===================================
protected Analyzer analyzer() {
return analyzer;
}
protected CoreParser coreParser() {
return coreParser;
}
private Query parse(String xmlFileName) throws ParserException, IOException {
InputStream xmlStream = TestParser.class.getResourceAsStream(xmlFileName);
Query result = builder.parse(xmlStream);
Query result = coreParser().parse(xmlStream);
xmlStream.close();
return result;
}