Zookeeper setup
[lui-solr.git] / zookeeper / exampledocs / test_utf8.sh
1 #!/bin/sh
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 #Test script to tell if the server is accepting UTF-8
18 #The python writer currently escapes non-ascii chars, so it's good for testing
19
20 URL=http://localhost:8983/solr
21
22 if [ ! -z $1 ]; then
23   URL=$1
24 fi
25
26 curl "$URL/select?q=hello&params=explicit&wt=python" 2> /dev/null | grep 'hello' > /dev/null 2>&1
27 if [ $? = 0 ]; then
28   echo "Solr server is up."
29 else
30   echo "ERROR: Could not curl to Solr - is curl installed? Is Solr not running?"
31   exit 1
32 fi
33
34 curl "$URL/select?q=h%C3%A9llo&echoParams=explicit&wt=python" 2> /dev/null | grep 'h\\u00e9llo' > /dev/null 2>&1
35 if [ $? = 0 ]; then
36   echo "HTTP GET is accepting UTF-8"
37 else
38   echo "ERROR: HTTP GET is not accepting UTF-8"
39 fi
40
41 curl $URL/select --data-binary 'q=h%C3%A9llo&echoParams=explicit&wt=python' -H 'Content-type:application/x-www-form-urlencoded; charset=UTF-8' 2> /dev/null | grep 'h\\u00e9llo' > /dev/null 2>&1
42 if [ $? = 0 ]; then
43   echo "HTTP POST is accepting UTF-8"
44 else
45   echo "ERROR: HTTP POST is not accepting UTF-8"
46 fi
47
48 curl $URL/select --data-binary 'q=h%C3%A9llo&echoParams=explicit&wt=python' 2> /dev/null | grep 'h\\u00e9llo' > /dev/null 2>&1
49 if [ $? = 0 ]; then
50   echo "HTTP POST defaults to UTF-8"
51 else
52   echo "HTTP POST does not default to UTF-8"
53 fi
54
55
56 #A unicode character outside of the BMP (a circle with an x inside)
57 CHAR="𐌈"
58 CODEPOINT='0x10308'
59 #URL encoded UTF8 of the codepoint
60 URL_UTF8='%F0%90%8C%88'
61 #expected return of the python writer (currently uses UTF-16 surrogates)
62 EXPECTED='\\ud800\\udf08'
63
64 curl "$URL/select?q=$URL_UTF8&echoParams=explicit&wt=python" 2> /dev/null | grep $EXPECTED > /dev/null 2>&1
65 if [ $? = 0 ]; then
66   echo "HTTP GET is accepting UTF-8 beyond the basic multilingual plane"
67 else
68   echo "ERROR: HTTP GET is not accepting UTF-8 beyond the basic multilingual plane"
69 fi
70
71 curl $URL/select --data-binary "q=$URL_UTF8&echoParams=explicit&wt=python"  -H 'Content-type:application/x-www-form-urlencoded; charset=UTF-8' 2> /dev/null | grep $EXPECTED > /dev/null 2>&1
72 if [ $? = 0 ]; then
73   echo "HTTP POST is accepting UTF-8 beyond the basic multilingual plane"
74 else
75   echo "ERROR: HTTP POST is not accepting UTF-8 beyond the basic multilingual plane"
76 fi
77
78 curl "$URL/select?q=$URL_UTF8&echoParams=explicit&wt=python" --data-binary '' 2> /dev/null | grep $EXPECTED > /dev/null 2>&1
79 if [ $? = 0 ]; then
80   echo "HTTP POST + URL params is accepting UTF-8 beyond the basic multilingual plane"
81 else
82   echo "ERROR: HTTP POST + URL params is not accepting UTF-8 beyond the basic multilingual plane"
83 fi
84
85 #curl "$URL/select?q=$URL_UTF8&echoParams=explicit&wt=json" 2> /dev/null | od -tx1 -w1000 | sed 's/ //g' | grep 'f4808198' > /dev/null 2>&1
86 curl "$URL/select?q=$URL_UTF8&echoParams=explicit&wt=json" 2> /dev/null | grep "$CHAR" > /dev/null 2>&1
87 if [ $? = 0 ]; then
88   echo "Response correctly returns UTF-8 beyond the basic multilingual plane"
89 else
90   echo "ERROR: Response can't return UTF-8 beyond the basic multilingual plane"
91 fi
92
93