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;
20
import java.io.IOException;
21
import java.io.Writer;
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;
30
/** Tests the ability to configure multiple query output writers, and select those
34
public class OutputWriterTest extends SolrTestCaseJ4 {
36
/** The XML string that's output for testing purposes. */
37
public static final String USELESS_OUTPUT = "useless output";
40
public static void beforeClass() throws Exception {
41
initCore("solr/crazy-path-to-config.xml","solr/crazy-path-to-schema.xml");
45
/** responseHeader has changed in SOLR-59, check old and new variants */
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']");
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");
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']");
71
public void testUselessWriter() throws Exception {
72
lrf.args.put("wt", "useless");
73
String out = h.query(req("foo"));
74
assertEquals(USELESS_OUTPUT, out);
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"));
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"));
96
////////////////////////////////////////////////////////////////////////////
97
/** An output writer that doesn't do anything useful. */
99
public static class UselessOutputWriter implements QueryResponseWriter {
101
public UselessOutputWriter() {}
103
public void init(NamedList n) {}
105
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response)
107
writer.write(USELESS_OUTPUT);
110
public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
111
return CONTENT_TYPE_TEXT_UTF8;