Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.apache.solr.util;
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:
 @ThreadLeakFilters(defaultFilters = true, filters = {
 public abstract class AbstractSolrTestCase extends SolrTestCaseJ4 {
   protected SolrConfig solrConfig;

Subclasses can override this to change a test's solr home (default is in test-files)
   public String getSolrHome() {
     return SolrTestCaseJ4.TEST_HOME();
   public static Logger log = LoggerFactory.getLogger(AbstractSolrTestCase.class);

Causes an exception matching the regex pattern to not be logged.
   public static void ignoreException(String pattern) {
     if (. == null)
       . = new HashSet<String>();
   public static void resetExceptionIgnores() {
     . = null;
     ignoreException("ignore_exception");  // always ignore "ignore_exception"

Subclasses that override setUp can optionally call this method to log the fact that their setUp process has ended.
   public void postSetUp() {
     .info("####POSTSETUP " + getTestName());

Subclasses that override tearDown can optionally call this method to log the fact that the tearDown process has started. This is necessary since subclasses will want to call super.tearDown() at the *end* of their tearDown method.
   public void preTearDown() {
     .info("####PRETEARDOWN " + getTestName());      

Generates a simple <add><doc>... XML String with the commitWithin attribute.

commitWithin the value of the commitWithin attribute
fieldsAndValues 0th and Even numbered args are fields names odds are field values.
See also:
  public String adoc(int commitWithinString... fieldsAndValues) {
    XmlDoc d = doc(fieldsAndValues);
    return add(d"commitWithin", String.valueOf(commitWithin));

Generates a <delete>... XML string for an ID

  public String delI(String idString... args) {
    return TestHarness.deleteById(idargs);
Generates a <delete>... XML string for an query

  public String delQ(String qString... args) {
    return TestHarness.deleteByQuery(qargs);
  public static boolean recurseDelete(File f) {
    if (f.isDirectory()) {
      for (File sub : f.listFiles()) {
        if (!recurseDelete(sub)) {
          ..println("!!!! WARNING: best effort to remove " + sub.getAbsolutePath() + " FAILED !!!!!");
          return false;
    return f.delete();

  public static File getFile(String name) {
    return SolrTestCaseJ4.getFile(name);
New to GrepCode? Check out our FAQ X