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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/handler/component/SearchHandlerTest.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.handler.component;
19
 
 
20
 
import java.util.ArrayList;
21
 
import java.util.List;
22
 
 
23
 
import org.apache.solr.common.util.NamedList;
24
 
import org.apache.solr.core.SolrCore;
25
 
import org.apache.solr.util.AbstractSolrTestCase;
26
 
 
27
 
 
28
 
public class SearchHandlerTest extends AbstractSolrTestCase 
29
 
{
30
 
  @Override public String getSchemaFile() { return "schema.xml"; }
31
 
  @Override public String getSolrConfigFile() { return "solrconfig.xml"; }
32
 
  
33
 
  @SuppressWarnings("unchecked")
34
 
  public void testInitalization()
35
 
  {
36
 
    SolrCore core = h.getCore();
37
 
    
38
 
    // Build an explicit list
39
 
    //-----------------------------------------------
40
 
    List<String> names0 = new ArrayList<String>();
41
 
    names0.add( MoreLikeThisComponent.COMPONENT_NAME );
42
 
    
43
 
    NamedList args = new NamedList();
44
 
    args.add( SearchHandler.INIT_COMPONENTS, names0 );
45
 
    SearchHandler handler = new SearchHandler();
46
 
    handler.init( args );
47
 
    handler.inform( core );
48
 
    
49
 
    assertEquals( 1, handler.getComponents().size() );
50
 
    assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), 
51
 
        handler.getComponents().get( 0 ) );
52
 
 
53
 
    // Build an explicit list that includes the debug comp.
54
 
    //-----------------------------------------------
55
 
    names0 = new ArrayList<String>();
56
 
    names0.add( FacetComponent.COMPONENT_NAME );
57
 
    names0.add( DebugComponent.COMPONENT_NAME );
58
 
    names0.add( MoreLikeThisComponent.COMPONENT_NAME );
59
 
 
60
 
    args = new NamedList();
61
 
    args.add( SearchHandler.INIT_COMPONENTS, names0 );
62
 
    handler = new SearchHandler();
63
 
    handler.init( args );
64
 
    handler.inform( core );
65
 
 
66
 
    assertEquals( 3, handler.getComponents().size() );
67
 
    assertEquals( core.getSearchComponent( FacetComponent.COMPONENT_NAME ),
68
 
        handler.getComponents().get( 0 ) );
69
 
    assertEquals( core.getSearchComponent( DebugComponent.COMPONENT_NAME ),
70
 
        handler.getComponents().get( 1 ) );
71
 
    assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), 
72
 
        handler.getComponents().get( 2 ) );
73
 
    
74
 
 
75
 
    // First/Last list
76
 
    //-----------------------------------------------
77
 
    names0 = new ArrayList<String>();
78
 
    names0.add( MoreLikeThisComponent.COMPONENT_NAME );
79
 
    
80
 
    List<String> names1 = new ArrayList<String>();
81
 
    names1.add( FacetComponent.COMPONENT_NAME );
82
 
    
83
 
    args = new NamedList();
84
 
    args.add( SearchHandler.INIT_FIRST_COMPONENTS, names0 );
85
 
    args.add( SearchHandler.INIT_LAST_COMPONENTS, names1 );
86
 
    handler = new SearchHandler();
87
 
    handler.init( args );
88
 
    handler.inform( core );
89
 
    
90
 
    List<SearchComponent> comps = handler.getComponents();
91
 
    assertEquals( 2+handler.getDefaultComponents().size(), comps.size() );
92
 
    assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), comps.get( 0 ) );
93
 
    assertEquals( core.getSearchComponent( FacetComponent.COMPONENT_NAME ), comps.get( comps.size()-2 ) );
94
 
    //Debug component is always last in this case
95
 
    assertEquals( core.getSearchComponent( DebugComponent.COMPONENT_NAME ), comps.get( comps.size()-1 ) );
96
 
  }
97
 
}