FileDocCategorySizeDatePackage
TestIndexSchema.javaAPI DocApache Lucene 2.1.05296Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.search.config

TestIndexSchema

public class TestIndexSchema extends TestCase
author
Simon Willnauer

Fields Summary
IndexSchema
schema
Constructors Summary
Methods Summary
protected voidsetUp()

        schema = new IndexSchema();
    
protected voidtearDown()

        super.tearDown();
    
public voidtestAddSchemaField()

        schema.addSchemaField(null);
        assertEquals(0, schema.getFields().size());

        IndexSchemaField f = new IndexSchemaField();
        f.setName(IndexDocument.FIELD_ENTRY_ID);
        schema.addSchemaField(f);
        assertEquals(0, schema.getFields().size());

        f.setName(IndexDocument.FIELD_FEED_ID);
        schema.addSchemaField(f);
        assertEquals(0, schema.getFields().size());

        f.setName("some");
        schema.addSchemaField(f);
        assertEquals(1, schema.getFields().size());
        assertEquals(StandardAnalyzer.class, schema.getServiceAnalyzer()
                .getClass());
        assertEquals(StandardAnalyzer.class, schema.getSchemaAnalyzer()
                .getClass());
        f.setName("someOther");
        f.setAnalyzerClass(StopAnalyzer.class);
        schema.addSchemaField(f);
        assertEquals(2, schema.getFields().size());
        assertEquals(PerFieldAnalyzerWrapper.class, schema.getSchemaAnalyzer()
                .getClass());
        schema.addSchemaField(f);
        assertEquals(3, schema.getFields().size());

    
public voidtestEquals()

        assertFalse(schema.equals(null));
        assertFalse(schema.equals(new String()));
        assertTrue(schema.equals(schema));
        assertFalse(schema.equals(new IndexSchema()));
        IndexSchema s1 = new IndexSchema();
        s1.setName("someName");
        assertFalse(schema.equals(s1));
        schema.setName(s1.getName());
        assertTrue(schema.equals(s1));
    
public voidtestGetSearchableFieldNames()

        IndexSchemaField f = new IndexSchemaField();
        f.setName("some");
        schema.addSchemaField(f);
        assertEquals(1, schema.getSearchableFieldNames().size());
        assertTrue(schema.getSearchableFieldNames().contains("some"));
    
public voidtestHashCode()

        assertEquals(schema.hashCode(), schema.hashCode());
        assertNotNull(schema.hashCode());
        IndexSchema s1 = new IndexSchema();
        s1.setName("someName");
        assertTrue(schema.hashCode() != s1.hashCode());
        schema.setName(s1.getName());
        assertTrue(schema.hashCode() == s1.hashCode());
    
public voidtestInitialize()

        try {
            schema.initialize();
            fail("def search field is null");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
        schema.setDefaultSearchField("someField");
        try {
            schema.initialize();
            fail("name is null");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
        schema.setName("someName");
        try {
            schema.initialize();
            fail("indexLocation  is null");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
        schema.setIndexLocation("/loc/loc");
        try {
            schema.initialize();
            fail("default search field is not set as a field");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
        IndexSchemaField f = new IndexSchemaField();
        f.setName(schema.getDefaultSearchField());
        f.setContentType(ContentType.TEXT);
        schema.addSchemaField(f);
        try {
            schema.initialize();
            fail("field check failed");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
        f.setPath("path");
        schema.initialize();
    
public voidtestToSTringNoNullPEx()

        assertNotNull(schema.toString());