import java.util.List;
public class TestDocumentObjectBinder extends TestCase
{
public void testSimple() throws Exception {
DocumentObjectBinder binder = new DocumentObjectBinder();
XMLResponseParser parser = new XMLResponseParser();
NamedList<Object> nl = null;
nl = parser.processResponse(new StringReader(xml));
QueryResponse res = new QueryResponse(nl, null);
SolrDocumentList solDocList = res.getResults();
List<Item> l = binder.getBeans(Item.class,res.getResults());
Assert.assertEquals(solDocList.size(), l.size());
Assert.assertEquals(solDocList.get(0).getFieldValue("features"), l.get(0).features);
Item item = new Item();
item.id = "aaa";
item.categories = new String[] { "aaa", "bbb", "ccc" };
SolrInputDocument out = binder.toSolrInputDocument( item );
Assert.assertEquals( item.id, out.getFieldValue( "id" ) );
SolrInputField catfield = out.getField( "cat" );
Assert.assertEquals( 3, catfield.getValueCount() );
Assert.assertEquals( "[aaa, bbb, ccc]", catfield.getValue().toString() );
// Test the error on not settable stuff...
NotGettableItem ng = new NotGettableItem();
ng.setInStock( false );
try {
out = binder.toSolrInputDocument( ng );
Assert.fail( "Should throw an error" );
}
catch( RuntimeException ex ) {
// ok -- this should happen...
}