2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.schema;
20
import java.util.regex.Pattern;
21
import java.util.LinkedList;
22
import java.util.List;
24
import org.apache.solr.SolrTestCaseJ4;
25
import org.apache.solr.common.SolrException;
26
import org.apache.solr.common.SolrException.ErrorCode;
27
import org.apache.solr.core.SolrConfig;
29
import org.junit.Test;
33
public class BadIndexSchemaTest extends SolrTestCaseJ4 {
35
private void doTest(final String schema, final String errString)
38
ignoreException(Pattern.quote(errString));
40
initCore( "solrconfig.xml", schema );
41
} catch (SolrException e) {
42
// short circut out if we found what we expected
43
if (-1 != e.getMessage().indexOf(errString)) return;
45
// otherwise, rethrow it, possibly completley unrelated
46
throw new SolrException
47
(ErrorCode.SERVER_ERROR,
48
"Unexpected error, expected error matching: " + errString, e);
50
SolrConfig.severeErrors.clear();
52
fail("Did not encounter any exception from: " + schema);
56
public void testSevereErrorsForInvalidFieldOptions() throws Exception {
57
doTest("bad-schema-not-indexed-but-norms.xml", "bad_field");
58
doTest("bad-schema-not-indexed-but-tf.xml", "bad_field");
59
doTest("bad-schema-not-indexed-but-pos.xml", "bad_field");
60
doTest("bad-schema-omit-tf-but-not-pos.xml", "bad_field");
63
private Throwable findErrorWithSubstring( List<Throwable> err, String v )
65
for( Throwable t : err ) {
66
if( t.getMessage().indexOf( v ) > 0 ) {
73
public void testSevereErrors() throws Exception {
74
final String bad_type = "StrField (bad_type)";
76
initCore( "solrconfig.xml", "bad-schema.xml" );
78
ignoreException("_twice");
79
ignoreException("ftAgain");
80
ignoreException("fAgain");
81
ignoreException(Pattern.quote(bad_type));
83
for( Throwable t : SolrConfig.severeErrors ) {
84
log.info( "got ex:"+t.getMessage() );
87
assertEquals( 4, SolrConfig.severeErrors.size() );
89
List<Throwable> err = new LinkedList<Throwable>();
90
err.addAll( SolrConfig.severeErrors );
92
Throwable t = findErrorWithSubstring( err, "*_twice" );
96
t = findErrorWithSubstring( err, "ftAgain" );
100
t = findErrorWithSubstring( err, "fAgain" );
104
t = findErrorWithSubstring( err, bad_type );
108
// make sure thats all of them
109
assertTrue( err.isEmpty() );
111
SolrConfig.severeErrors.clear();