View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.config;
20  
21  /**
22   * http://issues.apache.org/jira/browse/MYFACES-889?page=all
23   * 
24   * @author Dennis C. Byrne
25   */
26  
27  import java.util.List;
28  import java.util.Map;
29  import java.util.logging.Logger;
30  
31  public class Myfaces889TestCase extends AbstractManagedBeanBuilderTestCase
32  {
33  
34      public Myfaces889TestCase(String name)
35      {
36          super(name);
37      }
38  
39      //private static Log log = LogFactory.getLog(Myfaces889TestCase.class);
40      private static Logger log = Logger.getLogger(Myfaces889TestCase.class.getName());
41  
42      public void testWriteOnlyMap()
43      {
44          assertTrue(example != null);
45          log.fine("managed bean successfully created");
46  
47          Map<String, String> writeOnlyMap = example.getHiddenWriteOnlyMap();
48  
49          assertTrue(writeOnlyMap != null);
50          log.fine("managed map is not null");
51  
52          scrutinizeMap(writeOnlyMap);
53      }
54  
55      public void testManagedMap()
56      {
57          assertTrue(example != null);
58          log.fine("managed bean successfully created");
59  
60          Map<String, String> managedMap = example.getManagedMap();
61  
62          assertTrue(managedMap != null);
63          log.fine("managed map is not null");
64  
65          scrutinizeMap(managedMap);
66      }
67  
68      private void scrutinizeMap(Map<String, String> map)
69      {
70          assertTrue(map.size() == 3);
71          log.fine("managed map has the correct size " + map.size());
72          
73          for (Map.Entry<String, String> entry : map.entrySet())
74          {
75              String key = entry.getKey();
76              String value = entry.getValue();
77              String config = (String) MANAGED_MAP.get(key);
78              log.fine("looking @ " + config + " and " + value);
79              assertTrue(config.equals(value));
80          }
81      }
82  
83      public void testManagedList()
84      {
85          assertTrue(example != null);
86          log.fine("managed bean successfully created");
87  
88          List<String> managedList = example.getManagedList();
89  
90          scrutinizeList(managedList);
91      }
92  
93      public void testWriteOnlyList()
94      {
95          assertTrue(example != null);
96          log.fine("managed bean successfully created");
97  
98          List<String> writeOnlyList = example.getHiddenWriteOnlyList();
99  
100         scrutinizeList(writeOnlyList);
101     }
102 
103     private void scrutinizeList(List<String> list)
104     {
105         assertTrue(list != null);
106         log.fine("managed list is not null " + list.size());
107         assertTrue(list.size() == 3);
108         log.fine("managed list has the correct size " + list.size());
109 
110         for (int i = 0; i < list.size(); i++)
111         {
112             String entry = list.get(i);
113             String config = MANAGED_LIST.get(i);
114             log.fine("looking @ " + config + " and " + entry);
115             assertTrue(config.equals(entry));
116         }
117     }
118 
119     public void testManagedProperty()
120     {
121         assertTrue(example != null);
122         log.fine("managed bean successfully created");
123 
124         String managedPropertyValue = example.getManagedProperty();
125 
126         assertTrue(INJECTED_VALUE.equals(managedPropertyValue));
127         log.fine("managed property String has the correct value ");
128     }
129 
130 }