FileDocCategorySizeDatePackage
TestMixedStrategy.javaAPI DocApache Lucene 2.1.03581Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.search.analysis

TestMixedStrategy

public class TestMixedStrategy extends TestCase
author
Simon Willnauer

Fields Summary
private static final String
FIELD
private static final float
BOOST
MixedContentStrategy
strategy
private org.apache.lucene.gdata.search.config.IndexSchemaField
field
Constructors Summary
Methods Summary
protected voidsetUp()


         
        this.field = new IndexSchemaField();
        field.setName(FIELD);

        field.setStore(Field.Store.YES);
        field.setIndex(Field.Index.UN_TOKENIZED);
        field.setBoost(BOOST);
        field.setPath("/path");
        field.setTypePath("/path");
        this.strategy = new MixedContentStrategy(field);
    
protected voidtearDown()

        super.tearDown();
    
public voidtestProcessIndexable()

        IndexableStub stub = new IndexableStub();
        stub.setReturnNull(true);
        try {
            this.strategy.processIndexable(stub);
            fail("retun value is null must fail");
        } catch (NotIndexableException e) {
        }
        assertNull(this.strategy.content);
        String content = "fooBar";
        stub.setReturnNull(false);
        stub.setReturnValueTextContent(content);
        this.strategy.processIndexable(stub);
        assertNotNull(this.strategy.strategy.content);
        assertEquals(content, this.strategy.strategy.content);
        assertEquals(this.strategy.strategy.getClass(), PlainTextStrategy.class);

       

        content = "html";
        stub.setReturnNull(false);
        stub.setReturnValueTextContent(content);
        this.strategy.processIndexable(stub);
        assertNotNull(this.strategy.strategy.content);
        assertEquals(content, this.strategy.strategy.content);
        assertEquals(this.strategy.strategy.getClass(), HTMLStrategy.class);

        content = "xhtml";
        stub.setReturnNull(false);
        stub.setReturnValueTextContent(content);
        this.strategy.processIndexable(stub);
        assertNotNull(this.strategy.strategy.content);
        assertEquals(content, this.strategy.strategy.content);
        assertEquals(this.strategy.strategy.getClass(), XHtmlStrategy.class);

        
        // test for xpath exc.
        this.field.setPath(null);
        try {
            this.strategy.processIndexable(stub);
            fail("path is null must fail");
        } catch (NotIndexableException e) {
        }