Source Code Cross Referenced for TapestryTestCase.java in  » Web-Framework » Tapestry » org » apache » tapestry » test » 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.test 
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.test;
016:
017:        import static java.lang.Thread.sleep;
018:        import static org.apache.tapestry.internal.test.CodeEq.codeEq;
019:        import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
020:        import static org.easymock.EasyMock.eq;
021:
022:        import java.io.File;
023:        import java.io.FileOutputStream;
024:        import java.io.IOException;
025:        import java.io.OutputStream;
026:        import java.lang.annotation.Annotation;
027:        import java.net.URL;
028:        import java.util.Arrays;
029:        import java.util.List;
030:        import java.util.Locale;
031:        import java.util.Map;
032:
033:        import javax.servlet.ServletOutputStream;
034:        import javax.servlet.http.HttpServletRequest;
035:        import javax.servlet.http.HttpServletResponse;
036:        import javax.servlet.http.HttpSession;
037:
038:        import org.apache.tapestry.Asset;
039:        import org.apache.tapestry.Binding;
040:        import org.apache.tapestry.Block;
041:        import org.apache.tapestry.ComponentEventHandler;
042:        import org.apache.tapestry.ComponentResources;
043:        import org.apache.tapestry.ComponentResourcesCommon;
044:        import org.apache.tapestry.Field;
045:        import org.apache.tapestry.FieldValidator;
046:        import org.apache.tapestry.Link;
047:        import org.apache.tapestry.MarkupWriter;
048:        import org.apache.tapestry.PropertyConduit;
049:        import org.apache.tapestry.Translator;
050:        import org.apache.tapestry.ValidationTracker;
051:        import org.apache.tapestry.Validator;
052:        import org.apache.tapestry.annotations.Id;
053:        import org.apache.tapestry.annotations.Inject;
054:        import org.apache.tapestry.annotations.Parameter;
055:        import org.apache.tapestry.annotations.Path;
056:        import org.apache.tapestry.beaneditor.BeanModel;
057:        import org.apache.tapestry.beaneditor.PropertyModel;
058:        import org.apache.tapestry.internal.services.MarkupWriterImpl;
059:        import org.apache.tapestry.ioc.AnnotationProvider;
060:        import org.apache.tapestry.ioc.Locatable;
061:        import org.apache.tapestry.ioc.Location;
062:        import org.apache.tapestry.ioc.Messages;
063:        import org.apache.tapestry.ioc.ObjectLocator;
064:        import org.apache.tapestry.ioc.Resource;
065:        import org.apache.tapestry.ioc.test.IOCTestCase;
066:        import org.apache.tapestry.model.ComponentModel;
067:        import org.apache.tapestry.model.MutableComponentModel;
068:        import org.apache.tapestry.model.ParameterModel;
069:        import org.apache.tapestry.runtime.Component;
070:        import org.apache.tapestry.services.AliasManager;
071:        import org.apache.tapestry.services.ApplicationStateCreator;
072:        import org.apache.tapestry.services.ApplicationStatePersistenceStrategy;
073:        import org.apache.tapestry.services.ApplicationStatePersistenceStrategySource;
074:        import org.apache.tapestry.services.AssetFactory;
075:        import org.apache.tapestry.services.AssetSource;
076:        import org.apache.tapestry.services.BeanModelSource;
077:        import org.apache.tapestry.services.BindingFactory;
078:        import org.apache.tapestry.services.BindingSource;
079:        import org.apache.tapestry.services.ClassTransformation;
080:        import org.apache.tapestry.services.ClasspathAssetAliasManager;
081:        import org.apache.tapestry.services.ComponentClassResolver;
082:        import org.apache.tapestry.services.Context;
083:        import org.apache.tapestry.services.Environment;
084:        import org.apache.tapestry.services.FieldValidatorSource;
085:        import org.apache.tapestry.services.Heartbeat;
086:        import org.apache.tapestry.services.InjectionProvider;
087:        import org.apache.tapestry.services.MethodFilter;
088:        import org.apache.tapestry.services.MethodSignature;
089:        import org.apache.tapestry.services.Request;
090:        import org.apache.tapestry.services.RequestHandler;
091:        import org.apache.tapestry.services.ResourceDigestGenerator;
092:        import org.apache.tapestry.services.Response;
093:        import org.apache.tapestry.services.Session;
094:        import org.apache.tapestry.services.ValidationConstraintGenerator;
095:        import org.apache.tapestry.services.ValidationMessagesSource;
096:        import org.easymock.EasyMock;
097:        import org.easymock.IAnswer;
098:
099:        /**
100:         * Base test case that adds a number of convienience factory and training methods for the public
101:         * interfaces of Tapestry.
102:         */
103:        public abstract class TapestryTestCase extends IOCTestCase {
104:
105:            /**
106:             * Creates a new markup writer instance (not a markup writer mock). Output can be directed at
107:             * the writer, which uses the default (HTML) markup model. The writer's toString() value
108:             * represents all the collected markup in the writer.
109:             * 
110:             * @return
111:             */
112:            protected final MarkupWriter createMarkupWriter() {
113:                return new MarkupWriterImpl();
114:            }
115:
116:            protected final void train_getAliasesForMode(AliasManager manager,
117:                    String mode, Map<Class, Object> configuration) {
118:                expect(manager.getAliasesForMode(mode))
119:                        .andReturn(configuration);
120:            }
121:
122:            protected final ApplicationStateCreator mockApplicationStateCreator() {
123:                return newMock(ApplicationStateCreator.class);
124:            }
125:
126:            protected final ApplicationStatePersistenceStrategy mockApplicationStatePersistenceStrategy() {
127:                return newMock(ApplicationStatePersistenceStrategy.class);
128:            }
129:
130:            protected final ApplicationStatePersistenceStrategySource mockApplicationStatePersistenceStrategySource() {
131:                return newMock(ApplicationStatePersistenceStrategySource.class);
132:            }
133:
134:            protected final Asset mockAsset() {
135:                return newMock(Asset.class);
136:            }
137:
138:            protected final AssetFactory mockAssetFactory() {
139:                return newMock(AssetFactory.class);
140:            }
141:
142:            protected final AssetSource mockAssetSource() {
143:                return newMock(AssetSource.class);
144:            }
145:
146:            protected final Binding mockBinding() {
147:                return newMock(Binding.class);
148:            }
149:
150:            protected final BindingFactory mockBindingFactory() {
151:                return newMock(BindingFactory.class);
152:            }
153:
154:            protected final BindingSource mockBindingSource() {
155:                return newMock(BindingSource.class);
156:            }
157:
158:            protected final Block mockBlock() {
159:                return newMock(Block.class);
160:            }
161:
162:            protected final ClasspathAssetAliasManager mockClasspathAssetAliasManager() {
163:                return newMock(ClasspathAssetAliasManager.class);
164:            }
165:
166:            protected final ClassTransformation mockClassTransformation() {
167:                return newMock(ClassTransformation.class);
168:            }
169:
170:            protected final Component mockComponent() {
171:                return newMock(Component.class);
172:            }
173:
174:            protected final ComponentClassResolver mockComponentClassResolver() {
175:                return newMock(ComponentClassResolver.class);
176:            }
177:
178:            protected final ComponentEventHandler mockComponentEventHandler() {
179:                return newMock(ComponentEventHandler.class);
180:            }
181:
182:            protected final ComponentModel mockComponentModel() {
183:                return newMock(ComponentModel.class);
184:            }
185:
186:            protected final ComponentResources mockComponentResources() {
187:                return newMock(ComponentResources.class);
188:            }
189:
190:            protected final Context mockContext() {
191:                return newMock(Context.class);
192:            }
193:
194:            protected final Environment mockEnvironment() {
195:                return newMock(Environment.class);
196:            }
197:
198:            protected final Field mockField() {
199:                return newMock(Field.class);
200:            }
201:
202:            protected final FieldValidator mockFieldValidator() {
203:                return newMock(FieldValidator.class);
204:            }
205:
206:            protected FieldValidatorSource mockFieldValidatorSource() {
207:                return newMock(FieldValidatorSource.class);
208:            }
209:
210:            protected final Field mockFieldWithLabel(String label) {
211:                Field field = mockField();
212:
213:                train_getLabel(field, label);
214:
215:                return field;
216:            }
217:
218:            protected final Heartbeat mockHeartbeat() {
219:                return newMock(Heartbeat.class);
220:            }
221:
222:            protected final HttpServletRequest mockHttpServletRequest() {
223:                return newMock(HttpServletRequest.class);
224:            }
225:
226:            protected final HttpServletResponse mockHttpServletResponse() {
227:                return newMock(HttpServletResponse.class);
228:            }
229:
230:            protected final HttpSession mockHttpSession() {
231:                return newMock(HttpSession.class);
232:            }
233:
234:            protected final Inject mockInject() {
235:                return newMock(Inject.class);
236:            }
237:
238:            protected final Link mockLink() {
239:                return newMock(Link.class);
240:            }
241:
242:            protected final MarkupWriter mockMarkupWriter() {
243:                return newMock(MarkupWriter.class);
244:            }
245:
246:            protected final MutableComponentModel mockMutableComponentModel() {
247:                return newMock(MutableComponentModel.class);
248:            }
249:
250:            protected final ParameterModel mockParameterModel() {
251:                return newMock(ParameterModel.class);
252:            }
253:
254:            protected final Path mockPath() {
255:                return newMock(Path.class);
256:            }
257:
258:            protected final PropertyConduit mockPropertyConduit() {
259:                return newMock(PropertyConduit.class);
260:            }
261:
262:            protected final PropertyModel mockPropertyEditModel() {
263:                return newMock(PropertyModel.class);
264:            }
265:
266:            protected final Request mockRequest() {
267:                return newMock(Request.class);
268:            }
269:
270:            protected final RequestHandler mockRequestHandler() {
271:                return newMock(RequestHandler.class);
272:            }
273:
274:            protected final ResourceDigestGenerator mockResourceDigestGenerator() {
275:                return newMock(ResourceDigestGenerator.class);
276:            }
277:
278:            protected final Response mockResponse() {
279:                return newMock(Response.class);
280:            }
281:
282:            protected final Session mockSession() {
283:                return newMock(Session.class);
284:            }
285:
286:            protected final Translator mockTranslator() {
287:                return newMock(Translator.class);
288:            }
289:
290:            protected final ValidationConstraintGenerator mockValidationConstraintGenerator() {
291:                return newMock(ValidationConstraintGenerator.class);
292:            }
293:
294:            protected final ValidationMessagesSource mockValidationMessagesSource() {
295:                return newMock(ValidationMessagesSource.class);
296:            }
297:
298:            protected final ValidationTracker mockValidationTracker() {
299:                return newMock(ValidationTracker.class);
300:            }
301:
302:            protected final Validator mockValidator() {
303:                return newMock(Validator.class);
304:            }
305:
306:            /** Writes a change to a file. */
307:            protected final void touch(File f) throws Exception {
308:                long startModified = f.lastModified();
309:
310:                while (true) {
311:                    OutputStream o = new FileOutputStream(f);
312:                    o.write(0);
313:                    o.close();
314:
315:                    long newModified = f.lastModified();
316:
317:                    if (newModified != startModified)
318:                        return;
319:
320:                    // Sleep 1/20 second and try again
321:
322:                    sleep(50);
323:                }
324:            }
325:
326:            protected final void train_addField(
327:                    ClassTransformation transformation, int modifiers,
328:                    String type, String suggestedName, String actualName) {
329:                expect(transformation.addField(modifiers, type, suggestedName))
330:                        .andReturn(actualName);
331:            }
332:
333:            protected final void train_addInjectedField(ClassTransformation ct,
334:                    Class type, String suggestedName, Object value,
335:                    String fieldName) {
336:                expect(ct.addInjectedField(type, suggestedName, value))
337:                        .andReturn(fieldName);
338:            }
339:
340:            protected final void train_addMethod(
341:                    ClassTransformation transformation,
342:                    MethodSignature signature, String... body) {
343:                transformation.addMethod(eq(signature), codeEq(join(body)));
344:            }
345:
346:            protected final void train_buildConstraints(
347:                    ValidationConstraintGenerator generator,
348:                    Class propertyType, AnnotationProvider provider,
349:                    String... constraints) {
350:                expect(generator.buildConstraints(propertyType, provider))
351:                        .andReturn(Arrays.asList(constraints));
352:            }
353:
354:            protected final <T> void train_create(
355:                    ApplicationStateCreator<T> creator, T aso) {
356:                expect(creator.create()).andReturn(aso);
357:            }
358:
359:            protected final void train_createAsset(AssetFactory factory,
360:                    Resource resource, Asset asset) {
361:                expect(factory.createAsset(resource)).andReturn(asset);
362:            }
363:
364:            protected final void train_createValidator(
365:                    FieldValidatorSource source, Field field,
366:                    String validatorType, String constraintValue,
367:                    String overrideId, Messages overrideMessages,
368:                    Locale locale, FieldValidator result) {
369:                expect(
370:                        source.createValidator(field, validatorType,
371:                                constraintValue, overrideId, overrideMessages,
372:                                locale)).andReturn(result);
373:            }
374:
375:            protected final void train_encodeRedirectURL(Response response,
376:                    String URI, String encoded) {
377:                expect(response.encodeRedirectURL(URI)).andReturn(encoded);
378:            }
379:
380:            protected final void train_encodeURL(Response response,
381:                    String inputURL, String outputURL) {
382:                expect(response.encodeURL(inputURL)).andReturn(outputURL);
383:            }
384:
385:            protected final <T> void train_exists(
386:                    ApplicationStatePersistenceStrategy strategy,
387:                    Class<T> asoClass, boolean exists) {
388:                expect(strategy.exists(asoClass)).andReturn(exists);
389:            }
390:
391:            protected final void train_extendConstructor(
392:                    ClassTransformation transformation, String... body) {
393:                transformation.extendConstructor(codeEq(join(body)));
394:            }
395:
396:            protected final void train_extendMethod(
397:                    ClassTransformation transformation,
398:                    MethodSignature signature, String... body) {
399:                transformation.extendMethod(eq(signature), codeEq(join(body)));
400:            }
401:
402:            protected final void train_findAsset(AssetSource source,
403:                    Resource root, String path, Locale locale, Asset asset) {
404:                expect(source.findAsset(root, path, locale)).andReturn(asset);
405:            }
406:
407:            protected final void train_findFieldsOfType(
408:                    ClassTransformation transformation, String type,
409:                    String... fieldNames) {
410:                expect(transformation.findFieldsOfType(type)).andReturn(
411:                        Arrays.asList(fieldNames));
412:            }
413:
414:            protected final void train_findFieldsWithAnnotation(
415:                    ClassTransformation transformation,
416:                    Class<? extends Annotation> annotationClass,
417:                    List<String> fieldNames) {
418:                expect(transformation.findFieldsWithAnnotation(annotationClass))
419:                        .andReturn(fieldNames);
420:            }
421:
422:            protected final void train_findFieldsWithAnnotation(
423:                    ClassTransformation transformation,
424:                    Class<? extends Annotation> annotationClass,
425:                    String... fieldNames) {
426:                train_findFieldsWithAnnotation(transformation, annotationClass,
427:                        Arrays.asList(fieldNames));
428:            }
429:
430:            protected final void train_findMethods(
431:                    ClassTransformation transformation,
432:                    final MethodSignature... signatures) {
433:                IAnswer<List<MethodSignature>> answer = new IAnswer<List<MethodSignature>>() {
434:                    public List<MethodSignature> answer() throws Throwable {
435:                        // Can't think of a way to do this without duplicating some code out of
436:                        // InternalClassTransformationImpl
437:
438:                        List<MethodSignature> result = newList();
439:                        MethodFilter filter = (MethodFilter) EasyMock
440:                                .getCurrentArguments()[0];
441:
442:                        for (MethodSignature sig : signatures) {
443:                            if (filter.accept(sig))
444:                                result.add(sig);
445:                        }
446:
447:                        // We don't have to sort them for testing purposes. Usually there's just going to be
448:                        // one in there.
449:
450:                        return result;
451:                    }
452:
453:                };
454:
455:                expect(
456:                        transformation.findMethods(EasyMock
457:                                .isA(MethodFilter.class))).andAnswer(answer);
458:            }
459:
460:            protected final void train_findMethodsWithAnnotation(
461:                    ClassTransformation tf,
462:                    Class<? extends Annotation> annotationType,
463:                    List<MethodSignature> sigs) {
464:                expect(tf.findMethodsWithAnnotation(annotationType)).andReturn(
465:                        sigs);
466:            }
467:
468:            protected final void train_findUnclaimedFields(
469:                    ClassTransformation transformation, String... fieldNames) {
470:                expect(transformation.findUnclaimedFields()).andReturn(
471:                        Arrays.asList(fieldNames));
472:            }
473:
474:            protected final void train_generateChecksum(
475:                    ResourceDigestGenerator generator, URL url, String digest) {
476:                expect(generator.generateDigest(url)).andReturn(digest);
477:            }
478:
479:            protected final <T> void train_get(
480:                    ApplicationStatePersistenceStrategy strategy,
481:                    Class<T> asoClass, ApplicationStateCreator<T> creator, T aso) {
482:                expect(strategy.get(asoClass, creator)).andReturn(aso);
483:            }
484:
485:            protected final void train_get(
486:                    ApplicationStatePersistenceStrategySource source,
487:                    String strategyName,
488:                    ApplicationStatePersistenceStrategy strategy) {
489:                expect(source.get(strategyName)).andReturn(strategy)
490:                        .atLeastOnce();
491:            }
492:
493:            protected final void train_get(Binding binding, Object value) {
494:                expect(binding.get()).andReturn(value);
495:            }
496:
497:            protected void train_getAttribute(HttpSession session,
498:                    String attributeName, Object value) {
499:                expect(session.getAttribute(attributeName)).andReturn(value);
500:            }
501:
502:            protected final void train_getAttribute(Session session,
503:                    String name, Object attribute) {
504:                expect(session.getAttribute(name)).andReturn(attribute);
505:            }
506:
507:            protected final void train_getAttributeNames(Session session,
508:                    String prefix, String... names) {
509:                expect(session.getAttributeNames(prefix)).andReturn(
510:                        Arrays.asList(names));
511:            }
512:
513:            protected final void train_getBaseResource(ComponentModel model,
514:                    Resource resource) {
515:                expect(model.getBaseResource()).andReturn(resource)
516:                        .atLeastOnce();
517:            }
518:
519:            protected final void train_getClassName(
520:                    ClassTransformation transformation, String className) {
521:                expect(transformation.getClassName()).andReturn(className)
522:                        .atLeastOnce();
523:            }
524:
525:            protected final void train_getClasspathAsset(AssetSource source,
526:                    String path, Asset asset) {
527:                expect(source.getClasspathAsset(path)).andReturn(asset);
528:            }
529:
530:            protected final void train_getClasspathAsset(AssetSource source,
531:                    String path, Locale locale, Asset asset) {
532:                expect(source.getClasspathAsset(path, locale)).andReturn(asset);
533:            }
534:
535:            protected final void train_getCompleteId(
536:                    ComponentResourcesCommon resources, String completeId) {
537:                expect(resources.getCompleteId()).andReturn(completeId)
538:                        .atLeastOnce();
539:            }
540:
541:            protected final void train_getComponent(
542:                    ComponentResources resources, Component component) {
543:                expect(resources.getComponent()).andReturn(component)
544:                        .atLeastOnce();
545:            }
546:
547:            protected final void train_getComponentClassName(
548:                    ComponentModel model, String className) {
549:                expect(model.getComponentClassName()).andReturn(className)
550:                        .atLeastOnce();
551:            }
552:
553:            protected final void train_getComponentResources(
554:                    Component component, ComponentResources resources) {
555:                expect(component.getComponentResources()).andReturn(resources)
556:                        .atLeastOnce();
557:            }
558:
559:            protected final void train_getConduit(PropertyModel model,
560:                    PropertyConduit conduit) {
561:                expect(model.getConduit()).andReturn(conduit).atLeastOnce();
562:            }
563:
564:            protected <C, T> void train_getConstraintType(
565:                    Validator<C, T> validator, Class<C> constraintType) {
566:                expect(validator.getConstraintType()).andReturn(constraintType)
567:                        .atLeastOnce();
568:            }
569:
570:            protected final void train_getContainer(
571:                    ComponentResources resources, Component container) {
572:                expect(resources.getContainer()).andReturn(container)
573:                        .atLeastOnce();
574:            }
575:
576:            protected final void train_getContainerMessages(
577:                    ComponentResources resources, Messages containerMessages) {
578:                expect(resources.getContainerMessages()).andReturn(
579:                        containerMessages).atLeastOnce();
580:            }
581:
582:            protected final void train_getContainerResources(
583:                    ComponentResources resources,
584:                    ComponentResources containerResources) {
585:                expect(resources.getContainerResources()).andReturn(
586:                        containerResources).atLeastOnce();
587:            }
588:
589:            protected final void train_getDateHeader(Request request,
590:                    String name, long value) {
591:                expect(request.getDateHeader(name)).andReturn(value)
592:                        .atLeastOnce();
593:            }
594:
595:            protected final <T extends Annotation> void train_getFieldAnnotation(
596:                    ClassTransformation transformation, String fieldName,
597:                    Class<T> annotationClass, T annotation) {
598:                expect(
599:                        transformation.getFieldAnnotation(fieldName,
600:                                annotationClass)).andReturn(annotation);
601:            }
602:
603:            protected final void train_getFieldPersistenceStrategy(
604:                    ComponentModel model, String fieldName, String fieldStrategy) {
605:                expect(model.getFieldPersistenceStrategy(fieldName)).andReturn(
606:                        fieldStrategy).atLeastOnce();
607:            }
608:
609:            protected final void train_getFieldType(
610:                    ClassTransformation transformation, String fieldName,
611:                    String type) {
612:                expect(transformation.getFieldType(fieldName)).andReturn(type)
613:                        .atLeastOnce();
614:
615:            }
616:
617:            protected final void train_getId(ComponentResources resources,
618:                    String id) {
619:                expect(resources.getId()).andReturn(id).atLeastOnce();
620:            }
621:
622:            protected final void train_getLabel(Field field, String label) {
623:                expect(field.getLabel()).andReturn(label).atLeastOnce();
624:            }
625:
626:            protected final void train_getLocale(
627:                    ComponentResourcesCommon resources, Locale locale) {
628:                expect(resources.getLocale()).andReturn(locale).atLeastOnce();
629:            }
630:
631:            protected final void train_getLocale(Request request, Locale locale) {
632:                expect(request.getLocale()).andReturn(locale).atLeastOnce();
633:            }
634:
635:            protected void train_getMessageKey(Validator validator,
636:                    String messageKey) {
637:                expect(validator.getMessageKey()).andReturn(messageKey)
638:                        .atLeastOnce();
639:            }
640:
641:            protected final void train_getMessages(
642:                    ComponentResources resources, Messages messages) {
643:                expect(resources.getMessages()).andReturn(messages)
644:                        .atLeastOnce();
645:            }
646:
647:            protected final void train_getMeta(ComponentModel model,
648:                    String key, String value) {
649:                expect(model.getMeta(key)).andReturn(value).atLeastOnce();
650:            }
651:
652:            protected final <T extends Annotation> void train_getMethodAnnotation(
653:                    ClassTransformation ct, MethodSignature signature,
654:                    Class<T> annotationClass, T annotation) {
655:                expect(ct.getMethodAnnotation(signature, annotationClass))
656:                        .andReturn(annotation).atLeastOnce();
657:            }
658:
659:            protected final void train_getMethodIdentifier(
660:                    ClassTransformation transformation,
661:                    MethodSignature signature, String id) {
662:                expect(transformation.getMethodIdentifier(signature))
663:                        .andReturn(id);
664:            }
665:
666:            protected final void train_getOutputStream(
667:                    HttpServletResponse response, ServletOutputStream stream) {
668:                try {
669:                    expect(response.getOutputStream()).andReturn(stream);
670:                } catch (IOException e) {
671:                    fail(e.getMessage(), e);
672:                }
673:            }
674:
675:            protected final void train_getPage(ComponentResources resources,
676:                    Component page) {
677:                expect(resources.getPage()).andReturn(page).atLeastOnce();
678:            }
679:
680:            protected final void train_getParameterModel(ComponentModel model,
681:                    String parameterName, ParameterModel parameterModel) {
682:                expect(model.getParameterModel(parameterName)).andReturn(
683:                        parameterModel);
684:            }
685:
686:            protected final void train_getParameterNames(ComponentModel model,
687:                    String... names) {
688:                expect(model.getParameterNames()).andReturn(
689:                        Arrays.asList(names));
690:            }
691:
692:            protected final void train_getParentModel(ComponentModel model,
693:                    ComponentModel parentModel) {
694:                expect(model.getParentModel()).andReturn(parentModel)
695:                        .atLeastOnce();
696:            }
697:
698:            protected final void train_getPath(Request request, String path) {
699:                expect(request.getPath()).andReturn(path).atLeastOnce();
700:            }
701:
702:            protected final void train_getPersistentFieldNames(
703:                    ComponentModel model, String... names) {
704:                expect(model.getPersistentFieldNames()).andReturn(
705:                        Arrays.asList(names)).atLeastOnce();
706:            }
707:
708:            protected final void train_getResourcesFieldName(
709:                    ClassTransformation transformation, String name) {
710:                expect(transformation.getResourcesFieldName()).andReturn(name)
711:                        .atLeastOnce();
712:            }
713:
714:            protected final void train_getRootResource(AssetFactory factory,
715:                    Resource rootResource) {
716:                expect(factory.getRootResource()).andReturn(rootResource);
717:            }
718:
719:            protected final void train_getSession(HttpServletRequest request,
720:                    boolean create, HttpSession session) {
721:                expect(request.getSession(create)).andReturn(session);
722:            }
723:
724:            protected void train_getSession(Request request, boolean create,
725:                    Session session) {
726:                expect(request.getSession(create)).andReturn(session);
727:            }
728:
729:            protected final void train_getSupportsInformalParameters(
730:                    ComponentModel model, boolean supports) {
731:                expect(model.getSupportsInformalParameters()).andReturn(
732:                        supports);
733:            }
734:
735:            protected final void train_getValidationMessages(
736:                    ValidationMessagesSource messagesSource, Locale locale,
737:                    Messages messages) {
738:                expect(messagesSource.getValidationMessages(locale)).andReturn(
739:                        messages).atLeastOnce();
740:            }
741:
742:            protected final void train_getValueType(Validator validator,
743:                    Class valueType) {
744:                expect(validator.getValueType()).andReturn(valueType)
745:                        .atLeastOnce();
746:            }
747:
748:            @SuppressWarnings("unchecked")
749:            protected final void train_handleResult(
750:                    ComponentEventHandler handler, Object result,
751:                    Component component, String methodDescription, boolean abort) {
752:                expect(
753:                        handler.handleResult(result, component,
754:                                methodDescription)).andReturn(abort);
755:            }
756:
757:            protected final void train_inError(ValidationTracker tracker,
758:                    Field field, boolean inError) {
759:                expect(tracker.inError(field)).andReturn(inError);
760:            }
761:
762:            protected final void train_invokeIfBlank(Validator validator,
763:                    boolean invokeIfBlank) {
764:                expect(validator.invokeIfBlank()).andReturn(invokeIfBlank)
765:                        .atLeastOnce();
766:            }
767:
768:            protected final void train_isInvariant(Binding binding,
769:                    boolean isInvariant) {
770:                expect(binding.isInvariant()).andReturn(isInvariant);
771:            }
772:
773:            protected final void train_isRequired(ParameterModel model,
774:                    boolean isRequired) {
775:                expect(model.isRequired()).andReturn(isRequired);
776:            }
777:
778:            protected final void train_isRootClass(MutableComponentModel model,
779:                    boolean isRootClass) {
780:                expect(model.isRootClass()).andReturn(isRootClass);
781:            }
782:
783:            protected final void train_name(Parameter parameter, String name) {
784:                expect(parameter.name()).andReturn(name).atLeastOnce();
785:            }
786:
787:            protected final void train_newBinding(BindingFactory factory,
788:                    String description, ComponentResources container,
789:                    ComponentResources component, String expression,
790:                    Location l, Binding binding) {
791:                expect(
792:                        factory.newBinding(description, container, component,
793:                                expression, l)).andReturn(binding);
794:            }
795:
796:            protected void train_newBinding(BindingSource bindingSource,
797:                    String description, ComponentResources componentResources,
798:                    String defaultBindingPrefix, String expression,
799:                    Binding binding) {
800:                expect(
801:                        bindingSource.newBinding(description,
802:                                componentResources, defaultBindingPrefix,
803:                                expression)).andReturn(binding);
804:            }
805:
806:            protected final void train_newMemberName(
807:                    ClassTransformation transformation, String suggested,
808:                    String name) {
809:                expect(transformation.newMemberName(suggested)).andReturn(name);
810:            }
811:
812:            protected final void train_newMemberName(
813:                    ClassTransformation transformation, String prefix,
814:                    String baseName, String name) {
815:                expect(transformation.newMemberName(prefix, baseName))
816:                        .andReturn(name);
817:            }
818:
819:            protected final <T> void train_peek(Environment env, Class<T> type,
820:                    T value) {
821:                expect(env.peek(type)).andReturn(value);
822:            }
823:
824:            protected final <T> void train_peekRequired(Environment env,
825:                    Class<T> type, T value) {
826:                expect(env.peekRequired(type)).andReturn(value);
827:            }
828:
829:            protected final void train_provideInjection(
830:                    InjectionProvider provider, String fieldName,
831:                    String fieldType, ObjectLocator locator,
832:                    ClassTransformation transformation,
833:                    MutableComponentModel model, boolean result) {
834:                expect(
835:                        provider.provideInjection(fieldName, fieldType,
836:                                locator, transformation, model)).andReturn(
837:                        result);
838:            }
839:
840:            @SuppressWarnings("unchecked")
841:            protected final void train_renderInformalParameters(
842:                    ComponentResources resources, final MarkupWriter writer,
843:                    final String... informals) {
844:                resources.renderInformalParameters(writer);
845:                IAnswer answer = new IAnswer() {
846:                    public Object answer() throws Throwable {
847:                        writer.attributes(informals);
848:
849:                        return null;
850:                    }
851:                };
852:
853:                getMocksControl().andAnswer(answer);
854:            }
855:
856:            protected final void train_requiresDigest(
857:                    ResourceDigestGenerator generator, String path,
858:                    boolean requiresDigest) {
859:                expect(generator.requiresDigest(path))
860:                        .andReturn(requiresDigest);
861:            }
862:
863:            protected final void train_service(RequestHandler handler,
864:                    Request request, Response response, boolean result)
865:                    throws IOException {
866:                expect(handler.service(request, response)).andReturn(result);
867:            }
868:
869:            protected final void train_setContentLength(
870:                    HttpServletResponse response, int length) {
871:                response.setContentLength(length);
872:            }
873:
874:            protected final void train_setContentType(
875:                    HttpServletResponse response, String contentType) {
876:                response.setContentType(contentType);
877:            }
878:
879:            protected final void train_setDateHeader(
880:                    HttpServletResponse response, String headerName, long date) {
881:                response.setDateHeader(headerName, date);
882:            }
883:
884:            protected final void train_toClass(
885:                    ClassTransformation transformation, String type,
886:                    Class classForType) {
887:                expect(transformation.toClass(type)).andReturn(classForType);
888:            }
889:
890:            protected final void train_toClientURL(Asset asset, String URL) {
891:                expect(asset.toClientURL()).andReturn(URL).atLeastOnce();
892:            }
893:
894:            protected final void train_toClientURL(
895:                    ClasspathAssetAliasManager manager, String resourcePath,
896:                    String clientURL) {
897:                expect(manager.toClientURL(resourcePath)).andReturn(clientURL);
898:            }
899:
900:            protected final void train_toRedirectURI(Link link, String URI) {
901:                expect(link.toRedirectURI()).andReturn(URI).atLeastOnce();
902:            }
903:
904:            protected final void train_toResourcePath(
905:                    ClasspathAssetAliasManager manager, String clientURL,
906:                    String resourcePath) {
907:                expect(manager.toResourcePath(clientURL)).andReturn(
908:                        resourcePath).atLeastOnce();
909:            }
910:
911:            protected final void train_value(Id annotation, String value) {
912:                expect(annotation.value()).andReturn(value).atLeastOnce();
913:            }
914:
915:            protected final void train_value(Path annotation, String value) {
916:                expect(annotation.value()).andReturn(value).atLeastOnce();
917:            }
918:
919:            protected final void train_create(BeanModelSource source,
920:                    Class beanClass, boolean filterReadOnly,
921:                    ComponentResources containerResources, BeanModel model) {
922:                expect(
923:                        source.create(beanClass, filterReadOnly,
924:                                containerResources)).andReturn(model);
925:            }
926:
927:            protected final void train_getBoundType(
928:                    ComponentResources resources, Class type) {
929:                expect(resources.getBoundType("object")).andReturn(type);
930:            }
931:
932:            protected final BeanModel mockBeanModel() {
933:                return newMock(BeanModel.class);
934:            }
935:
936:            protected final BeanModelSource mockBeanModelSource() {
937:                return newMock(BeanModelSource.class);
938:            }
939:
940:            public final void train_getLocation(Locatable locatable,
941:                    Location location) {
942:                expect(locatable.getLocation()).andReturn(location)
943:                        .atLeastOnce();
944:            }
945:
946:            protected final void train_getParameter(Request request,
947:                    String elementName, String value) {
948:                expect(request.getParameter(elementName)).andReturn(value)
949:                        .atLeastOnce();
950:            }
951:
952:            protected final void train_getPageName(
953:                    ComponentResourcesCommon resources, String pageName) {
954:                expect(resources.getPageName()).andReturn(pageName)
955:                        .atLeastOnce();
956:            }
957:
958:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.