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


001:        package com.ecyrd.jspwiki.xmlrpc;
002:
003:        import com.ecyrd.jspwiki.*;
004:        import com.ecyrd.jspwiki.attachment.Attachment;
005:        import junit.framework.*;
006:        import java.util.*;
007:        import org.apache.xmlrpc.*;
008:        import com.ecyrd.jspwiki.xmlrpc.RPCHandler;
009:
010:        public class RPCHandlerTest extends TestCase {
011:            TestEngine m_engine;
012:            RPCHandler m_handler;
013:            Properties m_props;
014:
015:            static final String NAME1 = "Test";
016:
017:            public RPCHandlerTest(String s) {
018:                super (s);
019:            }
020:
021:            public void setUp() throws Exception {
022:                m_props = new Properties();
023:                m_props.load(TestEngine.findTestProperties());
024:
025:                m_engine = new TestEngine(m_props);
026:
027:                m_handler = new RPCHandler();
028:                WikiContext ctx = new WikiContext(m_engine, new WikiPage(
029:                        m_engine, "Dummy"));
030:                m_handler.initialize(ctx);
031:            }
032:
033:            public void tearDown() {
034:                TestEngine.deleteTestPage(NAME1);
035:                m_engine.deleteAttachments(NAME1);
036:                TestEngine.emptyWorkDir();
037:            }
038:
039:            public void testNonexistantPage() {
040:                try {
041:                    m_handler.getPage("NoSuchPage");
042:                    fail("No exception for missing page.");
043:                } catch (XmlRpcException e) {
044:                    assertEquals("Wrong error code.", RPCHandler.ERR_NOPAGE,
045:                            e.code);
046:                }
047:            }
048:
049:            public void testRecentChanges() throws Exception {
050:                Date time = getCalendarTime(Calendar.getInstance().getTime());
051:                Vector previousChanges = m_handler.getRecentChanges(time);
052:
053:                m_engine.saveText(NAME1, "Foo");
054:                WikiPage directInfo = m_engine.getPage(NAME1);
055:                time = getCalendarTime(directInfo.getLastModified());
056:                Vector recentChanges = m_handler.getRecentChanges(time);
057:
058:                assertEquals("wrong number of changes", 1, recentChanges.size()
059:                        - previousChanges.size());
060:            }
061:
062:            public void testRecentChangesWithAttachments() throws Exception {
063:                Date time = getCalendarTime(Calendar.getInstance().getTime());
064:                Vector previousChanges = m_handler.getRecentChanges(time);
065:
066:                m_engine.saveText(NAME1, "Foo");
067:                Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
068:                att.setAuthor("FirstPost");
069:                m_engine.getAttachmentManager().storeAttachment(att,
070:                        m_engine.makeAttachmentFile());
071:                WikiPage directInfo = m_engine.getPage(NAME1);
072:                time = getCalendarTime(directInfo.getLastModified());
073:                Vector recentChanges = m_handler.getRecentChanges(time);
074:
075:                assertEquals("wrong number of changes", 1, recentChanges.size()
076:                        - previousChanges.size());
077:            }
078:
079:            public void testPageInfo() throws Exception {
080:                m_engine.saveText(NAME1, "Foobar.[{ALLOW view Anonymous}]");
081:                WikiPage directInfo = m_engine.getPage(NAME1);
082:
083:                Hashtable ht = m_handler.getPageInfo(NAME1);
084:                assertEquals("name", (String) ht.get("name"), NAME1);
085:
086:                Date d = (Date) ht.get("lastModified");
087:
088:                Calendar cal = Calendar.getInstance();
089:                cal.setTime(d);
090:
091:                System.out.println("Real: " + directInfo.getLastModified());
092:                System.out.println("RPC:  " + d);
093:
094:                // Offset the ZONE offset and DST offset away.  DST only
095:                // if we're actually in DST.
096:                cal.add(Calendar.MILLISECOND,
097:                        (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone()
098:                                .inDaylightTime(d) ? cal
099:                                .get(Calendar.DST_OFFSET) : 0)));
100:                System.out.println("RPC2: " + cal.getTime());
101:
102:                assertEquals("date", cal.getTime().getTime(), directInfo
103:                        .getLastModified().getTime());
104:            }
105:
106:            /**
107:             *  Tests if listLinks() works with a single, non-existant local page.
108:             */
109:            public void testListLinks() throws Exception {
110:                String text = "[Foobar]";
111:                String pageName = NAME1;
112:
113:                m_engine.saveText(pageName, text);
114:
115:                Vector links = m_handler.listLinks(pageName);
116:
117:                assertEquals("link count", 1, links.size());
118:
119:                Hashtable linkinfo = (Hashtable) links.elementAt(0);
120:
121:                assertEquals("name", "Foobar", linkinfo.get("page"));
122:                assertEquals("type", "local", linkinfo.get("type"));
123:                assertEquals("href", "http://localhost/Edit.jsp?page=Foobar",
124:                        linkinfo.get("href"));
125:            }
126:
127:            public void testListLinksWithAttachments() throws Exception {
128:                String text = "[Foobar] [Test/TestAtt.txt]";
129:                String pageName = NAME1;
130:
131:                m_engine.saveText(pageName, text);
132:
133:                Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
134:                att.setAuthor("FirstPost");
135:                m_engine.getAttachmentManager().storeAttachment(att,
136:                        m_engine.makeAttachmentFile());
137:
138:                // Test.
139:
140:                Vector links = m_handler.listLinks(pageName);
141:
142:                assertEquals("link count", 2, links.size());
143:
144:                Hashtable linkinfo = (Hashtable) links.elementAt(0);
145:
146:                assertEquals("edit name", "Foobar", linkinfo.get("page"));
147:                assertEquals("edit type", "local", linkinfo.get("type"));
148:                assertEquals("edit href",
149:                        "http://localhost/Edit.jsp?page=Foobar", linkinfo
150:                                .get("href"));
151:
152:                linkinfo = (Hashtable) links.elementAt(1);
153:
154:                assertEquals("att name", NAME1 + "/TestAtt.txt", linkinfo
155:                        .get("page"));
156:                assertEquals("att type", "local", linkinfo.get("type"));
157:                assertEquals("att href", "http://localhost/attach/" + NAME1
158:                        + "/TestAtt.txt", linkinfo.get("href"));
159:            }
160:
161:            private Date getCalendarTime(Date modifiedDate) {
162:                Calendar cal = Calendar.getInstance();
163:                cal.setTime(modifiedDate);
164:                cal.add(Calendar.HOUR, -1);
165:
166:                // Go to UTC
167:                // Offset the ZONE offset and DST offset away.  DST only
168:                // if we're actually in DST.
169:                cal.add(Calendar.MILLISECOND,
170:                        -(cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone()
171:                                .inDaylightTime(modifiedDate) ? cal
172:                                .get(Calendar.DST_OFFSET) : 0)));
173:
174:                return cal.getTime();
175:            }
176:
177:            /*
178:             * TODO: ENABLE
179:            public void testPermissions()
180:                throws Exception
181:            {
182:                String text ="Blaa. [{DENY view Guest}] [{ALLOW view NamedGuest}]";
183:
184:                m_engine.saveText( NAME1, text );
185:
186:                try
187:                {
188:                    Vector links = m_handler.listLinks( NAME1 );
189:                    fail("Didn't get an exception in listLinks()");
190:                }
191:                catch( XmlRpcException e ) {}
192:
193:                try
194:                {
195:                    Hashtable ht = m_handler.getPageInfo( NAME1 );
196:                    fail("Didn't get an exception in getPageInfo()");
197:                }
198:                catch( XmlRpcException e ) {}
199:            }
200:             */
201:
202:            public static Test suite() {
203:                return new TestSuite(RPCHandlerTest.class);
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.