Source Code Cross Referenced for TestActionCreator.java in  » Web-Framework » Strecks » org » strecks » controller » 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 » Strecks » org.strecks.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005:         * in compliance with the License. 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 distributed under the License
010:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011:         * or implied. See the License for the specific language governing permissions and limitations under
012:         * the License.
013:         */
014:
015:        package org.strecks.controller;
016:
017:        import static org.testng.Assert.assertEquals;
018:
019:        import java.util.Collection;
020:
021:        import org.apache.struts.action.Action;
022:        import org.strecks.action.navigable.NavigableController;
023:        import org.strecks.controller.impl.AbstractControllerAction;
024:        import org.strecks.controller.impl.ActionWithNonInterface;
025:        import org.strecks.controller.impl.ActionWithNonStrutsControllerAction;
026:        import org.strecks.controller.impl.ReadOnlyAction;
027:        import org.strecks.controller.impl.ReadOnlyControllerAction;
028:        import org.strecks.controller.impl.TestAction;
029:        import org.strecks.exceptions.ApplicationConfigurationException;
030:        import org.strecks.navigate.NavigationHolder;
031:        import org.strecks.navigate.internal.impl.ActionWithNavigate;
032:        import org.strecks.navigate.internal.impl.ActionWithNoNavigate;
033:        import org.testng.Assert;
034:        import org.testng.annotations.BeforeMethod;
035:        import org.testng.annotations.Test;
036:
037:        /**
038:         * @author Phil Zoio
039:         */
040:        public class TestActionCreator {
041:
042:            private ActionCreatorImpl actionCreator;
043:
044:            @BeforeMethod
045:            public void setUp() {
046:                actionCreator = new ActionCreatorImpl();
047:            }
048:
049:            /**
050:             * Coarse grained test on happy path. Creates controller action and actionBean which satisfy mutual depependency
051:             * requirements
052:             */
053:            @Test
054:            public void testActionCreate() throws Exception {
055:
056:                Action createAction = actionCreator
057:                        .createAction(TestAction.class);
058:
059:                assert createAction instanceof  ControllerAction;
060:
061:                ControllerAction controllerAction = (ControllerAction) createAction;
062:                Object newActionBean = controllerAction.getBeanSource()
063:                        .createBean(null);
064:
065:                assert newActionBean instanceof  TestAction;
066:
067:            }
068:
069:            @Test
070:            public void testCreateControllerAction() throws Exception {
071:
072:                Action createAction = actionCreator
073:                        .createControllerAction(TestAction.class);
074:
075:                assert createAction instanceof  ControllerAction;
076:
077:                ControllerAction controllerAction = (ControllerAction) createAction;
078:                Object newActionBean = controllerAction.getBeanSource()
079:                        .createBean(null);
080:
081:                assert newActionBean instanceof  TestAction;
082:
083:                assert createAction instanceof  BaseControllerAction;
084:                BaseControllerAction bc = (BaseControllerAction) createAction;
085:                Assert.assertNotNull(bc.getInitMethod());
086:
087:            }
088:
089:            @Test
090:            public void testGetActionInterfaceType() throws Exception {
091:                Class actionInterfaceType = actionCreator
092:                        .getActionInterfaceType(ReadOnlyControllerAction.class,
093:                                null);
094:                assertEquals(actionInterfaceType, ReadOnlyAction.class);
095:            }
096:
097:            @Test(expectedExceptions=ApplicationConfigurationException.class)
098:            public void noActionInterfaceAnnotation() {
099:                actionCreator.getActionInterfaceType(String.class,
100:                        TestAction.class);
101:            }
102:
103:            @Test(expectedExceptions=ApplicationConfigurationException.class)
104:            public void actionInterfaceNotInterface() {
105:                actionCreator.getActionInterfaceType(
106:                        ActionWithNonInterface.class, TestAction.class);
107:            }
108:
109:            @Test
110:            public void instantiateControllerAction() {
111:                Object instantiateControllerAction = actionCreator
112:                        .instantiateControllerAction(
113:                                ReadOnlyControllerAction.class,
114:                                TestAction.class);
115:                // assert instantiateControllerAction instanceof ReadOnlyControllerAction;
116:                System.out.println(instantiateControllerAction);
117:            }
118:
119:            @Test(expectedExceptions=ApplicationConfigurationException.class)
120:            public void abstractControllerAction() {
121:                actionCreator.instantiateControllerAction(
122:                        AbstractControllerAction.class, TestAction.class);
123:            }
124:
125:            @Test(expectedExceptions=ApplicationConfigurationException.class)
126:            public void privateControllerAction() throws Exception {
127:                actionCreator
128:                        .instantiateControllerAction(
129:                                Class
130:                                        .forName("org.strecks.controller.impl.PrivateControllerAction"),
131:                                TestAction.class);
132:            }
133:
134:            @Test
135:            public void testIsAssignable() {
136:                actionCreator.checkIsAssignable(TestAction.class,
137:                        ReadOnlyAction.class, ReadOnlyControllerAction.class);
138:            }
139:
140:            @Test(expectedExceptions=ApplicationConfigurationException.class)
141:            public void nonImplementingInterface() throws Exception {
142:                actionCreator.checkIsAssignable(TestAction.class,
143:                        Collection.class, ReadOnlyControllerAction.class);
144:            }
145:
146:            @Test
147:            public void testGetControllerClass() {
148:                Class controllerClass = actionCreator
149:                        .getControllerClass(TestAction.class);
150:                assertEquals(controllerClass, ReadOnlyControllerAction.class);
151:            }
152:
153:            @Test
154:            public void testControllerNotStrutsAction() {
155:                try {
156:                    actionCreator.getControllerClass(String.class);
157:                } catch (ApplicationConfigurationException e) {
158:                    assertEquals(
159:                            e.getMessage(),
160:                            "java.lang.String is not a Struts Action subclass and does not have a org.strecks.controller.annotation.Controller annotation");
161:                }
162:            }
163:
164:            @Test
165:            public void testActionWithControllerNotStrutsAction() {
166:                try {
167:                    actionCreator
168:                            .getControllerClass(ActionWithNonStrutsControllerAction.class);
169:                } catch (ApplicationConfigurationException e) {
170:                    assertEquals(
171:                            e.getMessage(),
172:                            "org.strecks.controller.impl.ActionWithNonStrutsControllerAction is has a org.strecks.controller.annotation.Controller annotation "
173:                                    + "which points to the class org.strecks.controller.impl.NonStrutsActionControllerAction which is not a Struts Action subclass");
174:                }
175:            }
176:
177:            /**
178:             * Tests creation with navigate mechanism
179:             */
180:            @Test
181:            public void testCreateWithNavigate() throws Exception {
182:
183:                NavigableControllerAction createAction = (NavigableControllerAction) actionCreator
184:                        .createAction(ActionWithNavigate.class);
185:                assert null != createAction.getNavigationHolder();
186:
187:            }
188:
189:            /**
190:             * Tests creation with navigate mechanism
191:             */
192:            @Test
193:            public void testCreateWithNoNavigate() throws Exception {
194:
195:                ControllerAction createAction = (ControllerAction) actionCreator
196:                        .createAction(ActionWithNoNavigate.class);
197:                assert !(createAction instanceof  NavigableControllerAction);
198:
199:            }
200:
201:            /**
202:             * Tests reading the annotation extension handling mechanism
203:             */
204:            @Test
205:            public void testReadControllerClassAnnotations() throws Exception {
206:
207:                NavigableController controller = new NavigableController();
208:                actionCreator.readControllerClassAnnotations(
209:                        ActionWithNavigate.class, controller);
210:
211:                NavigationHolder navigationHolder = controller
212:                        .getNavigationHolder();
213:                assert navigationHolder != null;
214:
215:            }
216:
217:            /**
218:             * Tests reading the annotation extension handling mechanism
219:             */
220:            @Test
221:            public void testNoAnnotations() throws Exception {
222:
223:                try {
224:                    NavigableController controller = new NavigableController();
225:                    actionCreator.readControllerClassAnnotations(
226:                            ActionWithNoNavigate.class, controller);
227:                } catch (ApplicationConfigurationException e) {
228:                    assertEquals(
229:                            e.getMessage(),
230:                            "No annotation using the @NavigationInfo annotation found. This is needed to determine the navigation for the action bean class org.strecks.navigate.internal.impl.ActionWithNoNavigate");
231:                }
232:
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.