1 16 package org.apache.myfaces.config; 17 18 import java.util.List ; 19 import java.util.Map ; 20 import javax.faces.el.VariableResolver; 21 22 import org.apache.myfaces.cactus.TestBean; 23 import org.apache.myfaces.cactus.MyFacesServletTestCase; 24 25 26 29 public class ManagedBeanCactusTest extends MyFacesServletTestCase 30 { 31 32 private VariableResolver variableResolver; 33 34 35 protected void setUp() throws Exception 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 list = testManagedProperties.getList(); 52 53 assertNotNull(list); 54 assertEquals(4, list.size()); 55 assertEquals(29, ((Integer ) list.get(0)).intValue()); 56 assertEquals(99, ((Integer ) list.get(1)).intValue()); 57 assertNull(list.get(2)); 58 assertEquals(23, ((Integer ) list.get(3)).intValue()); 59 60 Map map = testManagedProperties.getMap(); 61 62 assertNotNull(map); 63 assertEquals(4, map.size()); 64 assertEquals(25, ((Integer ) map.get("key1")).intValue()); 65 assertEquals(29, ((Integer ) map.get("test")).intValue()); 66 assertEquals(99, ((Integer ) map.get("test44")).intValue()); 67 assertNull(map.get("nullValue")); 68 assertTrue(map.containsKey("nullValue")); 69 } 70 71 72 public void testManagedList() 73 { 74 List list = (List ) variableResolver.resolveVariable(getContext(), "testList"); 75 76 assertNotNull(list); 77 assertEquals(4, list.size()); 78 assertEquals(29, ((Integer ) list.get(0)).intValue()); 79 assertEquals(99, ((Integer ) list.get(1)).intValue()); 80 assertNull(list.get(2)); 81 assertEquals(23, ((Integer ) list.get(3)).intValue()); 82 } 83 84 85 public void testManagedMap() 86 { 87 Map map = (Map ) variableResolver.resolveVariable(getContext(), "testMap"); 88 89 assertNotNull(map); 90 assertEquals(4, map.size()); 91 assertEquals(25, ((Integer ) map.get("key1")).intValue()); 92 assertEquals(29, ((Integer ) map.get("test")).intValue()); 93 assertEquals(99, ((Integer ) 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 list = testAdditional.getList(); 108 109 assertNotNull(list); 110 assertEquals(4, list.size()); 111 assertEquals(29, ((Integer ) list.get(0)).intValue()); 112 assertEquals(99, ((Integer ) list.get(1)).intValue()); 113 assertNull(list.get(2)); 114 assertEquals(23, ((Integer ) list.get(3)).intValue()); 115 116 Map map = testAdditional.getMap(); 117 118 assertNotNull(map); 119 assertEquals(4, map.size()); 120 assertEquals(25, ((Integer ) map.get("key1")).intValue()); 121 assertEquals(29, ((Integer ) map.get("test")).intValue()); 122 assertEquals(99, ((Integer ) map.get("test44")).intValue()); 123 assertNull(map.get("nullValue")); 124 assertTrue(map.containsKey("nullValue")); 125 } 126 127 public void testBug1007234() 128 { 129 Map map = (Map ) variableResolver.resolveVariable(getContext(), "filter"); 130 131 assertNotNull(map); 132 assertEquals(1, map.size()); 133 assertTrue(map.containsKey("mapping")); 134 135 Map mapping = (Map ) 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 |