~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
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
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
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.
16
 
 */
17
 
 
18
 
package org.apache.solr.schema;
19
 
 
20
 
import java.util.regex.Pattern;
21
 
import java.util.LinkedList;
22
 
import java.util.List;
23
 
 
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;
28
 
 
29
 
import org.junit.Test;
30
 
 
31
 
/**
32
 
 */
33
 
public class BadIndexSchemaTest extends SolrTestCaseJ4 {
34
 
 
35
 
  private void doTest(final String schema, final String errString) 
36
 
    throws Exception {
37
 
 
38
 
    ignoreException(Pattern.quote(errString));
39
 
    try {
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;
44
 
 
45
 
      // otherwise, rethrow it, possibly completley unrelated
46
 
      throw new SolrException
47
 
        (ErrorCode.SERVER_ERROR, 
48
 
         "Unexpected error, expected error matching: " + errString, e);
49
 
    } finally {
50
 
      SolrConfig.severeErrors.clear();
51
 
    }
52
 
    fail("Did not encounter any exception from: " + schema);
53
 
  }
54
 
 
55
 
  @Test
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");
61
 
  }
62
 
  
63
 
  private Throwable findErrorWithSubstring( List<Throwable> err, String v )
64
 
  {
65
 
    for( Throwable t : err ) {
66
 
      if( t.getMessage().indexOf( v ) > 0 ) {
67
 
        return t;
68
 
      }
69
 
    }
70
 
    return null;
71
 
  }
72
 
  
73
 
  public void testSevereErrors() throws Exception {
74
 
    final String bad_type = "StrField (bad_type)";
75
 
    try {
76
 
      initCore( "solrconfig.xml", "bad-schema.xml" );
77
 
      
78
 
      ignoreException("_twice");
79
 
      ignoreException("ftAgain");
80
 
      ignoreException("fAgain");
81
 
      ignoreException(Pattern.quote(bad_type));
82
 
      
83
 
      for( Throwable t : SolrConfig.severeErrors ) {
84
 
        log.info( "got ex:"+t.getMessage() );
85
 
      }
86
 
    
87
 
      assertEquals( 4, SolrConfig.severeErrors.size() );
88
 
 
89
 
      List<Throwable> err = new LinkedList<Throwable>();
90
 
      err.addAll( SolrConfig.severeErrors );
91
 
      
92
 
      Throwable t = findErrorWithSubstring( err, "*_twice" );
93
 
      assertNotNull( t );
94
 
      err.remove( t );
95
 
      
96
 
      t = findErrorWithSubstring( err, "ftAgain" );
97
 
      assertNotNull( t );
98
 
      err.remove( t );
99
 
      
100
 
      t = findErrorWithSubstring( err, "fAgain" );
101
 
      assertNotNull( t );
102
 
      err.remove( t );
103
 
      
104
 
      t = findErrorWithSubstring( err, bad_type );
105
 
      assertNotNull( t );
106
 
      err.remove( t );
107
 
 
108
 
      // make sure thats all of them
109
 
      assertTrue( err.isEmpty() );
110
 
    } finally {
111
 
      SolrConfig.severeErrors.clear();
112
 
    }
113
 
  }
114
 
}