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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/handler/XsltUpdateRequestHandlerTest.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
 
package org.apache.solr.handler;
18
 
 
19
 
import org.apache.solr.SolrTestCaseJ4;
20
 
import java.io.StringWriter;
21
 
import java.util.ArrayList;
22
 
import java.util.HashMap;
23
 
import java.util.Map;
24
 
 
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;
36
 
 
37
 
public class XsltUpdateRequestHandlerTest extends SolrTestCaseJ4 {
38
 
  protected static XsltUpdateRequestHandler handler;
39
 
 
40
 
  @BeforeClass
41
 
  public static void beforeTests() throws Exception {
42
 
    initCore("solrconfig.xml","schema.xml");
43
 
    handler = new XsltUpdateRequestHandler();
44
 
  }
45
 
 
46
 
  @Override
47
 
  @Before
48
 
  public void setUp() throws Exception {
49
 
    super.setUp();
50
 
    clearIndex();
51
 
    assertU(commit());
52
 
  }
53
 
 
54
 
  @Test
55
 
  public void testUpdate() throws Exception
56
 
  {
57
 
    String xml = 
58
 
      "<random>" +
59
 
      " <document>" +
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\"/>" +
65
 
      " </document>" +
66
 
      "</random>";
67
 
 
68
 
        Map<String,String> args = new HashMap<String, String>();
69
 
        args.put("tr", "xsl-update-handler-test.xsl");
70
 
    
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);
83
 
        req.close();
84
 
        String response = sw.toString();
85
 
        assertU(response);
86
 
    assertU(commit());
87
 
 
88
 
    assertQ("test document was correctly committed", req("q","*:*")
89
 
            , "//result[@numFound='1']"
90
 
            , "//int[@name='id'][.='12345']"
91
 
                );  
92
 
  }
93
 
}