001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.util;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    import org.apache.tapestry.BaseComponentTestCase;
021    import org.testng.annotations.Test;
022    
023    /**
024     * Tests for {@link org.apache.tapestry.util.QueryParameterMap}.
025     * 
026     * @author Howard M. Lewis Ship
027     * @since 4.0
028     */
029    @Test
030    public class TestQueryParameterMap extends BaseComponentTestCase
031    {
032        public void testUnknownKey()
033        {
034            QueryParameterMap m = new QueryParameterMap();
035    
036            assertNull(m.getParameterValue("unknown"));
037            assertNull(m.getParameterValues("unknown"));
038        }
039    
040        public void testGetSingleValue()
041        {
042            QueryParameterMap m = new QueryParameterMap();
043    
044            m.setParameterValue("fred", "flintstone");
045    
046            assertEquals("flintstone", m.getParameterValue("fred"));
047            assertListEquals(new String[]
048            { "flintstone" }, m.getParameterValues("fred"));
049        }
050    
051        public void testGetValuesArray()
052        {
053            QueryParameterMap m = new QueryParameterMap();
054    
055            String[] values = new String[]
056            { "fred", "wilma" };
057    
058            m.setParameterValues("flintstone", values);
059    
060            assertListEquals(values, m.getParameterValues("flintstone"));
061    
062            m.setParameterValue("rubble", "barney");
063    
064            assertListEquals(new String[]
065            { "barney" }, m.getParameterValues("rubble"));
066        }
067    
068        public void testGetParameterNames()
069        {
070            QueryParameterMap m = new QueryParameterMap();
071    
072            m.setParameterValue("fred", "flintstone");
073            m.setParameterValue("barney", "rubble");
074    
075            assertListEquals(new String[]
076            { "barney", "fred" }, m.getParameterNames());
077        }
078    
079        public void testExistingMap()
080        {
081            Map map = new HashMap();
082            QueryParameterMap m = new QueryParameterMap(map);
083    
084            m.setParameterValue("fred", "flintstone");
085    
086            assertEquals("flintstone", map.get("fred"));
087        }
088    }