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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/OutputWriterTest.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;
19
 
 
20
 
import java.io.IOException;
21
 
import java.io.Writer;
22
 
 
23
 
import org.apache.solr.common.util.NamedList;
24
 
import org.apache.solr.request.SolrQueryRequest;
25
 
import org.apache.solr.response.QueryResponseWriter;
26
 
import org.apache.solr.response.SolrQueryResponse;
27
 
import org.junit.BeforeClass;
28
 
import org.junit.Test;
29
 
 
30
 
/** Tests the ability to configure multiple query output writers, and select those
31
 
 * at query time.
32
 
 *
33
 
 */
34
 
public class OutputWriterTest extends SolrTestCaseJ4 {
35
 
    
36
 
    /** The XML string that's output for testing purposes. */
37
 
    public static final String USELESS_OUTPUT = "useless output";
38
 
    
39
 
    @BeforeClass
40
 
    public static void beforeClass() throws Exception {
41
 
      initCore("solr/crazy-path-to-config.xml","solr/crazy-path-to-schema.xml");
42
 
    }
43
 
    
44
 
    
45
 
    /** responseHeader has changed in SOLR-59, check old and new variants */
46
 
    @Test
47
 
    public void testSOLR59responseHeaderVersions() {
48
 
        // default version is 2.2, with "new" responseHeader
49
 
        lrf.args.remove("version");
50
 
        lrf.args.put("wt", "standard");
51
 
        assertQ(req("foo"), "/response/lst[@name='responseHeader']/int[@name='status'][.='0']");
52
 
        lrf.args.remove("wt");
53
 
        assertQ(req("foo"), "/response/lst[@name='responseHeader']/int[@name='QTime']");
54
 
        
55
 
        // version=2.1 reverts to old responseHeader
56
 
        lrf.args.put("version", "2.1");
57
 
        lrf.args.put("wt", "standard");
58
 
        assertQ(req("foo"), "/response/responseHeader/status[.='0']");
59
 
        lrf.args.remove("wt");
60
 
        assertQ(req("foo"), "/response/responseHeader/QTime");
61
 
 
62
 
        // and explicit 2.2 works as default  
63
 
        lrf.args.put("version", "2.2");
64
 
        lrf.args.put("wt", "standard");
65
 
        assertQ(req("foo"), "/response/lst[@name='responseHeader']/int[@name='status'][.='0']");
66
 
        lrf.args.remove("wt");
67
 
        assertQ(req("foo"), "/response/lst[@name='responseHeader']/int[@name='QTime']");
68
 
    }
69
 
    
70
 
    @Test
71
 
    public void testUselessWriter() throws Exception {
72
 
        lrf.args.put("wt", "useless");
73
 
        String out = h.query(req("foo"));
74
 
        assertEquals(USELESS_OUTPUT, out);
75
 
    }
76
 
    
77
 
    @Test
78
 
    public void testTrivialXsltWriter() throws Exception {
79
 
        lrf.args.put("wt", "xslt");
80
 
        lrf.args.put("tr", "dummy.xsl");
81
 
        String out = h.query(req("foo"));
82
 
        // System.out.println(out);
83
 
        assertTrue(out.contains("DUMMY"));
84
 
    }
85
 
    
86
 
    @Test
87
 
    public void testTrivialXsltWriterInclude() throws Exception {
88
 
        lrf.args.put("wt", "xslt");
89
 
        lrf.args.put("tr", "dummy-using-include.xsl");
90
 
        String out = h.query(req("foo"));
91
 
        // System.out.println(out);
92
 
        assertTrue(out.contains("DUMMY"));
93
 
    }
94
 
    
95
 
    
96
 
    ////////////////////////////////////////////////////////////////////////////
97
 
    /** An output writer that doesn't do anything useful. */
98
 
    
99
 
    public static class UselessOutputWriter implements QueryResponseWriter {
100
 
        
101
 
        public UselessOutputWriter() {}
102
 
 
103
 
        public void init(NamedList n) {}
104
 
        
105
 
        public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response)
106
 
        throws IOException {
107
 
            writer.write(USELESS_OUTPUT);
108
 
        }
109
 
 
110
 
      public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
111
 
        return CONTENT_TYPE_TEXT_UTF8;
112
 
      }
113
 
 
114
 
    }
115
 
    
116
 
}