KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > TestServiceEncoding


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.engine;
16
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.apache.hivemind.test.HiveMindTestCase;
21
22 /**
23  * Tests for {@link org.apache.tapestry.engine.ServiceEncodingImpl}.
24  *
25  * @author Howard M. Lewis Ship
26  */

27 public class TestServiceEncoding extends HiveMindTestCase
28 {
29     public void testSetServletPath()
30     {
31         ServiceEncodingImpl se = new ServiceEncodingImpl("/bar");
32
33         assertEquals("/bar", se.getServletPath());
34         assertEquals(false, se.isModified());
35
36         se.setServletPath("/foo");
37
38         assertEquals("/foo", se.getServletPath());
39         assertEquals(true, se.isModified());
40     }
41
42     public void testCreateWithExistingMap()
43     {
44         Map JavaDoc parameters = new HashMap JavaDoc();
45
46         ServiceEncodingImpl se = new ServiceEncodingImpl("/foo", parameters);
47
48         se.setParameterValue("foo", "bar");
49
50         assertEquals("bar", parameters.get("foo"));
51     }
52
53     public void testGetParameterValue()
54     {
55         ServiceEncodingImpl se = new ServiceEncodingImpl("/foo");
56
57         se.setParameterValue("foo", "bar");
58
59         assertEquals(true, se.isModified());
60
61         assertEquals("bar", se.getParameterValue("foo"));
62
63         se.setParameterValues("flintstone", new String JavaDoc[]
64         { "fred", "wilma", "dino" });
65
66         assertEquals("fred", se.getParameterValue("flintstone"));
67
68         assertNull(se.getParameterValue("unknown"));
69     }
70
71     public void testGetParameterValues()
72     {
73         ServiceEncodingImpl se = new ServiceEncodingImpl("/foo");
74         se.setParameterValues("flintstone", new String JavaDoc[]
75         { "fred", "wilma", "dino" });
76
77         assertListsEqual(new String JavaDoc[]
78         { "fred", "wilma", "dino" }, se.getParameterValues("flintstone"));
79
80         assertEquals(true, se.isModified());
81
82         se.setParameterValue("foo", "bar");
83
84         assertListsEqual(new String JavaDoc[]
85         { "bar" }, se.getParameterValues("foo"));
86
87         assertNull(se.getParameterValue("unknown"));
88     }
89
90     public void testResetModified()
91     {
92         ServiceEncodingImpl se = new ServiceEncodingImpl("/bar");
93
94         assertEquals(false, se.isModified());
95
96         se.setServletPath("/foo");
97
98         assertEquals(true, se.isModified());
99
100         se.resetModified();
101
102         assertEquals(false, se.isModified());
103     }
104
105     public void testGetParameterNames()
106     {
107         ServiceEncodingImpl se = new ServiceEncodingImpl("/foo");
108
109         se.setParameterValue("foo", "bar");
110         se.setParameterValue("alpha", "beta");
111
112         assertListsEqual(new String JavaDoc[]
113         { "alpha", "foo" }, se.getParameterNames());
114     }
115 }
Popular Tags