KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > TestListEditMap


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.form;
16
17 import org.apache.tapestry.form.ListEditMap;
18 import org.apache.tapestry.junit.TapestryTestCase;
19 import org.apache.tapestry.spec.BeanLifecycle;
20
21 /**
22  * Suite of tests for {@link org.apache.tapestry.form.ListEditMap}.
23  *
24  * @author Howard Lewis Ship
25  * @since 3.0
26  */

27
28 public class TestListEditMap extends TapestryTestCase
29 {
30
31     private ListEditMap create()
32     {
33         ListEditMap m = new ListEditMap();
34
35         m.add("request", BeanLifecycle.REQUEST);
36         m.add("page", BeanLifecycle.PAGE);
37         m.add("render", BeanLifecycle.RENDER);
38
39         return m;
40     }
41
42     public void testAdd()
43     {
44         ListEditMap m = create();
45
46         assertEquals("render", m.getKey());
47
48         checkList("keys", new Object JavaDoc[]
49         { "request", "page", "render" }, m.getKeys());
50         checkList("all values", new Object JavaDoc[]
51         { BeanLifecycle.REQUEST, BeanLifecycle.PAGE, BeanLifecycle.RENDER }, m.getAllValues());
52         checkList("all values", new Object JavaDoc[]
53         { BeanLifecycle.REQUEST, BeanLifecycle.PAGE, BeanLifecycle.RENDER }, m.getValues());
54
55         assertTrue(m.getDeletedKeys().isEmpty());
56     }
57
58     public void testGet()
59     {
60         ListEditMap m = create();
61
62         m.setKey("page");
63
64         assertEquals("page", m.getKey());
65         assertSame(BeanLifecycle.PAGE, m.getValue());
66     }
67
68     public void testGetUnknown()
69     {
70         ListEditMap m = create();
71
72         m.setKey("unknown");
73
74         assertNull(m.getValue());
75     }
76
77     public void testMarkDeleted()
78     {
79         ListEditMap m = create();
80
81         m.setKey("page");
82
83         assertEquals(false, m.isDeleted());
84
85         m.setDeleted(true);
86
87         assertEquals(true, m.isDeleted());
88
89         checkList("all values", new Object JavaDoc[]
90         { BeanLifecycle.REQUEST, BeanLifecycle.PAGE, BeanLifecycle.RENDER }, m.getAllValues());
91
92         checkList("undeleted values", new Object JavaDoc[]
93         { BeanLifecycle.REQUEST, BeanLifecycle.RENDER }, m.getValues());
94
95         checkList("deleted keys", new Object JavaDoc[]
96         { "page" }, m.getDeletedKeys());
97     }
98
99     public void testMarkAlreadyDeleted()
100     {
101         ListEditMap m = create();
102
103         m.setKey("page");
104
105         assertEquals(false, m.isDeleted());
106
107         m.setDeleted(false);
108
109         assertEquals(false, m.isDeleted());
110     }
111
112     public void testMarkMultipleDeleted()
113     {
114         ListEditMap m = create();
115
116         m.setKey("page");
117         m.setDeleted(true);
118
119         m.setKey("render");
120         assertEquals(false, m.isDeleted());
121         m.setDeleted(true);
122
123         assertEquals(true, m.isDeleted());
124
125         checkList("undeleted values", new Object JavaDoc[]
126         { BeanLifecycle.REQUEST }, m.getValues());
127     }
128
129     public void testDeleteUndelete()
130     {
131         ListEditMap m = create();
132
133         m.setKey("page");
134         m.setDeleted(true);
135         m.setDeleted(false);
136
137         m.setKey("render");
138         m.setDeleted(true);
139
140         checkList("undeleted values", new Object JavaDoc[]
141         { BeanLifecycle.REQUEST, BeanLifecycle.PAGE }, m.getValues());
142     }
143
144     /** @since 4.0 */
145
146     public void testPurgeDeletedKeys()
147     {
148         ListEditMap m = create();
149
150         m.setKey("render");
151         m.setDeleted(true);
152
153         checkList("deleted keys before purge", new Object JavaDoc[]
154         { "render" }, m.getDeletedKeys());
155
156         m.purgeDeletedKeys();
157
158         checkList("all values after purge", new Object JavaDoc[]
159         { BeanLifecycle.REQUEST, BeanLifecycle.PAGE }, m.getAllValues());
160         checkList("keys after purge", new Object JavaDoc[]
161         { "request", "page" }, m.getKeys());
162
163         assertTrue(m.getDeletedKeys().isEmpty());
164
165         m.purgeDeletedKeys();
166
167         checkList("all values after second purge", new Object JavaDoc[]
168         { BeanLifecycle.REQUEST, BeanLifecycle.PAGE }, m.getAllValues());
169         checkList("keys after second purge", new Object JavaDoc[]
170         { "request", "page" }, m.getKeys());
171     }
172
173 }
Popular Tags