Source Code Cross Referenced for XSLTResultTest.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » views » xslt » 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 » J2EE » webwork 2.2.6 » com.opensymphony.webwork.views.xslt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.views.xslt;
006:
007:        import com.opensymphony.webwork.ServletActionContext;
008:        import com.opensymphony.xwork.Action;
009:        import com.opensymphony.xwork.ActionContext;
010:        import com.opensymphony.xwork.mock.MockActionInvocation;
011:        import com.opensymphony.xwork.util.OgnlValueStack;
012:        import junit.framework.TestCase;
013:        import org.springframework.core.io.DefaultResourceLoader;
014:        import org.springframework.mock.web.MockHttpServletRequest;
015:        import org.springframework.mock.web.MockHttpServletResponse;
016:        import org.springframework.mock.web.MockServletContext;
017:
018:        import javax.xml.transform.TransformerException;
019:        import java.util.List;
020:        import java.util.ArrayList;
021:
022:        /**
023:         * Unit test for {@link XSLTResult}.
024:         *
025:         * @author Claus Ibsen
026:         */
027:        public class XSLTResultTest extends TestCase {
028:
029:            private XSLTResult result;
030:            private MockHttpServletResponse response;
031:            private MockHttpServletRequest request;
032:            private MockServletContext servletContext;
033:            private MockActionInvocation mai;
034:            private OgnlValueStack stack;
035:
036:            public void testNoLocation() throws Exception {
037:                try {
038:                    result.setParse(false);
039:                    result.setLocation(null);
040:                    result.execute(mai);
041:                    fail("Should have thrown an IllegalArgumentException");
042:                } catch (IllegalArgumentException e) {
043:                    // success
044:                }
045:            }
046:
047:            public void testNoFileFound() throws Exception {
048:                try {
049:                    result.setParse(false);
050:                    result.setLocation("nofile.xsl");
051:                    result.execute(mai);
052:                    fail("Should have thrown a TransformerException");
053:                } catch (TransformerException e) {
054:                    // success
055:                }
056:            }
057:
058:            public void testSimpleTransform() throws Exception {
059:                // TODO: XSLTResult does not work with JDK1.5
060:
061:                result.setParse(false);
062:                result.setLocation("XSLTResultTest.xsl");
063:                result.execute(mai);
064:
065:                String out = response.getContentAsString();
066:                assertTrue(out
067:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
068:                assertTrue(out
069:                        .indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
070:            }
071:
072:            public void testSimpleTransformParse() throws Exception {
073:                result.setParse(true);
074:                result.setLocation("${top.myLocation}");
075:                result.execute(mai);
076:
077:                String out = response.getContentAsString();
078:                assertTrue(out
079:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
080:                assertTrue(out
081:                        .indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
082:            }
083:
084:            public void testTransform2() throws Exception {
085:                result.setParse(false);
086:                result.setLocation("XSLTResultTest2.xsl");
087:                result.execute(mai);
088:
089:                String out = response.getContentAsString();
090:                assertTrue(out
091:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
092:                assertTrue(out
093:                        .indexOf("<html xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
094:                assertTrue(out.indexOf("Hello Santa Claus how are you?") > -1);
095:            }
096:
097:            public void testTransform3() throws Exception {
098:                result.setParse(false);
099:                result.setLocation("XSLTResultTest3.xsl");
100:                result.execute(mai);
101:
102:                String out = response.getContentAsString();
103:                assertTrue(out
104:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
105:                assertTrue(out
106:                        .indexOf("<html xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
107:                assertTrue(out.indexOf("Hello Santa Claus how are you?") > -1);
108:                assertTrue(out
109:                        .indexOf("WebWork in Action by Patrick and Jason") > -1);
110:                // TODO: There is a bug in XSLTResult and having collections
111:                assertTrue(out.indexOf("XWork not in Action by Superman") > -1);
112:            }
113:
114:            protected void setUp() throws Exception {
115:                request = new MockHttpServletRequest();
116:                response = new MockHttpServletResponse();
117:                servletContext = new MockServletContext(
118:                        new DefaultResourceLoader());
119:
120:                result = new XSLTResult();
121:                stack = new OgnlValueStack();
122:                ActionContext.getContext().setValueStack(stack);
123:
124:                MyAction action = new MyAction();
125:
126:                mai = new com.opensymphony.xwork.mock.MockActionInvocation();
127:                mai.setAction(action);
128:                mai.setStack(stack);
129:                mai.setInvocationContext(ActionContext.getContext());
130:                stack.push(action);
131:
132:                ActionContext.getContext().put(
133:                        ServletActionContext.HTTP_REQUEST, request);
134:                ActionContext.getContext().put(
135:                        ServletActionContext.HTTP_RESPONSE, response);
136:                ActionContext.getContext().put(
137:                        ServletActionContext.SERVLET_CONTEXT, servletContext);
138:            }
139:
140:            protected void tearDown() {
141:                request = null;
142:                response = null;
143:                servletContext = null;
144:                result = null;
145:                stack = null;
146:                mai = null;
147:            }
148:
149:            private class MyAction implements  Action {
150:
151:                public String execute() throws Exception {
152:                    return SUCCESS;
153:                }
154:
155:                public String getMyLocation() {
156:                    return ("XSLTResultTest.xsl");
157:                }
158:
159:                public String getUsername() {
160:                    return "Santa Claus";
161:                }
162:
163:                public List getBooks() {
164:                    List list = new ArrayList();
165:                    list
166:                            .add(new Book("WebWork in Action",
167:                                    "Patrick and Jason"));
168:                    list.add(new Book("XWork not in Action", "Superman"));
169:                    return list;
170:                }
171:
172:            }
173:
174:            public class Book {
175:
176:                private String title;
177:                private String author;
178:
179:                public Book(String title, String author) {
180:                    this .title = title;
181:                    this .author = author;
182:                }
183:
184:                public String getTitle() {
185:                    return title;
186:                }
187:
188:                public String getAuthor() {
189:                    return author;
190:                }
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.