KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > test > TestRequestDescriptor


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.test;
16
17 import java.util.Arrays JavaDoc;
18
19 import org.apache.hivemind.test.HiveMindTestCase;
20
21 /**
22  * Tests for {@link org.apache.tapestry.test.RequestDescriptor}.
23  *
24  * @author Howard Lewis Ship
25  * @since 4.0
26  */

27 public class TestRequestDescriptor extends HiveMindTestCase
28 {
29     private static class Assertion implements ResponseAssertion
30     {
31         private boolean _executed;
32
33         public void execute(ScriptedTestSession session)
34         {
35             _executed = true;
36         }
37
38         boolean getExecuted()
39         {
40             return _executed;
41         }
42     }
43
44     public void testAdd()
45     {
46         RequestDescriptor d = new RequestDescriptor();
47
48         d.addParameter("frank", "burns");
49
50         assertListsEqual(new String JavaDoc[]
51         { "burns" }, d.getParameterValues("frank"));
52     }
53
54     public void testGetNames()
55     {
56         RequestDescriptor d = new RequestDescriptor();
57
58         assertListsEqual(new Object JavaDoc[0], d.getParameterNames());
59
60         d.addParameter("flintstone", "fred");
61         d.addParameter("rubble", "barney");
62
63         String JavaDoc[] names = d.getParameterNames();
64
65         // Don't know what order they come back in, so sort them.
66

67         Arrays.sort(names);
68
69         assertListsEqual(new String JavaDoc[]
70         { "flintstone", "rubble" }, names);
71     }
72
73     public void testAddMultiple()
74     {
75         RequestDescriptor d = new RequestDescriptor();
76
77         d.addParameter("flintstone", "fred");
78         d.addParameter("flintstone", "wilma");
79         d.addParameter("flintstone", "dino");
80
81         assertListsEqual(new String JavaDoc[]
82         { "fred", "wilma", "dino" }, d.getParameterValues("flintstone"));
83     }
84
85     public void testGetUnknown()
86     {
87         RequestDescriptor d = new RequestDescriptor();
88
89         assertNull(d.getParameterValues("unknown"));
90     }
91
92     public void testServletName()
93     {
94         RequestDescriptor d = new RequestDescriptor();
95
96         assertNull(d.getServletName());
97
98         d.setServletName("servlet");
99
100         assertEquals("servlet", d.getServletName());
101     }
102
103     public void testExecuteAssertions()
104     {
105         RequestDescriptor d = new RequestDescriptor();
106
107         Assertion a1 = new Assertion();
108         Assertion a2 = new Assertion();
109
110         d.addAssertion(a1);
111         d.addAssertion(a2);
112
113         d.executeAssertions(null);
114
115         assertEquals(true, a1.getExecuted());
116         assertEquals(true, a2.getExecuted());
117     }
118
119 }
Popular Tags