Source Code Cross Referenced for CommandResolverTest.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » ui » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Janne Jalkanen 2005
003:         * 
004:         */
005:        package com.ecyrd.jspwiki.ui;
006:
007:        import java.util.Properties;
008:
009:        import junit.framework.Test;
010:        import junit.framework.TestCase;
011:        import junit.framework.TestSuite;
012:
013:        import com.ecyrd.jspwiki.TestEngine;
014:        import com.ecyrd.jspwiki.TestHttpServletRequest;
015:        import com.ecyrd.jspwiki.WikiContext;
016:        import com.ecyrd.jspwiki.WikiEngine;
017:        import com.ecyrd.jspwiki.WikiPage;
018:        import com.ecyrd.jspwiki.auth.GroupPrincipal;
019:
020:        public class CommandResolverTest extends TestCase {
021:            TestEngine testEngine;
022:            CommandResolver resolver;
023:
024:            protected void setUp() throws Exception {
025:                Properties props = new Properties();
026:                props.load(TestEngine.findTestProperties());
027:                props.put(WikiEngine.PROP_MATCHPLURALS, "yes");
028:                testEngine = new TestEngine(props);
029:                resolver = testEngine.getCommandResolver();
030:                testEngine.saveText("SinglePage", "This is a test.");
031:                testEngine.saveText("PluralPages", "This is a test.");
032:            }
033:
034:            protected void tearDown() throws Exception {
035:                testEngine.deletePage("TestPage");
036:                testEngine.deletePage("SinglePage");
037:                testEngine.deletePage("PluralPage");
038:            }
039:
040:            public void testFindStaticWikiAction() {
041:                Command a;
042:
043:                // If we look for action with "edit" request context, we get EDIT action
044:                a = CommandResolver.findCommand(WikiContext.EDIT);
045:                assertEquals(PageCommand.EDIT, a);
046:                assertEquals(WikiContext.EDIT, a.getRequestContext());
047:
048:                // Ditto for prefs context
049:                a = CommandResolver.findCommand(WikiContext.PREFS);
050:                assertEquals(WikiCommand.PREFS, a);
051:                assertEquals(WikiContext.PREFS, a.getRequestContext());
052:
053:                // Ditto for group view context
054:                a = CommandResolver.findCommand(WikiContext.VIEW_GROUP);
055:                assertEquals(GroupCommand.VIEW_GROUP, a);
056:                assertEquals(WikiContext.VIEW_GROUP, a.getRequestContext());
057:
058:                // Looking for non-existent context; should result in exception
059:                try {
060:                    a = CommandResolver.findCommand("nonExistentContext");
061:                    assertFalse("Context supported, strangely...", true);
062:                } catch (IllegalArgumentException e) {
063:                    // Good; this is what we expect
064:                }
065:            }
066:
067:            public void testFindWikiActionNoParams() {
068:                Command a;
069:                TestHttpServletRequest request = new TestHttpServletRequest();
070:
071:                // Passing an EDIT request with no explicit page params means the EDIT action
072:                a = resolver.findCommand(request, WikiContext.EDIT);
073:                assertEquals(PageCommand.EDIT, a);
074:                assertEquals("EditContent.jsp", a.getContentTemplate());
075:                assertEquals("Edit.jsp", a.getJSP());
076:                assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
077:                assertNull(a.getTarget());
078:
079:                // Ditto for prefs context
080:                a = resolver.findCommand(request, WikiContext.PREFS);
081:                assertEquals(WikiCommand.PREFS, a);
082:                assertNull(a.getTarget());
083:
084:                // Ditto for group view context
085:                a = resolver.findCommand(request, WikiContext.VIEW_GROUP);
086:                assertEquals(GroupCommand.VIEW_GROUP, a);
087:                assertNull(a.getTarget());
088:
089:                // Looking for non-existent context; should result in exception
090:                try {
091:                    a = resolver.findCommand(request, "nonExistentContext");
092:                    assertFalse("Context supported, strangely...", true);
093:                } catch (IllegalArgumentException e) {
094:                    // Good; this is what we expect
095:                }
096:
097:                // Request for "UserPreference.jsp" should resolve to PREFS action
098:                request.setServletPath("/UserPreferences.jsp");
099:                a = resolver.findCommand(request, WikiContext.EDIT);
100:                assertEquals(WikiCommand.PREFS, a);
101:                assertNull(a.getTarget());
102:
103:                // Request for "NewGroup.jsp" should resolve to CREATE_GROUP action
104:                // but targeted at the wiki
105:                request.setServletPath("/NewGroup.jsp");
106:                a = resolver.findCommand(request, WikiContext.EDIT);
107:                assertNotSame(WikiCommand.CREATE_GROUP, a);
108:                assertEquals(WikiCommand.CREATE_GROUP.getRequestContext(), a
109:                        .getRequestContext());
110:                assertEquals(testEngine.getApplicationName(), a.getTarget());
111:
112:                // But request for JSP not mapped to action should get default
113:                request.setServletPath("/NonExistent.jsp");
114:                a = resolver.findCommand(request, WikiContext.EDIT);
115:                assertEquals(PageCommand.EDIT, a);
116:                assertNull(a.getTarget());
117:            }
118:
119:            public void testFindWikiActionWithParams() throws Exception {
120:                Command a;
121:                WikiPage page = testEngine.getPage("SinglePage");
122:
123:                // Passing an EDIT request with page param yields a wrapped action
124:                TestHttpServletRequest request = new TestHttpServletRequest();
125:                request.setParameter("page", "SinglePage");
126:                request.setServletPath("/Edit.jsp?page=SinglePage");
127:                a = resolver.findCommand(request, WikiContext.EDIT);
128:                assertNotSame(PageCommand.EDIT, a);
129:                assertEquals("EditContent.jsp", a.getContentTemplate());
130:                assertEquals("Edit.jsp", a.getJSP());
131:                assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
132:                assertEquals(page, a.getTarget());
133:
134:                // Passing an EDIT request with page=FindPage yields FIND action, *not* edit
135:                request.setParameter("page", "FindPage");
136:                request.setServletPath("/Edit.jsp?page=FindPage");
137:                a = resolver.findCommand(request, WikiContext.EDIT);
138:                assertEquals(WikiCommand.FIND, a);
139:                assertEquals("FindContent.jsp", a.getContentTemplate());
140:                assertEquals("Search.jsp", a.getJSP());
141:                assertEquals("%uSearch.jsp", a.getURLPattern());
142:                assertNull(a.getTarget());
143:
144:                // Passing an EDIT request with group="Foo" yields wrapped VIEW_GROUP
145:                request = new TestHttpServletRequest();
146:                request.setParameter("group", "Foo");
147:                request.setServletPath("/Group.jsp?group=Foo");
148:                a = resolver.findCommand(request, WikiContext.EDIT);
149:                assertNotSame(GroupCommand.VIEW_GROUP, a);
150:                assertEquals("GroupContent.jsp", a.getContentTemplate());
151:                assertEquals("Group.jsp", a.getJSP());
152:                assertEquals("%uGroup.jsp?group=%n", a.getURLPattern());
153:                assertEquals(new GroupPrincipal("Foo"), a.getTarget());
154:            }
155:
156:            public void testFindWikiActionWithPath() {
157:                TestHttpServletRequest request;
158:                Command a;
159:
160:                // Passing an EDIT request with View JSP yields EDIT of the Front page
161:                request = new TestHttpServletRequest();
162:                request.setServletPath("/Wiki.jsp");
163:                a = resolver.findCommand(request, WikiContext.EDIT);
164:                assertNotNull(a.getTarget());
165:                assertEquals(((WikiPage) a.getTarget()).getName(), testEngine
166:                        .getFrontPage());
167:
168:                // Passing an EDIT request with Group JSP yields VIEW_GROUP
169:                request.setServletPath("/Group.jsp");
170:                a = resolver.findCommand(request, WikiContext.EDIT);
171:                assertEquals(GroupCommand.VIEW_GROUP, a);
172:                assertNull(a.getTarget());
173:
174:                // Passing an EDIT request with UserPreferences JSP yields PREFS
175:                request.setServletPath("/UserPreferences.jsp");
176:                a = resolver.findCommand(request, WikiContext.EDIT);
177:                assertEquals(WikiCommand.PREFS, a);
178:                assertNull(a.getTarget());
179:            }
180:
181:            public void testFinalPageName() throws Exception {
182:                String page;
183:                page = resolver.getFinalPageName("SinglePage");
184:                assertEquals("SinglePage", page);
185:                page = resolver.getFinalPageName("SinglePages");
186:                assertEquals("SinglePage", page);
187:
188:                page = resolver.getFinalPageName("PluralPages");
189:                assertEquals("PluralPages", page);
190:                page = resolver.getFinalPageName("PluralPage");
191:                assertEquals("PluralPages", page);
192:
193:                page = resolver.getFinalPageName("NonExistentPage");
194:                assertNull(page);
195:            }
196:
197:            public void testSpecialPageReference() {
198:                String url;
199:                url = resolver.getSpecialPageReference("RecentChanges");
200:                assertEquals("http://localhost/RecentChanges.jsp", url);
201:
202:                url = resolver.getSpecialPageReference("FindPage");
203:                assertEquals("http://localhost/Search.jsp", url);
204:
205:                url = resolver.getSpecialPageReference("FindPage");
206:                assertEquals("http://localhost/Search.jsp", url);
207:
208:                // UserPrefs doesn't exist in our test properties
209:                url = resolver.getSpecialPageReference("UserPrefs");
210:                assertNull(url);
211:            }
212:
213:            public static Test suite() {
214:                return new TestSuite(CommandResolverTest.class);
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.