/** * 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; import org.apache.solr.request.*; import org.apache.solr.util.*; /** * This is an example of how to write a JUnit tests for Solr using the * AbstractSolrTestCase */ public class SampleTest extends AbstractSolrTestCase { /** * All subclasses of AbstractSolrTestCase must define this method. * *
* Note that different tests can use different schemas by refering * to any crazy path they want (as long as it works). *
*/ public String getSchemaFile() { return "solr/crazy-path-to-schema.xml"; } /** * All subclasses of AbstractSolrTestCase must define this method * ** Note that different tests can use different configs by refering * to any crazy path they want (as long as it works). *
*/ public String getSolrConfigFile() { return "solr/crazy-path-to-config.xml"; } /** * Demonstration of some of the simple ways to use the base class */ public void testSimple() { lrf.args.put("version","2.0"); assertU("Simple assertion that adding a document works", adoc("id", "4055", "subject", "Hoss the Hoss man Hostetter")); /* alternate syntax, no label */ assertU(adoc("id", "4056", "subject", "Some Other Guy")); assertU(commit()); assertU(optimize()); assertQ("couldn't find subject hoss", req("subject:Hoss") ,"//result[@numFound=1]" ,"//int[@name='id'][.='4055']" ); } /** * Demonstration of some of the more complex ways to use the base class */ public void testAdvanced() throws Exception { lrf.args.put("version","2.0"); assertU("less common case, a complex addition with options", add(doc("id", "4059", "subject", "Who Me?"), "allowDups", "true")); assertU("or just make the raw XML yourself", "