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
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * 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;
 
 
 import java.io.File;
 
 
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
 
 @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<>();
     ..add(pattern);
   }
 
   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.
 
   @Override
   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.
 
   @Override
   public void preTearDown() {
     .info("####PRETEARDOWN " + getTestName());      
   }


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

Parameters:
commitWithin the value of the commitWithin attribute
fieldsAndValues 0th and Even numbered args are fields names odds are field values.
See also:
org.apache.solr.SolrTestCaseJ4.add(org.apache.solr.SolrTestCaseJ4.XmlDoc,java.lang.String[])
org.apache.solr.SolrTestCaseJ4.doc(java.lang.String[])
  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 File getFile(String name) {
    return SolrTestCaseJ4.getFile(name);
  }
New to GrepCode? Check out our FAQ X