Source Code Cross Referenced for PersistentFieldManagerImplTest.java in  » Web-Framework » Tapestry » org » apache » tapestry » internal » services » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » Tapestry » org.apache.tapestry.internal.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 2006, 2007 The Apache Software Foundation
002:        //
003:        // Licensed under the Apache License, Version 2.0 (the "License");
004:        // you may not use this file except in compliance with the License.
005:        // You may obtain a copy of the License at
006:        //
007:        //     http://www.apache.org/licenses/LICENSE-2.0
008:        //
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:
015:        package org.apache.tapestry.internal.services;
016:
017:        import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
018:        import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
019:
020:        import java.util.Collection;
021:        import java.util.Map;
022:
023:        import org.apache.tapestry.ComponentResources;
024:        import org.apache.tapestry.internal.test.InternalBaseTestCase;
025:        import org.apache.tapestry.model.ComponentModel;
026:        import org.apache.tapestry.services.MetaDataLocator;
027:        import org.apache.tapestry.services.PersistentFieldBundle;
028:        import org.apache.tapestry.services.PersistentFieldChange;
029:        import org.apache.tapestry.services.PersistentFieldManager;
030:        import org.apache.tapestry.services.PersistentFieldStrategy;
031:        import org.testng.annotations.Test;
032:
033:        public class PersistentFieldManagerImplTest extends
034:                InternalBaseTestCase {
035:            @Test
036:            public void post_change_with_unknown_strategy() {
037:                String fieldName = "field";
038:
039:                PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
040:                PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
041:                ComponentResources resources = mockComponentResources();
042:                ComponentModel model = mockComponentModel();
043:
044:                Map<String, PersistentFieldStrategy> strategies = newMap();
045:                strategies.put("foo", strat1);
046:                strategies.put("bar", strat2);
047:
048:                train_getComponentModel(resources, model);
049:
050:                train_getFieldPersistenceStrategy(model, fieldName,
051:                        "braveheart");
052:
053:                replay();
054:
055:                PersistentFieldManager manager = new PersistentFieldManagerImpl(
056:                        null, strategies);
057:
058:                try {
059:                    manager.postChange("foo.Bar", resources, fieldName, null);
060:                    unreachable();
061:                } catch (RuntimeException ex) {
062:                    assertEquals(
063:                            ex.getMessage(),
064:                            "\'braveheart\' is not a defined persistent strategy.  Defined stategies: bar, foo.");
065:                }
066:
067:                verify();
068:            }
069:
070:            @Test
071:            public void post_change() {
072:                String pageName = "foo.Bar";
073:                String nestedId = "nested";
074:                String fieldName = "field";
075:                String strategyName = "foo";
076:
077:                ComponentResources resources = mockComponentResources();
078:                ComponentModel model = mockComponentModel();
079:                PersistentFieldStrategy strat = newPersistentFieldStrategy();
080:                Object value = new Object();
081:
082:                Map<String, PersistentFieldStrategy> strategies = newMap();
083:                strategies.put(strategyName, strat);
084:
085:                train_getComponentModel(resources, model);
086:
087:                train_getFieldPersistenceStrategy(model, fieldName,
088:                        strategyName);
089:
090:                train_getNestedId(resources, nestedId);
091:
092:                strat.postChange(pageName, nestedId, fieldName, value);
093:
094:                replay();
095:
096:                PersistentFieldManager manager = new PersistentFieldManagerImpl(
097:                        null, strategies);
098:
099:                manager.postChange(pageName, resources, fieldName, value);
100:
101:                verify();
102:            }
103:
104:            public void strategy_name_is_case_insensitive() {
105:                String pageName = "foo.Bar";
106:                String nestedId = "nested";
107:                String fieldName = "field";
108:                String strategyName = "FOO";
109:
110:                ComponentResources resources = mockComponentResources();
111:                ComponentModel model = mockComponentModel();
112:                PersistentFieldStrategy strat = newPersistentFieldStrategy();
113:                Object value = new Object();
114:
115:                Map<String, PersistentFieldStrategy> strategies = newMap();
116:                strategies.put("foo", strat);
117:
118:                train_getComponentModel(resources, model);
119:
120:                train_getFieldPersistenceStrategy(model, fieldName,
121:                        strategyName);
122:
123:                train_getNestedId(resources, nestedId);
124:
125:                strat.postChange(pageName, nestedId, fieldName, value);
126:
127:                replay();
128:
129:                PersistentFieldManager manager = new PersistentFieldManagerImpl(
130:                        null, strategies);
131:
132:                manager.postChange(pageName, resources, fieldName, value);
133:
134:                verify();
135:            }
136:
137:            @Test
138:            public void post_change_strategy_by_meta_data() {
139:                String pageName = "foo.Bar";
140:                String nestedId = "nested";
141:                String fieldName = "field";
142:                String strategyName = "foo";
143:
144:                ComponentResources resources = mockComponentResources();
145:                ComponentModel model = mockComponentModel();
146:                PersistentFieldStrategy strat = newPersistentFieldStrategy();
147:                MetaDataLocator locator = newMetaDataLocator();
148:
149:                Object value = new Object();
150:
151:                Map<String, PersistentFieldStrategy> strategies = newMap();
152:                strategies.put(strategyName, strat);
153:
154:                train_getComponentModel(resources, model);
155:
156:                train_getFieldPersistenceStrategy(model, fieldName, "");
157:
158:                train_findMeta(locator, PersistentFieldManagerImpl.META_KEY,
159:                        resources, strategyName);
160:
161:                train_getNestedId(resources, nestedId);
162:
163:                strat.postChange(pageName, nestedId, fieldName, value);
164:
165:                replay();
166:
167:                PersistentFieldManager manager = new PersistentFieldManagerImpl(
168:                        locator, strategies);
169:
170:                manager.postChange(pageName, resources, fieldName, value);
171:
172:                verify();
173:            }
174:
175:            @Test
176:            public void post_change_with_ultimate_default_strategy() {
177:                String pageName = "foo.Bar";
178:                String nestedId = "nested";
179:                String fieldName = "field";
180:
181:                ComponentResources resources = mockComponentResources();
182:                ComponentModel model = mockComponentModel();
183:                MetaDataLocator locator = newMetaDataLocator();
184:
185:                PersistentFieldStrategy strat = newPersistentFieldStrategy();
186:                Object value = new Object();
187:
188:                Map<String, PersistentFieldStrategy> strategies = newMap();
189:                strategies.put(PersistentFieldManagerImpl.DEFAULT_STRATEGY,
190:                        strat);
191:
192:                train_getComponentModel(resources, model);
193:
194:                train_getFieldPersistenceStrategy(model, fieldName, "");
195:
196:                train_findMeta(locator, PersistentFieldManagerImpl.META_KEY,
197:                        resources, PersistentFieldManagerImpl.DEFAULT_STRATEGY);
198:
199:                train_getNestedId(resources, nestedId);
200:
201:                strat.postChange(pageName, nestedId, fieldName, value);
202:
203:                replay();
204:
205:                PersistentFieldManager manager = new PersistentFieldManagerImpl(
206:                        locator, strategies);
207:
208:                manager.postChange(pageName, resources, fieldName, value);
209:
210:                verify();
211:            }
212:
213:            protected void train_findMeta(MetaDataLocator locator, String key,
214:                    ComponentResources resources, String value) {
215:                expect(locator.findMeta(key, resources)).andReturn(value)
216:                        .atLeastOnce();
217:            }
218:
219:            protected MetaDataLocator newMetaDataLocator() {
220:                return newMock(MetaDataLocator.class);
221:            }
222:
223:            private PersistentFieldStrategy newPersistentFieldStrategy() {
224:                return newMock(PersistentFieldStrategy.class);
225:            }
226:
227:            @Test
228:            public void gather_changes() {
229:                Object value1 = new Object();
230:                Object value2 = new Object();
231:
232:                PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
233:
234:                Collection<PersistentFieldChange> changes1 = newList();
235:                changes1.add(new PersistentFieldChangeImpl("component",
236:                        "field1", value1));
237:
238:                PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
239:
240:                Collection<PersistentFieldChange> changes2 = newList();
241:                changes2.add(new PersistentFieldChangeImpl("component",
242:                        "field2", value2));
243:
244:                // We don't know the exact order the strategies will be ordered in the map,
245:                // so we can't guarantee the order the strategies will be invoked.
246:
247:                getMocksControl().checkOrder(false);
248:
249:                expect(strat1.gatherFieldChanges("foo.Bar"))
250:                        .andReturn(changes1);
251:
252:                expect(strat2.gatherFieldChanges("foo.Bar"))
253:                        .andReturn(changes2);
254:
255:                replay();
256:
257:                Map<String, PersistentFieldStrategy> strategies = newMap();
258:
259:                strategies.put("alpha", strat1);
260:                strategies.put("beta", strat2);
261:
262:                PersistentFieldManager manager = new PersistentFieldManagerImpl(
263:                        null, strategies);
264:
265:                PersistentFieldBundle bundle = manager.gatherChanges("foo.Bar");
266:
267:                assertSame(bundle.getValue("component", "field1"), value1);
268:                assertSame(bundle.getValue("component", "field2"), value2);
269:
270:                verify();
271:            }
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.