01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.wicket;
18:
19: import junit.framework.TestCase;
20:
21: /**
22: * Unit test for the PageParameters, introduced for bug [ 1213889 ]
23: * PageParameter keyValuePair disallows negatives.
24: *
25: * @author Martijn Dashorst
26: */
27: public class PageParametersTest extends TestCase {
28: /**
29: *
30: */
31: public void test_1() {
32: PageParameters parameters = new PageParameters("0=test");
33: assertEquals("test", parameters.get("0"));
34: }
35:
36: /**
37: *
38: */
39: public void test_2() {
40: PageParameters parameters = new PageParameters("test");
41: assertNull(parameters.get("test"));
42: }
43:
44: /**
45: *
46: */
47: public void test_3() {
48: PageParameters parameters = new PageParameters("test=");
49: assertEquals("", parameters.get("test"));
50: }
51:
52: /**
53: *
54: */
55: public void test_4() {
56: try {
57: new PageParameters("=test");
58: fail("Expected an exception: invalid URL parameter");
59: } catch (IllegalArgumentException ex) {
60: // ok; expected
61: }
62: }
63:
64: /**
65: * Test creation of an array on multiple calls to add.
66: */
67: public void testArray1() {
68: PageParameters parameters = new PageParameters();
69: parameters.add("a", "1");
70: assertEquals("1", parameters.get("a"));
71: parameters.add("a", "2");
72: Object o = parameters.get("a");
73: assertTrue(o instanceof String[]);
74: String[] a = (String[]) o;
75: assertEquals(2, a.length);
76: assertEquals("1", a[0]);
77: assertEquals("2", a[1]);
78: parameters.add("a", "3");
79: o = parameters.get("a");
80: assertTrue(o instanceof String[]);
81: a = (String[]) o;
82: assertEquals(3, a.length);
83: assertEquals("1", a[0]);
84: assertEquals("2", a[1]);
85: assertEquals("3", a[2]);
86: }
87:
88: /**
89: * Parsing of negative numbers on the right side of the assignment didn't
90: * work, as the minus character was not part of the word pattern.
91: */
92: public void testNegativeNumberParameter() {
93: PageParameters parameters = new PageParameters("a=-1");
94: assertEquals("-1", parameters.get("a"));
95: }
96: }
|