FileDocCategorySizeDatePackage
TestindexDocumentBuilderTask.javaAPI DocApache Lucene 2.1.06540Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.search.index

TestindexDocumentBuilderTask

public class TestindexDocumentBuilderTask extends TestCase
author
Simon Willnauer

Fields Summary
IndexDocumentBuilder
fineBuilder
IndexDocumentBuilder
failInStrategyBuilder
IndexDocumentBuilder
builder
IndexDocumentBuilderTask
zeroFields
static String
ID
static String
CONTENT_FIELD
static String
CONTENT
Constructors Summary
Methods Summary
protected voidsetUp()

         
        ServerBaseEntry entry = new ServerBaseEntry();
        entry.setVersionId("1");
        entry.setFeedId("myFeed");
        entry.setId(ID);
        entry.setContent(new PlainTextConstruct(CONTENT));
        entry.setServiceConfig(new ProvidedServiceStub());
        IndexSchema schema = new IndexSchema();
        schema.setName("mySchema");
        IndexSchemaField field = new IndexSchemaField();
        field.setName(CONTENT_FIELD);
        field.setPath("/entry/content");
        field.setContentType(ContentType.TEXT);
        schema.addSchemaField(field);
        this.fineBuilder = new IndexDocumentBuilderTask(entry,schema,IndexAction.INSERT,true,true);
        
        /*
         * two fields, one will fail due to broken xpath.
         * One will remain.
         */
        schema = new IndexSchema();
        schema.setName("mySchema");
        field = new IndexSchemaField();
        field.setName("someContent");
        //broken xpath
        field.setPath("/entry///wrongXPath");
        field.setContentType(ContentType.TEXT);
        schema.addSchemaField(field);
        field = new IndexSchemaField();
        field.setName(CONTENT_FIELD);
        field.setPath("/entry/content");
        field.setContentType(ContentType.TEXT);
        schema.addSchemaField(field);
        this.failInStrategyBuilder = new IndexDocumentBuilderTask(entry,schema,IndexAction.INSERT,false,false);
        //fail with no fields
        schema = new IndexSchema();
        schema.setName("mySchema");
        this.zeroFields = new IndexDocumentBuilderTask(entry,schema,IndexAction.INSERT,false,false);
        
        
    
protected voidtearDown()

        super.tearDown();
    
public voidtestCall()

        ExecutorService service = Executors.newSingleThreadExecutor();
        Future<IndexDocument> future = service.submit(this.fineBuilder);
        IndexDocument doc = future.get();
        assertNotNull(doc.getDeletealbe());
        assertNotNull(doc.getWriteable());
        assertEquals(IndexDocument.FIELD_ENTRY_ID,doc.getDeletealbe().field());
        assertEquals(ID,doc.getDeletealbe().text());
        assertEquals(ID,doc.getWriteable().getField(IndexDocument.FIELD_ENTRY_ID).stringValue());
        assertNotNull(doc.getWriteable().getField(CONTENT_FIELD).stringValue());
        assertTrue(doc.commitAfter());
        assertTrue(doc.optimizeAfter());
      
        /*
         * the broken xpath fails but the other fields will be indexed
         */
        future = service.submit(this.failInStrategyBuilder);
         doc = future.get();
        
        assertNotNull(doc.getDeletealbe());
        assertNotNull(doc.getWriteable());
        assertEquals(IndexDocument.FIELD_ENTRY_ID,doc.getDeletealbe().field());
        assertEquals(ID,doc.getDeletealbe().text());
        assertEquals(ID,doc.getWriteable().getField(IndexDocument.FIELD_ENTRY_ID).stringValue());
        assertNotNull(doc.getWriteable().getField(CONTENT_FIELD).stringValue());
        future = service.submit(this.zeroFields);
        
        try{
         future.get();
        fail("zero fields in document");
        }catch (ExecutionException e) {
            assertTrue(e.getCause().getClass() == GdataIndexerException.class);
            
        }
        service.shutdownNow();
    
public voidtestIndexDocumentBuilderTask()

        IndexDocument doc = this.fineBuilder.call();
        assertNotNull(doc.getDeletealbe());
        assertNotNull(doc.getWriteable());
        assertEquals(IndexDocument.FIELD_ENTRY_ID,doc.getDeletealbe().field());
        assertEquals(ID,doc.getDeletealbe().text());
        assertEquals(ID,doc.getWriteable().getField(IndexDocument.FIELD_ENTRY_ID).stringValue());
        assertNotNull(doc.getWriteable().getField(CONTENT_FIELD).stringValue());
      
        /*
         * the broken xpath fails but the other fields will be indexed
         */
        doc = this.failInStrategyBuilder.call();
        assertNotNull(doc.getDeletealbe());
        assertNotNull(doc.getWriteable());
        assertEquals(IndexDocument.FIELD_ENTRY_ID,doc.getDeletealbe().field());
        assertEquals(ID,doc.getDeletealbe().text());
        assertEquals(ID,doc.getWriteable().getField(IndexDocument.FIELD_ENTRY_ID).stringValue());
        assertNotNull(doc.getWriteable().getField(CONTENT_FIELD).stringValue());
        
        try{
        this.zeroFields.call();
        fail("zero fields in document");
        }catch (GdataIndexerException e) {}