FileDocCategorySizeDatePackage
TestQueryTranslator.javaAPI DocApache Lucene 2.1.04601Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.search.query

TestQueryTranslator

public class TestQueryTranslator extends TestCase
author
Simon Willnauer

Fields Summary
private static final String
CONTENT_FIELD
private static final String
UPDATED_FIELD
private org.apache.lucene.gdata.search.config.IndexSchema
schema
Map
parameterMap
Constructors Summary
Methods Summary
protected voidsetUp()

    /*
     * @see junit.framework.TestCase#setUp()
     */
    
         
        this.schema = new IndexSchema();
        //must be set
        this.schema.setDefaultSearchField(CONTENT_FIELD);
        this.schema.setIndexLocation("/tmp/");
        this.schema.setName(ProvidedServiceStub.SERVICE_NAME);
        IndexSchemaField field = new IndexSchemaField();
        
        field.setName(CONTENT_FIELD);
        field.setContentType(ContentType.TEXT);
        
        IndexSchemaField field1 = new IndexSchemaField();
        field1.setName(UPDATED_FIELD);
        field1.setContentType(ContentType.GDATADATE);
        this.schema.addSchemaField(field);
        this.schema.addSchemaField(field1);
        parameterMap = new HashMap<String,String[]>();
        

    
public voidtestTranslateHttpSearchRequest()

        assertNull(QueryTranslator.translateHttpSearchRequest(this.schema,this.parameterMap,null));
        String contentQuery = "content1 -content2 \"exact Content\""; 
        parameterMap.put("q", new String[]{contentQuery});
        String expected = CONTENT_FIELD+":("+contentQuery+") ";
      
        assertEquals(expected,QueryTranslator.translateHttpSearchRequest(this.schema,this.parameterMap,null));
        parameterMap.put("updated-min", new String[]{"2005-08-09T10:57:00-08:00"});
        parameterMap.put("updated-max", new String[]{"2005-10-09T10:57:00-08:00"});
        parameterMap.put("max-results", new String[]{"3"});
        parameterMap.remove("q");
        parameterMap.put(CONTENT_FIELD, new String[]{"apache"});
        
        String tranlatedQuery = QueryTranslator.translateHttpSearchRequest(this.schema,this.parameterMap,"test |{urn:google.com} {urn:apache.org}");
        assertTrue(tranlatedQuery.contains("updated:[1123613820000 TO 1128884219999]"));
        assertTrue(tranlatedQuery.contains(CONTENT_FIELD+":(apache)"));
        
        parameterMap.remove("updated-max");
        tranlatedQuery = QueryTranslator.translateHttpSearchRequest(this.schema,this.parameterMap,"test |{urn:google.com} {urn:apache.org}");
        assertTrue(tranlatedQuery.contains("updated:[1123613820000 TO "+Long.MAX_VALUE+"]"));
        assertTrue(tranlatedQuery.contains(CONTENT_FIELD+":(apache)"));
        parameterMap.put("updated-max", new String[]{"2005-10-09T10:57:00-08:00"});
        parameterMap.remove("updated-min");
        tranlatedQuery = QueryTranslator.translateHttpSearchRequest(this.schema,this.parameterMap,"test |{urn:google.com} {urn:apache.org}");
        assertTrue(tranlatedQuery.contains("updated:["+0+" TO 1128884219999]"));
        assertTrue(tranlatedQuery.contains(CONTENT_FIELD+":(apache)"));
        
        
        
        parameterMap.put("wrong-parameter", new String[]{"3"});
        try{
        QueryTranslator.translateHttpSearchRequest(this.schema,this.parameterMap,"test |{urn:google.com} {urn:apache.org}");
        fail("illegal parameter");
        }catch (RuntimeException e) {
           
        }