org.apache.solr.util
Class AbstractSolrTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.solr.util.AbstractSolrTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class AbstractSolrTestCase
extends junit.framework.TestCase

An Abstract base class that makes writing Solr JUnit tests "easier"

Test classes that subclass this need only specify the path to the schema.xml file (:TODO: the solrconfig.xml as well) and write some testMethods. This class takes care of creating/destroying the index, and provides several assert methods to assist you.

See Also:
setUp(), tearDown()

Nested Class Summary
static class AbstractSolrTestCase.Doc
          Neccessary to make method signatures un-ambiguous
 
Field Summary
protected  File dataDir
          The directory used to story the index managed by the TestHarness h
protected  TestHarness h
          Harness initialized by initTestHarness.
protected  TestHarness.LocalRequestFactory lrf
          LocalRequestFactory initialized by initTestHarness using sensible defaults.
 
Constructor Summary
AbstractSolrTestCase()
           
 
Method Summary
 String add(AbstractSolrTestCase.Doc doc, String... args)
          Generates an <add><doc>...
 String adoc(String... fieldsAndValues)
          Generates a simple <add><doc>...
 void assertFailedU(String update)
          Validates an update XML String failed
 void assertFailedU(String message, String update)
          Validates an update XML String failed
 void assertQ(SolrQueryRequest req, String... tests)
          Validates a query matches some XPath test expressions and closes the query
 void assertQ(String message, SolrQueryRequest req, String... tests)
          Validates a query matches some XPath test expressions and closes the query
 void assertQEx(String message, SolrQueryRequest req, int code)
          Makes sure a query throws a SolrException with the listed response code
 void assertU(String update)
          Validates an update XML String is successful
 void assertU(String message, String update)
          Validates an update XML String is successful
 String commit(String... args)
           
 String delI(String id)
          Generates a <delete>...
 String delQ(String q)
          Generates a <delete>...
 AbstractSolrTestCase.Doc doc(String... fieldsAndValues)
          Generates a simple <doc>...
abstract  String getSchemaFile()
          Subclasses must define this method to return the name of the schema.xml they wish to use.
abstract  String getSolrConfigFile()
          Subclasses must define this method to return the name of the solrconfig.xml they wish to use.
 String optimize(String... args)
           
static boolean recurseDelete(File f)
           
 SolrQueryRequest req(String... q)
          Generates a SolrQueryRequest using the LocalRequestFactory
 SolrQueryRequest req(String[] params, String... moreParams)
          Generates a SolrQueryRequest using the LocalRequestFactory
 void setUp()
          Initializes things your test might need Creates a dataDir in the "java.io.tmpdir" initializes the TestHarness h using this data directory, and getSchemaPath() initializes the LocalRequestFactory lrf using sensible defaults.
 void tearDown()
          Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the system property "solr.test.leavedatadir" is set.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

h

protected TestHarness h
Harness initialized by initTestHarness.

For use in test methods as needed.


lrf

protected TestHarness.LocalRequestFactory lrf
LocalRequestFactory initialized by initTestHarness using sensible defaults.

For use in test methods as needed.


dataDir

protected File dataDir
The directory used to story the index managed by the TestHarness h

Constructor Detail

AbstractSolrTestCase

public AbstractSolrTestCase()
Method Detail

getSchemaFile

public abstract String getSchemaFile()
Subclasses must define this method to return the name of the schema.xml they wish to use.


getSolrConfigFile

public abstract String getSolrConfigFile()
Subclasses must define this method to return the name of the solrconfig.xml they wish to use.


setUp

public void setUp()
           throws Exception
Initializes things your test might need

Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception

tearDown

public void tearDown()
              throws Exception
Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the system property "solr.test.leavedatadir" is set.

Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception

assertU

public void assertU(String update)
Validates an update XML String is successful


assertU

public void assertU(String message,
                    String update)
Validates an update XML String is successful


assertFailedU

public void assertFailedU(String update)
Validates an update XML String failed


assertFailedU

public void assertFailedU(String message,
                          String update)
Validates an update XML String failed


assertQ

public void assertQ(SolrQueryRequest req,
                    String... tests)
Validates a query matches some XPath test expressions and closes the query


assertQ

public void assertQ(String message,
                    SolrQueryRequest req,
                    String... tests)
Validates a query matches some XPath test expressions and closes the query


assertQEx

public void assertQEx(String message,
                      SolrQueryRequest req,
                      int code)
Makes sure a query throws a SolrException with the listed response code


optimize

public String optimize(String... args)
See Also:
TestHarness.optimize(java.lang.String...)

commit

public String commit(String... args)
See Also:
TestHarness.commit(java.lang.String...)

adoc

public String adoc(String... fieldsAndValues)
Generates a simple <add><doc>... XML String with no options

Parameters:
fieldsAndValues - 0th and Even numbered args are fields names odds are field values.
See Also:
add(org.apache.solr.util.AbstractSolrTestCase.Doc, java.lang.String...), doc(java.lang.String...)

add

public String add(AbstractSolrTestCase.Doc doc,
                  String... args)
Generates an <add><doc>... XML String with options on the add.

Parameters:
doc - the Document to add
args - 0th and Even numbered args are param names, Odds are param values.
See Also:
add(org.apache.solr.util.AbstractSolrTestCase.Doc, java.lang.String...), doc(java.lang.String...)

delI

public String delI(String id)
Generates a <delete>... XML string for an ID

See Also:
TestHarness.deleteById(java.lang.String)

delQ

public String delQ(String q)
Generates a <delete>... XML string for an query

See Also:
TestHarness.deleteByQuery(java.lang.String)

doc

public AbstractSolrTestCase.Doc doc(String... fieldsAndValues)
Generates a simple <doc>... XML String with no options

Parameters:
fieldsAndValues - 0th and Even numbered args are fields names, Odds are field values.
See Also:
TestHarness.makeSimpleDoc(java.lang.String...)

req

public SolrQueryRequest req(String... q)
Generates a SolrQueryRequest using the LocalRequestFactory

See Also:
lrf

req

public SolrQueryRequest req(String[] params,
                            String... moreParams)
Generates a SolrQueryRequest using the LocalRequestFactory

See Also:
lrf

recurseDelete

public static boolean recurseDelete(File f)


Copyright © 2006 - 2009 The Apache Software Foundation