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

TestGdataDateStrategy

public class TestGdataDateStrategy extends TestCase
author
Simon Willnauer

Fields Summary
private static final String
FIELD
private static final float
BOOST
ContentStrategy
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.NO);
        field.setIndex(Field.Index.TOKENIZED);
        field.setBoost(BOOST);
        field.setPath("/path");
        this.strategy = new GdataDateStrategy(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) {
        }
        // test with proper date 
        String content = "2005-01-09T08:00:00Z";
        String parsedConent = Long.toString(DateTime.parseDateTime(content)
                .getValue());
        stub.setReturnNull(false);
        stub.setReturnValueTextContent(content);
        this.strategy.processIndexable(stub);
        assertNotNull(this.strategy.content);
        assertEquals(parsedConent, this.strategy.content);

        Field[] fields = this.strategy.createLuceneField();
        assertEquals(1, fields.length);
        assertEquals(this.field.getName(), fields[0].name());
        assertEquals(parsedConent, fields[0].stringValue());
        // timestamp is stored and untok.
        assertTrue(fields[0].isStored());
        assertFalse(fields[0].isTokenized());
        
        this.strategy = new GdataDateStrategy(this.field);
        content = "2005-01-09T##08:00:00Z";
        stub.setReturnValueTextContent(content);
        try {
            this.strategy.processIndexable(stub);
            fail("unparsable date must fail");
        } catch (NotIndexableException e) {
        }
        
        
        // test for xpath exc.
        this.field.setPath(null);
        this.strategy = new GdataDateStrategy(this.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) {
        }