Source Code Cross Referenced for XSLTResultTest.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » 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 » Web Framework » struts 2.0.11 » org.apache.struts2.views.xslt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: XSLTResultTest.java 481180 2006-12-01 08:02:59Z mrdon $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.views.xslt;
022:
023:        import java.util.ArrayList;
024:        import java.util.List;
025:
026:        import javax.xml.transform.Source;
027:        import javax.xml.transform.TransformerException;
028:        import javax.xml.transform.URIResolver;
029:        import javax.xml.transform.stream.StreamSource;
030:
031:        import org.apache.struts2.ServletActionContext;
032:        import org.apache.struts2.StrutsTestCase;
033:        import org.apache.struts2.util.ClassLoaderUtils;
034:        import org.springframework.mock.web.MockHttpServletRequest;
035:        import org.springframework.mock.web.MockHttpServletResponse;
036:        import org.springframework.mock.web.MockServletContext;
037:
038:        import com.opensymphony.xwork2.Action;
039:        import com.opensymphony.xwork2.ActionContext;
040:        import com.opensymphony.xwork2.mock.MockActionInvocation;
041:        import com.opensymphony.xwork2.util.ValueStack;
042:        import com.opensymphony.xwork2.util.ValueStackFactory;
043:
044:        /**
045:         * Unit test for {@link XSLTResult}.
046:         *
047:         */
048:        public class XSLTResultTest extends StrutsTestCase {
049:
050:            private XSLTResult result;
051:            private MockHttpServletResponse response;
052:            private MockHttpServletRequest request;
053:            private MockServletContext servletContext;
054:            private MockActionInvocation mai;
055:            private ValueStack stack;
056:
057:            public void testNoLocation() throws Exception {
058:                try {
059:                    result.setParse(false);
060:                    result.setLocation(null);
061:                    result.execute(mai);
062:                    fail("Should have thrown an IllegalArgumentException");
063:                } catch (IllegalArgumentException e) {
064:                    // success
065:                }
066:            }
067:
068:            public void testNoFileFound() throws Exception {
069:                try {
070:                    result.setParse(false);
071:                    result.setLocation("nofile.xsl");
072:                    result.execute(mai);
073:                    fail("Should have thrown a TransformerException");
074:                } catch (TransformerException e) {
075:                    // success
076:                }
077:            }
078:
079:            public void testSimpleTransform() throws Exception {
080:                result.setParse(false);
081:                result.setLocation("XSLTResultTest.xsl");
082:                result.execute(mai);
083:
084:                String out = response.getContentAsString();
085:                assertTrue(out
086:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
087:                assertTrue(out
088:                        .indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
089:            }
090:
091:            public void testSimpleTransformParse() throws Exception {
092:                result.setParse(true);
093:                result.setLocation("${top.myLocation}");
094:                result.execute(mai);
095:
096:                String out = response.getContentAsString();
097:                assertTrue(out
098:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
099:                assertTrue(out
100:                        .indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
101:            }
102:
103:            public void testTransform2() throws Exception {
104:                result.setParse(false);
105:                result.setLocation("XSLTResultTest2.xsl");
106:                result.execute(mai);
107:
108:                String out = response.getContentAsString();
109:                assertTrue(out
110:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
111:                assertTrue(out
112:                        .indexOf("<html xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
113:                assertTrue(out.indexOf("Hello Santa Claus how are you?") > -1);
114:            }
115:
116:            public void testTransform3() throws Exception {
117:                result.setParse(false);
118:                result.setLocation("XSLTResultTest3.xsl");
119:                result.execute(mai);
120:
121:                String out = response.getContentAsString();
122:                assertTrue(out
123:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
124:                assertTrue(out
125:                        .indexOf("<html xmlns=\"http://www.w3.org/TR/xhtml1/strict\"") > -1);
126:                assertTrue(out.indexOf("Hello Santa Claus how are you?") > -1);
127:                assertTrue(out
128:                        .indexOf("WebWork in Action by Patrick and Jason") > -1);
129:                assertTrue(out.indexOf("XWork not in Action by Superman") > -1);
130:            }
131:
132:            public void testTransform4WithDocumentInclude() throws Exception {
133:                result = new XSLTResult() {
134:                    protected URIResolver getURIResolver() {
135:                        return new URIResolver() {
136:                            public Source resolve(String href, String base)
137:                                    throws TransformerException {
138:                                return new StreamSource(ClassLoaderUtils
139:                                        .getResourceAsStream(href, this 
140:                                                .getClass()));
141:                            }
142:
143:                        };
144:                    }
145:
146:                };
147:                result.setParse(false);
148:                result.setLocation("XSLTResultTest4.xsl");
149:                result.execute(mai);
150:
151:                String out = response.getContentAsString();
152:                assertTrue(out
153:                        .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
154:                assertTrue(out.indexOf("<validators>") > -1);
155:            }
156:
157:            protected void setUp() throws Exception {
158:                request = new MockHttpServletRequest();
159:                response = new MockHttpServletResponse();
160:                servletContext = new MockServletContext();
161:
162:                result = new XSLTResult();
163:                stack = ValueStackFactory.getFactory().createValueStack();
164:                ActionContext.getContext().setValueStack(stack);
165:
166:                MyAction action = new MyAction();
167:
168:                mai = new com.opensymphony.xwork2.mock.MockActionInvocation();
169:                mai.setAction(action);
170:                mai.setStack(stack);
171:                mai.setInvocationContext(ActionContext.getContext());
172:                stack.push(action);
173:
174:                ActionContext.getContext().put(
175:                        ServletActionContext.HTTP_REQUEST, request);
176:                ActionContext.getContext().put(
177:                        ServletActionContext.HTTP_RESPONSE, response);
178:                ActionContext.getContext().put(
179:                        ServletActionContext.SERVLET_CONTEXT, servletContext);
180:            }
181:
182:            protected void tearDown() {
183:                request = null;
184:                response = null;
185:                servletContext = null;
186:                result = null;
187:                stack = null;
188:                mai = null;
189:            }
190:
191:            private class MyAction implements  Action {
192:
193:                public String execute() throws Exception {
194:                    return SUCCESS;
195:                }
196:
197:                public String getMyLocation() {
198:                    return ("XSLTResultTest.xsl");
199:                }
200:
201:                public String getUsername() {
202:                    return "Santa Claus";
203:                }
204:
205:                public List getBooks() {
206:                    List list = new ArrayList();
207:                    list
208:                            .add(new Book("WebWork in Action",
209:                                    "Patrick and Jason"));
210:                    list.add(new Book("XWork not in Action", "Superman"));
211:                    return list;
212:                }
213:
214:            }
215:
216:            public class Book {
217:
218:                private String title;
219:                private String author;
220:
221:                public Book(String title, String author) {
222:                    this .title = title;
223:                    this .author = author;
224:                }
225:
226:                public String getTitle() {
227:                    return title;
228:                }
229:
230:                public String getAuthor() {
231:                    return author;
232:                }
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.