Adding tests to make sure you get FieldTypeInfo when you ask for the schema

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@586516 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-10-19 16:02:31 +00:00
parent 87e233db19
commit 37345a65d3
2 changed files with 41 additions and 10 deletions

View File

@ -195,9 +195,10 @@ public class LukeResponse extends SolrResponseBase {
// Parse indexinfo
indexInfo = (NamedList<Object>) res.get("index");
NamedList<Object> schema = (NamedList<Object>) res.get("schema");
NamedList<Object> flds = (NamedList<Object>) res.get("fields");
if (flds == null) {
flds = (NamedList<Object>) ((NamedList<Object>) res.get("schema")).get("fields");
if (flds == null && schema != null ) {
flds = (NamedList<Object>) schema.get("fields");
}
if (flds != null) {
fieldInfo = new HashMap<String, FieldInfo>();
@ -208,16 +209,17 @@ public class LukeResponse extends SolrResponseBase {
}
}
NamedList<Object> fldTypes = (NamedList<Object>) ((NamedList<Object>) res.get("schema")).get("types");
if (fldTypes != null) {
fieldTypeInfo = new HashMap<String, FieldTypeInfo>();
for (Map.Entry<String, Object> fieldType : fldTypes) {
FieldTypeInfo ft = new FieldTypeInfo(fieldType.getKey());
ft.read((NamedList<Object>) fieldType.getValue());
fieldTypeInfo.put(fieldType.getKey(), ft);
if( schema != null ) {
NamedList<Object> fldTypes = (NamedList<Object>) schema.get("types");
if (fldTypes != null) {
fieldTypeInfo = new HashMap<String, FieldTypeInfo>();
for (Map.Entry<String, Object> fieldType : fldTypes) {
FieldTypeInfo ft = new FieldTypeInfo(fieldType.getKey());
ft.read((NamedList<Object>) fieldType.getValue());
fieldTypeInfo.put(fieldType.getKey(), ft);
}
}
}
}
//----------------------------------------------------------------

View File

@ -27,6 +27,8 @@ import java.util.List;
import junit.framework.Assert;
import org.apache.solr.client.solrj.request.DirectXmlRequest;
import org.apache.solr.client.solrj.request.LukeRequest;
import org.apache.solr.client.solrj.response.LukeResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.client.solrj.util.ClientUtils;
@ -252,4 +254,31 @@ abstract public class SolrExampleTests extends SolrExampleTestBase
server.commit();
assertNumFound( "*:*", 0 ); // make sure it got out
}
public void testLukeHandler() throws Exception
{
SolrServer server = getSolrServer();
// Empty the database...
server.deleteByQuery( "*:*" );// delete everything!
SolrInputDocument[] doc = new SolrInputDocument[5];
for( int i=0; i<doc.length; i++ ) {
doc[i] = new SolrInputDocument();
doc[i].setField( "id", "ID"+i, 1.0f );
server.add( doc[i] );
}
server.commit();
assertNumFound( "*:*", doc.length ); // make sure it got in
LukeRequest luke = new LukeRequest();
luke.setShowSchema( false );
LukeResponse rsp = luke.process( server );
assertNull( rsp.getFieldTypeInfo() ); // if you don't ask for it, the schema is null
luke.setShowSchema( true );
rsp = luke.process( server );
assertNotNull( rsp.getFieldTypeInfo() );
}
}