Apache Lucene open-source search software
SOLR-2291: bug doesn't exist on trunk, but forward porting test to prove it
Chris M. Hostetterd7bccac40bf1
diff --git a/solr/core/src/test/org/apache/solr/request/JSONWriterTest.java b/solr/core/src/test/org/apache/solr/request/JSONWriterTest.javaindex 0a657a0f39b..d56826627ce 100644--- a/solr/core/src/test/org/apache/solr/request/JSONWriterTest.java+++ b/solr/core/src/test/org/apache/solr/request/JSONWriterTest.java@@ -19,9 +19,15 @@ package org.apache.solr.request;import java.io.IOException;import java.io.StringWriter;+import java.util.HashSet;+import java.util.Set;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.search.ReturnFields;import org.apache.solr.response.JSONResponseWriter;import org.apache.solr.response.PHPSerializedResponseWriter;import org.apache.solr.response.PythonResponseWriter;@@ -85,5 +91,45 @@ public class JSONWriterTest extends SolrTestCaseJ4 {assertEquals("{\"nl\":[[\"data1\",\"he\\u2028llo\\u2029!\"],[null,42]],\"byte\":-3,\"short\":-4,\"bytes\":\"YWJj\"}", buf.toString());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();+ }}