001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.lookup;
017
018import org.junit.Assert;
019import org.junit.Before;
020import org.junit.Test;
021import org.kuali.rice.core.api.search.SearchOperator;
022
023import java.util.Map;
024import java.util.HashMap;
025
026/**
027 * Unit test for LookupUtils.
028 *
029 * @author Rice Team (rice.collab@kuali.org)
030 */
031public class LookupUtilsTest {
032
033    @Test
034    public void testScrubQueryCharacters() {
035        // build up some sample values to scrub
036        Map<String, String> queryCharacterSamples = new HashMap<String, String>();
037        queryCharacterSamples.put(null, null);
038        queryCharacterSamples.put("", "");
039        queryCharacterSamples.put("this is a string with no query characters", "this is a string with no query characters");
040        queryCharacterSamples.put("this is a string with one.. query character", "this is a string with one query character");
041        queryCharacterSamples.put("..test...test", "testtest");
042        StringBuilder allQueryCharacters = new StringBuilder();
043        for (SearchOperator operator : SearchOperator.QUERY_CHARACTERS) {
044            allQueryCharacters.append(operator.op());
045        }
046        queryCharacterSamples.put(allQueryCharacters.toString(), "");
047
048        // scrub them and make sure they produce the proper output
049        for (String input : queryCharacterSamples.keySet()) {
050            String output = queryCharacterSamples.get(input);
051            Assert.assertEquals("Check failed for input: " + input, output, LookupUtils.scrubQueryCharacters(input));
052        }
053    }
054
055
056
057}