View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.lookup;
17  
18  import org.junit.Assert;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.kuali.rice.core.api.search.SearchOperator;
22  
23  import java.util.Map;
24  import java.util.HashMap;
25  
26  /**
27   * Unit test for LookupUtils.
28   *
29   * @author Rice Team (rice.collab@kuali.org)
30   */
31  public class LookupUtilsTest {
32  
33      @Test
34      public void testScrubQueryCharacters() {
35          // build up some sample values to scrub
36          Map<String, String> queryCharacterSamples = new HashMap<String, String>();
37          queryCharacterSamples.put(null, null);
38          queryCharacterSamples.put("", "");
39          queryCharacterSamples.put("this is a string with no query characters", "this is a string with no query characters");
40          queryCharacterSamples.put("this is a string with one.. query character", "this is a string with one query character");
41          queryCharacterSamples.put("..test...test", "testtest");
42          StringBuilder allQueryCharacters = new StringBuilder();
43          for (SearchOperator operator : SearchOperator.QUERY_CHARACTERS) {
44              allQueryCharacters.append(operator.op());
45          }
46          queryCharacterSamples.put(allQueryCharacters.toString(), "");
47  
48          // scrub them and make sure they produce the proper output
49          for (String input : queryCharacterSamples.keySet()) {
50              String output = queryCharacterSamples.get(input);
51              Assert.assertEquals("Check failed for input: " + input, output, LookupUtils.scrubQueryCharacters(input));
52          }
53      }
54  
55  
56  
57  }