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.
17
package org.apache.solr.handler;
19
import org.apache.solr.SolrTestCaseJ4;
20
import java.io.StringWriter;
21
import java.util.ArrayList;
22
import java.util.HashMap;
25
import org.apache.solr.common.params.MapSolrParams;
26
import org.apache.solr.common.util.ContentStream;
27
import org.apache.solr.common.util.ContentStreamBase;
28
import org.apache.solr.common.util.NamedList;
29
import org.apache.solr.core.SolrCore;
30
import org.apache.solr.request.LocalSolrQueryRequest;
31
import org.apache.solr.response.QueryResponseWriter;
32
import org.apache.solr.response.SolrQueryResponse;
33
import org.junit.Before;
34
import org.junit.BeforeClass;
35
import org.junit.Test;
37
public class XsltUpdateRequestHandlerTest extends SolrTestCaseJ4 {
38
protected static XsltUpdateRequestHandler handler;
41
public static void beforeTests() throws Exception {
42
initCore("solrconfig.xml","schema.xml");
43
handler = new XsltUpdateRequestHandler();
48
public void setUp() throws Exception {
55
public void testUpdate() throws Exception
60
" <node name=\"id\" enhance=\"2.2\" value=\"12345\"/>" +
61
" <node name=\"name\" value=\"kitten\"/>" +
62
" <node name=\"text\" enhance=\"3\" value=\"some other day\"/>" +
63
" <node name=\"title\" enhance=\"4\" value=\"A story\"/>" +
64
" <node name=\"timestamp\" enhance=\"5\" value=\"2011-07-01T10:31:57.140Z\"/>" +
68
Map<String,String> args = new HashMap<String, String>();
69
args.put("tr", "xsl-update-handler-test.xsl");
71
SolrCore core = h.getCore();
72
LocalSolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
73
ArrayList<ContentStream> streams = new ArrayList<ContentStream>();
74
streams.add(new ContentStreamBase.StringStream(xml));
75
req.setContentStreams(streams);
76
SolrQueryResponse rsp = new SolrQueryResponse();
77
XsltUpdateRequestHandler handler = new XsltUpdateRequestHandler();
78
handler.init(new NamedList<String>());
79
handler.handleRequestBody(req, rsp);
80
StringWriter sw = new StringWriter(32000);
81
QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
82
responseWriter.write(sw,req,rsp);
84
String response = sw.toString();
88
assertQ("test document was correctly committed", req("q","*:*")
89
, "//result[@numFound='1']"
90
, "//int[@name='id'][.='12345']"