SOLR-2291: bug doesn't exist on trunk, but forward porting test to prove it

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1304628 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2012-03-23 22:14:19 +00:00
parent 3a29e80f31
commit d7bccac40b
1 changed files with 46 additions and 0 deletions

View File

@ -19,9 +19,15 @@ package org.apache.solr.request;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.search.ReturnFields;
import org.apache.solr.response.JSONResponseWriter; import org.apache.solr.response.JSONResponseWriter;
import org.apache.solr.response.PHPSerializedResponseWriter; import org.apache.solr.response.PHPSerializedResponseWriter;
import org.apache.solr.response.PythonResponseWriter; import org.apache.solr.response.PythonResponseWriter;
@ -86,4 +92,44 @@ public class JSONWriterTest extends SolrTestCaseJ4 {
req.close(); req.close();
} }
@Test
public void testJSONSolrDocument() throws IOException {
SolrQueryRequest req = req(CommonParams.WT,"json",
CommonParams.FL,"id,score");
SolrQueryResponse rsp = new SolrQueryResponse();
JSONResponseWriter w = new JSONResponseWriter();
ReturnFields returnFields = new ReturnFields(req);
rsp.setReturnFields(returnFields);
StringWriter buf = new StringWriter();
SolrDocument solrDoc = new SolrDocument();
solrDoc.addField("id", "1");
solrDoc.addField("subject", "hello2");
solrDoc.addField("title", "hello3");
solrDoc.addField("score", "0.7");
SolrDocumentList list = new SolrDocumentList();
list.setNumFound(1);
list.setStart(0);
list.setMaxScore(0.7f);
list.add(solrDoc);
rsp.add("response", list);
w.write(buf, req, rsp);
String result = buf.toString();
assertFalse("response contains unexpected fields: " + result,
result.contains("hello") ||
result.contains("\"subject\"") ||
result.contains("\"title\""));
assertTrue("response doesn't contain expected fields: " + result,
result.contains("\"id\"") &&
result.contains("\"score\""));
req.close();
}
} }