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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/response/TestPHPSerializedResponseWriter.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.response;
19
 
 
20
 
import java.io.IOException;
21
 
import java.io.StringWriter;
22
 
import java.util.Arrays;
23
 
import java.util.LinkedHashMap;
24
 
 
25
 
import org.apache.solr.SolrTestCaseJ4;
26
 
import org.apache.solr.common.util.NamedList;
27
 
import org.apache.solr.response.PHPSerializedResponseWriter;
28
 
import org.apache.solr.request.SolrQueryRequest;
29
 
import org.apache.solr.response.QueryResponseWriter;
30
 
import org.apache.solr.response.SolrQueryResponse;
31
 
import org.apache.solr.common.SolrDocument;
32
 
import org.apache.solr.common.SolrDocumentList;
33
 
import org.junit.BeforeClass;
34
 
import org.junit.Test;
35
 
 
36
 
/** 
37
 
 * Basic PHPS tests based on JSONWriterTest
38
 
 *
39
 
 */
40
 
public class TestPHPSerializedResponseWriter extends SolrTestCaseJ4 {
41
 
  @BeforeClass
42
 
  public static void beforeClass() throws Exception {
43
 
    initCore("solrconfig.xml","schema.xml");
44
 
  }
45
 
 
46
 
  @Test
47
 
  public void testSimple() throws IOException {
48
 
    SolrQueryRequest req = req("dummy");
49
 
    SolrQueryResponse rsp = new SolrQueryResponse();
50
 
    QueryResponseWriter w = new PHPSerializedResponseWriter();
51
 
 
52
 
    StringWriter buf = new StringWriter();
53
 
    rsp.add("data1", "hello");
54
 
    rsp.add("data2", 42);
55
 
    rsp.add("data3", true);
56
 
    w.write(buf, req, rsp);
57
 
    assertEquals("a:3:{s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;}", 
58
 
                 buf.toString());
59
 
    req.close();
60
 
  }
61
 
 
62
 
  
63
 
  @Test
64
 
  public void testSolrDocuments() throws IOException {
65
 
    SolrQueryRequest req = req("q","*:*");
66
 
    SolrQueryResponse rsp = new SolrQueryResponse();
67
 
    QueryResponseWriter w = new PHPSerializedResponseWriter();
68
 
    StringWriter buf = new StringWriter();
69
 
 
70
 
    SolrDocument d = new SolrDocument();
71
 
 
72
 
    SolrDocument d1 = d;
73
 
    d.addField("id","1");
74
 
    d.addField("data1","hello");
75
 
    d.addField("data2",42);
76
 
    d.addField("data3",true);
77
 
 
78
 
    // multivalued fields: 
79
 
 
80
 
    // extremely odd edge case: value is a map
81
 
 
82
 
    // we use LinkedHashMap because we are doing a string comparison 
83
 
    // later and we need predictible ordering
84
 
    LinkedHashMap<String,String> nl = new LinkedHashMap<String,String>();
85
 
    nl.put("data4.1", "hashmap");
86
 
    nl.put("data4.2", "hello");
87
 
    d.addField("data4",nl);
88
 
    // array value 
89
 
    d.addField("data5",Arrays.asList("data5.1", "data5.2", "data5.3"));
90
 
 
91
 
    // adding one more document to test array indexes
92
 
    d = new SolrDocument();
93
 
    SolrDocument d2 = d;
94
 
    d.addField("id","2");
95
 
 
96
 
    SolrDocumentList sdl = new SolrDocumentList();
97
 
    sdl.add(d1);
98
 
    sdl.add(d2);
99
 
    rsp.add("response", sdl); 
100
 
    
101
 
    w.write(buf, req, rsp);
102
 
    assertEquals("a:1:{s:8:\"response\";a:3:{s:8:\"numFound\";i:0;s:5:\"start\";i:0;s:4:\"docs\";a:2:{i:0;a:6:{s:2:\"id\";s:1:\"1\";s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;s:5:\"data4\";a:2:{s:7:\"data4.1\";s:7:\"hashmap\";s:7:\"data4.2\";s:5:\"hello\";}s:5:\"data5\";a:3:{i:0;s:7:\"data5.1\";i:1;s:7:\"data5.2\";i:2;s:7:\"data5.3\";}}i:1;a:1:{s:2:\"id\";s:1:\"2\";}}}}", 
103
 
                 buf.toString());
104
 
    req.close();
105
 
  }
106
 
 
107
 
}