mirror of https://github.com/apache/lucene.git
SOLR-8388: more TestSolrQueryResponse.java tests; add SolrReturnFields.toString method, ReturnFieldsTest.testToString test;
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1720160 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
58bf523941
commit
fc09a4729f
|
@ -304,6 +304,7 @@ Other Changes
|
|||
* SOLR-8305: replace LatLonType.getValueSource's QParser use (Christine Poerschke)
|
||||
|
||||
* SOLR-8388: factor out response/TestSolrQueryResponse.java from servlet/ResponseHeaderTest.java
|
||||
more TestSolrQueryResponse.java tests; add SolrReturnFields.toString method, ReturnFieldsTest.testToString test;
|
||||
(Christine Poerschke)
|
||||
|
||||
* SOLR-8383: SolrCore.java + QParserPlugin.java container initialCapacity tweaks
|
||||
|
|
|
@ -447,4 +447,18 @@ public class SolrReturnFields extends ReturnFields {
|
|||
{
|
||||
return transformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("SolrReturnFields=(");
|
||||
sb.append("globs="); sb.append(globs);
|
||||
sb.append(",fields="); sb.append(fields);
|
||||
sb.append(",okFieldNames="); sb.append(okFieldNames);
|
||||
sb.append(",reqFieldNames="); sb.append(reqFieldNames);
|
||||
sb.append(",transformer="); sb.append(transformer);
|
||||
sb.append(",wantsScore="); sb.append(_wantsScore);
|
||||
sb.append(",wantsAllFields="); sb.append(_wantsAllFields);
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,52 @@ package org.apache.solr.response;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ArithmeticException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
import org.apache.solr.search.ReturnFields;
|
||||
import org.apache.solr.search.SolrReturnFields;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestSolrQueryResponse extends LuceneTestCase {
|
||||
|
||||
@Test
|
||||
public void testName() throws Exception {
|
||||
assertEquals("SolrQueryResponse.NAME value changed", "response", SolrQueryResponse.NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValues() throws Exception {
|
||||
final SolrQueryResponse response = new SolrQueryResponse();
|
||||
assertEquals("values initially not empty", 0, response.getValues().size());
|
||||
// initially empty, then add something
|
||||
final NamedList<Object> newValue = new SimpleOrderedMap<>();
|
||||
newValue.add("key1", "value1");
|
||||
response.setAllValues(newValue);
|
||||
assertEquals("values new value", newValue, response.getValues());
|
||||
response.add("key2", "value2");
|
||||
{
|
||||
final Iterator<Map.Entry<String,Object>> it = response.getValues().iterator();
|
||||
assertTrue(it.hasNext());
|
||||
final Map.Entry<String,Object> entry1 = it.next();
|
||||
assertEquals("key1", entry1.getKey());
|
||||
assertEquals("value1", entry1.getValue());
|
||||
assertTrue(it.hasNext());
|
||||
final Map.Entry<String,Object> entry2 = it.next();
|
||||
assertEquals("key2", entry2.getKey());
|
||||
assertEquals("value2", entry2.getValue());
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToLog() throws Exception {
|
||||
final SolrQueryResponse response = new SolrQueryResponse();
|
||||
|
@ -63,6 +98,17 @@ public class TestSolrQueryResponse extends LuceneTestCase {
|
|||
assertEquals("xyz789 key1=value1 key2=value2", response.getToLogAsString("xyz789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnFields() throws Exception {
|
||||
final SolrQueryResponse response = new SolrQueryResponse();
|
||||
final ReturnFields defaultReturnFields = new SolrReturnFields();
|
||||
assertEquals("returnFields initial value", defaultReturnFields.toString(), response.getReturnFields().toString());
|
||||
final SolrReturnFields newValue = new SolrReturnFields((random().nextBoolean()
|
||||
? SolrReturnFields.SCORE : "value"), null);
|
||||
response.setReturnFields(newValue);
|
||||
assertEquals("returnFields new value", newValue.toString(), response.getReturnFields().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddHttpHeader() {
|
||||
SolrQueryResponse response = new SolrQueryResponse();
|
||||
|
@ -191,4 +237,23 @@ public class TestSolrQueryResponse extends LuceneTestCase {
|
|||
assertEquals("key2", response.httpHeaders().next().getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testException() throws Exception {
|
||||
final SolrQueryResponse response = new SolrQueryResponse();
|
||||
assertEquals("exception initial value", null, response.getException());
|
||||
final Exception newValue = (random().nextBoolean()
|
||||
? (random().nextBoolean() ? new ArithmeticException() : new IOException()) : null);
|
||||
response.setException(newValue);
|
||||
assertEquals("exception new value", newValue, response.getException());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHttpCaching() throws Exception {
|
||||
final SolrQueryResponse response = new SolrQueryResponse();
|
||||
assertEquals("httpCaching initial value", true, response.isHttpCaching());
|
||||
final boolean newValue = random().nextBoolean();
|
||||
response.setHttpCaching(newValue);
|
||||
assertEquals("httpCaching new value", newValue, response.isHttpCaching());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.solr.response.transform.*;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -81,6 +82,33 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
for (Method m : SolrReturnFields.class.getMethods()) {
|
||||
if (m.getName().equals("toString")) {
|
||||
assertTrue(m + " is not overridden ! ", m.getDeclaringClass() == SolrReturnFields.class);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final ReturnFields rf1 = new SolrReturnFields();
|
||||
final String rf1ToString = "SolrReturnFields=(globs=[]"
|
||||
+",fields=[]"
|
||||
+",okFieldNames=[]"
|
||||
+",reqFieldNames=null"
|
||||
+",transformer=null,wantsScore=false,wantsAllFields=true)";
|
||||
assertEquals(rf1ToString, rf1.toString());
|
||||
|
||||
final ReturnFields rf2 = new SolrReturnFields(
|
||||
req("fl", "id "+SolrReturnFields.SCORE+" test"));
|
||||
final String rf2ToString = "SolrReturnFields=(globs=[]"
|
||||
+",fields=[score, test, id]"
|
||||
+",okFieldNames=[null, score, test, id]"
|
||||
+",reqFieldNames=[id, score, test]"
|
||||
+",transformer=score,wantsScore=true,wantsAllFields=false)";
|
||||
assertEquals(rf2ToString, rf2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeparators() {
|
||||
ReturnFields rf = new SolrReturnFields( req("fl", "id name test subject score") );
|
||||
|
|
Loading…
Reference in New Issue