LUCENE-7252: add TestCoreParser.testTermQueryEmptyXML test

This commit is contained in:
Christine Poerschke 2016-04-26 17:39:33 +01:00
parent 9166647918
commit 9c69c4cf12
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<TermQuery fieldName="contents"></TermQuery>

View File

@ -66,6 +66,11 @@ public class TestCoreParser extends LuceneTestCase {
dumpResults("TermQuery", q, 5);
}
public void testTermQueryEmptyXML() throws ParserException, IOException {
parseShouldFail("TermQueryEmpty.xml",
"TermQuery has no text");
}
public void testTermsQueryXML() throws ParserException, IOException {
Query q = parse("TermsQuery.xml");
dumpResults("TermsQuery", q, 5);
@ -207,6 +212,20 @@ public class TestCoreParser extends LuceneTestCase {
return indexData().searcher;
}
protected void parseShouldFail(String xmlFileName, String expectedParserExceptionMessage) throws IOException {
Query q = null;
ParserException pe = null;
try {
q = parse(xmlFileName);
} catch (ParserException e) {
pe = e;
}
assertNull("for "+xmlFileName+" unexpectedly got "+q, q);
assertNotNull("expected a ParserException for "+xmlFileName, pe);
assertEquals("expected different ParserException for "+xmlFileName,
expectedParserExceptionMessage, pe.getMessage());
}
protected Query parse(String xmlFileName) throws ParserException, IOException {
try (InputStream xmlStream = TestCoreParser.class.getResourceAsStream(xmlFileName)) {
assertNotNull("Test XML file " + xmlFileName + " cannot be found", xmlStream);