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

TestGdataCategoryStrategy

public class TestGdataCategoryStrategy extends TestCase
author
Simon Willnauer

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


         
        this.field = new IndexSchemaField();
        field.setName(FIELD);
        //store and index will be ignored
        field.setStore(Field.Store.NO);
        field.setIndex(Field.Index.TOKENIZED);
        field.setBoost(BOOST);
        field.setPath("/path");
        this.strategy = new GdataCategoryStrategy(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);
        try {
            this.strategy.createLuceneField();
            fail("content is not set");
        } catch (GdataIndexerException e) {
        }

        String content = "fooBar";
        stub.setReturnNull(false);
        stub.setReturnValueTextContent(content);
        this.strategy.processIndexable(stub);
        assertNotNull(this.strategy.content);
        assertNotNull(this.strategy.categoryScheme);
        assertEquals(content+" "+content, this.strategy.content.trim());
        assertEquals(content, this.strategy.categoryScheme);

        Field[] fields = this.strategy.createLuceneField();
        assertEquals(2, fields.length);
        assertEquals(this.field.getName(), fields[0].name());
        assertEquals(content+" "+content, fields[0].stringValue().trim());
        assertEquals(this.strategy.categorySchemeField, fields[1].name());
        assertEquals(content, fields[1].stringValue());
        // this is also stored an untok.
        assertFalse(fields[0].isStored());
        assertTrue(fields[0].isTokenized());
        // test for xpath exc.
        this.field.setPath(null);
        this.strategy = new GdataCategoryStrategy(field);
        try {
            this.strategy.processIndexable(stub);
            fail("path is null must fail");
        } catch (NotIndexableException e) {
        }
        try {
            this.strategy.createLuceneField();
            fail("content is not set");
        } catch (GdataIndexerException e) {
        }