KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > config > ManagedBeanCactusTest


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

16 package org.apache.myfaces.config;
17
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import javax.faces.el.VariableResolver;
21
22 import org.apache.myfaces.cactus.TestBean;
23 import org.apache.myfaces.cactus.MyFacesServletTestCase;
24
25
26 /**
27  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
28  */

29 public class ManagedBeanCactusTest extends MyFacesServletTestCase
30 {
31
32     private VariableResolver variableResolver;
33
34
35     protected void setUp() throws Exception JavaDoc
36     {
37         super.setUp();
38         variableResolver = getContext().getApplication().getVariableResolver();
39     }
40
41
42     public void testManagedProperties()
43     {
44         TestBean testManagedProperties = (TestBean) variableResolver.resolveVariable(getContext(), "testManagedProperties");
45
46         assertNotNull(testManagedProperties);
47         assertEquals(5, testManagedProperties.getNumberPrimitiveLong());
48         assertEquals(99L, testManagedProperties.getNumberLong().longValue());
49         assertNull(testManagedProperties.getValueWithDefault());
50
51         List JavaDoc list = testManagedProperties.getList();
52
53         assertNotNull(list);
54         assertEquals(4, list.size());
55         assertEquals(29, ((Integer JavaDoc) list.get(0)).intValue());
56         assertEquals(99, ((Integer JavaDoc) list.get(1)).intValue());
57         assertNull(list.get(2));
58         assertEquals(23, ((Integer JavaDoc) list.get(3)).intValue());
59
60         Map JavaDoc map = testManagedProperties.getMap();
61
62         assertNotNull(map);
63         assertEquals(4, map.size());
64         assertEquals(25, ((Integer JavaDoc) map.get("key1")).intValue());
65         assertEquals(29, ((Integer JavaDoc) map.get("test")).intValue());
66         assertEquals(99, ((Integer JavaDoc) map.get("test44")).intValue());
67         assertNull(map.get("nullValue"));
68         assertTrue(map.containsKey("nullValue"));
69     }
70
71
72     public void testManagedList()
73     {
74         List JavaDoc list = (List JavaDoc) variableResolver.resolveVariable(getContext(), "testList");
75
76         assertNotNull(list);
77         assertEquals(4, list.size());
78         assertEquals(29, ((Integer JavaDoc) list.get(0)).intValue());
79         assertEquals(99, ((Integer JavaDoc) list.get(1)).intValue());
80         assertNull(list.get(2));
81         assertEquals(23, ((Integer JavaDoc) list.get(3)).intValue());
82     }
83
84
85     public void testManagedMap()
86     {
87         Map JavaDoc map = (Map JavaDoc) variableResolver.resolveVariable(getContext(), "testMap");
88
89         assertNotNull(map);
90         assertEquals(4, map.size());
91         assertEquals(25, ((Integer JavaDoc) map.get("key1")).intValue());
92         assertEquals(29, ((Integer JavaDoc) map.get("test")).intValue());
93         assertEquals(99, ((Integer JavaDoc) map.get("test44")).intValue());
94         assertNull(map.get("nullValue"));
95         assertTrue(map.containsKey("nullValue"));
96     }
97
98     public void testAdditional()
99      {
100          TestBean testAdditional = (TestBean) variableResolver.resolveVariable(getContext(), "testAdditional");
101
102          assertNotNull(testAdditional);
103          assertEquals(5, testAdditional.getNumberPrimitiveLong());
104          assertEquals(99L, testAdditional.getNumberLong().longValue());
105          assertNull(testAdditional.getValueWithDefault());
106
107          List JavaDoc list = testAdditional.getList();
108
109          assertNotNull(list);
110          assertEquals(4, list.size());
111          assertEquals(29, ((Integer JavaDoc) list.get(0)).intValue());
112          assertEquals(99, ((Integer JavaDoc) list.get(1)).intValue());
113          assertNull(list.get(2));
114          assertEquals(23, ((Integer JavaDoc) list.get(3)).intValue());
115
116          Map JavaDoc map = testAdditional.getMap();
117
118          assertNotNull(map);
119          assertEquals(4, map.size());
120          assertEquals(25, ((Integer JavaDoc) map.get("key1")).intValue());
121          assertEquals(29, ((Integer JavaDoc) map.get("test")).intValue());
122          assertEquals(99, ((Integer JavaDoc) map.get("test44")).intValue());
123          assertNull(map.get("nullValue"));
124          assertTrue(map.containsKey("nullValue"));
125      }
126
127     public void testBug1007234()
128     {
129         Map JavaDoc map = (Map JavaDoc) variableResolver.resolveVariable(getContext(), "filter");
130
131         assertNotNull(map);
132         assertEquals(1, map.size());
133         assertTrue(map.containsKey("mapping"));
134
135         Map JavaDoc mapping = (Map JavaDoc) map.get("mapping");
136
137         assertEquals(3, mapping.size());
138         assertEquals("primaryErrorDAO", mapping.get("PrimaryError"));
139         assertEquals("transactionLatencyDAO", mapping.get("TransactionLatency"));
140         assertEquals("highWaterMarkDAO", mapping.get("HighWaterMark"));
141     }
142 }
143
Popular Tags