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.handler.component;
20
import java.util.ArrayList;
21
import java.util.List;
23
import org.apache.solr.common.util.NamedList;
24
import org.apache.solr.core.SolrCore;
25
import org.apache.solr.util.AbstractSolrTestCase;
28
public class SearchHandlerTest extends AbstractSolrTestCase
30
@Override public String getSchemaFile() { return "schema.xml"; }
31
@Override public String getSolrConfigFile() { return "solrconfig.xml"; }
33
@SuppressWarnings("unchecked")
34
public void testInitalization()
36
SolrCore core = h.getCore();
38
// Build an explicit list
39
//-----------------------------------------------
40
List<String> names0 = new ArrayList<String>();
41
names0.add( MoreLikeThisComponent.COMPONENT_NAME );
43
NamedList args = new NamedList();
44
args.add( SearchHandler.INIT_COMPONENTS, names0 );
45
SearchHandler handler = new SearchHandler();
47
handler.inform( core );
49
assertEquals( 1, handler.getComponents().size() );
50
assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ),
51
handler.getComponents().get( 0 ) );
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 );
60
args = new NamedList();
61
args.add( SearchHandler.INIT_COMPONENTS, names0 );
62
handler = new SearchHandler();
64
handler.inform( core );
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 ) );
76
//-----------------------------------------------
77
names0 = new ArrayList<String>();
78
names0.add( MoreLikeThisComponent.COMPONENT_NAME );
80
List<String> names1 = new ArrayList<String>();
81
names1.add( FacetComponent.COMPONENT_NAME );
83
args = new NamedList();
84
args.add( SearchHandler.INIT_FIRST_COMPONENTS, names0 );
85
args.add( SearchHandler.INIT_LAST_COMPONENTS, names1 );
86
handler = new SearchHandler();
88
handler.inform( core );
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 ) );