Source Code Cross Referenced for TemplateTest.java in  » Content-Management-System » TransferCM » com » methodhead » shim » 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 » Content Management System » TransferCM » com.methodhead.shim 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (C) 2006 Methodhead Software LLC.  All rights reserved.
003:         * 
004:         * This file is part of TransferCM.
005:         * 
006:         * TransferCM is free software; you can redistribute it and/or modify it under the
007:         * terms of the GNU General Public License as published by the Free Software
008:         * Foundation; either version 2 of the License, or (at your option) any later
009:         * version.
010:         * 
011:         * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013:         * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
014:         * details.
015:         * 
016:         * You should have received a copy of the GNU General Public License along with
017:         * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018:         * Fifth Floor, Boston, MA  02110-1301  USA
019:         */
020:
021:        package com.methodhead.shim;
022:
023:        import java.io.*;
024:        import java.util.*;
025:        import java.sql.*;
026:        import junit.framework.*;
027:        import org.apache.log4j.*;
028:        import com.methodhead.persistable.*;
029:        import com.methodhead.test.*;
030:        import com.methodhead.sitecontext.*;
031:        import com.methodhead.*;
032:        import com.methodhead.util.*;
033:        import org.apache.cactus.*;
034:
035:        public class TemplateTest extends ServletTestCase {
036:
037:            static {
038:                TestUtils.initLogger();
039:                TestUtils.initDb();
040:            }
041:
042:            public TemplateTest(String name) {
043:                super (name);
044:            }
045:
046:            File templateBase_ = null;
047:            File template_ = null;
048:            SiteContext siteContext1_ = null;
049:            SiteContext siteContext2_ = null;
050:
051:            protected void setUp() {
052:                //setLogLevel( Level.DEBUG );
053:                try {
054:                    ConnectionSingleton.runBatchUpdate(new FileReader(
055:                            "webapp/WEB-INF/db/transfer-reset.sql"));
056:
057:                    siteContext1_ = new SiteContext();
058:                    siteContext1_.setString("path", "foo");
059:                    siteContext1_.saveNew();
060:
061:                    siteContext2_ = new SiteContext();
062:                    siteContext2_.setString("path", "foo");
063:                    siteContext2_.saveNew();
064:                } catch (Exception e) {
065:                    fail(e.getMessage());
066:                }
067:            }
068:
069:            protected void tearDown() {
070:            }
071:
072:            public void testGetSiteContext() {
073:                try {
074:                    Template template = null;
075:                    SiteContext siteContext = null;
076:
077:                    template = new Template();
078:                    siteContext = SiteContext.getDefaultContext();
079:
080:                    //
081:                    // get site context
082:                    //
083:                    try {
084:                        template.getSiteContext();
085:                        fail("Template.getSiteContext() did not throw an exception.");
086:                    } catch (ShimException e) {
087:                        // success
088:                    }
089:
090:                    template.setSiteContext(siteContext);
091:
092:                    assertNotNull(template.getSiteContext());
093:                    assertEquals(siteContext, template.getSiteContext());
094:                } catch (Exception e) {
095:                    e.printStackTrace();
096:                    fail();
097:                }
098:            }
099:
100:            public void testGetTemplateList() throws Exception {
101:                Template t = null;
102:                List l = null;
103:
104:                //
105:                // get the list for the default context
106:                //
107:                t = new Template();
108:                t.setSiteContext(SiteContext.getDefaultContext());
109:                l = t.getTemplateList(request);
110:
111:                assertNotNull(l);
112:                assertEquals(4, l.size());
113:                assertEquals("template.jsp", l.get(0));
114:                assertEquals("Template2.jsp", l.get(1));
115:                assertEquals("template3.jsp", l.get(2));
116:                assertEquals("template4.jsp", l.get(3));
117:
118:                //
119:                // get the list for a specific context (should be id=1)
120:                //
121:                t = new Template();
122:                t.setSiteContext(siteContext1_);
123:                l = t.getTemplateList(request);
124:
125:                assertNotNull(l);
126:                assertEquals(2, l.size());
127:                assertEquals("template.jsp", l.get(0));
128:
129:                //
130:                // get the list for a specific context with no templates (should be id=2)
131:                //
132:                t = new Template();
133:                t.setSiteContext(siteContext2_);
134:                l = t.getTemplateList(request);
135:
136:                assertNotNull(l);
137:                assertEquals(0, l.size());
138:            }
139:
140:            public void testLoad() {
141:                try {
142:                    Template t = null;
143:                    PanelConfig panelConfig = null;
144:                    Map map = null;
145:
146:                    TestData.createWebappFiles(ServletUtils.getRealFile(
147:                            request, ""));
148:
149:                    //
150:                    // try to load with an invalid template
151:                    //
152:                    try {
153:                        t = new Template();
154:                        t.setSiteContext(SiteContext.getDefaultContext());
155:                        t.load(request, null);
156:                        fail("load() did not throw an exception.");
157:                    } catch (ShimException e) {
158:                        // success
159:                    }
160:
161:                    //
162:                    // try to load with an invalid template
163:                    //
164:                    try {
165:                        t = new Template();
166:                        t.setSiteContext(SiteContext.getDefaultContext());
167:                        t.load(request, "");
168:                        fail("load() did not throw an exception.");
169:                    } catch (ShimException e) {
170:                        // success
171:                    }
172:
173:                    //
174:                    // load for the default context
175:                    //
176:                    t = new Template();
177:                    t.setSiteContext(SiteContext.getDefaultContext());
178:                    t.load(request, "template.jsp");
179:
180:                    assertEquals("template.jsp", t.getFileName());
181:                    assertNull(request.getAttribute(ShimGlobals.PANELMAP_KEY));
182:
183:                    map = t.getPanelConfigs();
184:
185:                    assertNotNull(map);
186:                    assertEquals(1, map.keySet().size());
187:
188:                    panelConfig = (PanelConfig) map.get("body");
189:
190:                    assertNotNull(panelConfig);
191:                    assertEquals(ShimGlobals.DEFAULT_MODULE, panelConfig
192:                            .getDefaultModule());
193:
194:                    //
195:                    // load for a particular context
196:                    //
197:                    t = new Template();
198:                    t.setSiteContext(siteContext1_);
199:                    t.load(request, "template.jsp");
200:
201:                    assertEquals("template.jsp", t.getFileName());
202:                    assertNull(request.getAttribute(ShimGlobals.PANELMAP_KEY));
203:
204:                    map = t.getPanelConfigs();
205:
206:                    assertNotNull(map);
207:                    assertEquals(2, map.keySet().size());
208:
209:                    panelConfig = (PanelConfig) map.get("body");
210:
211:                    assertNotNull(panelConfig);
212:                    assertEquals(ShimGlobals.DEFAULT_MODULE, panelConfig
213:                            .getDefaultModule());
214:
215:                    panelConfig = (PanelConfig) map.get("footer");
216:
217:                    assertNotNull(panelConfig);
218:                    assertEquals("some.Module", panelConfig.getDefaultModule());
219:                } catch (Exception e) {
220:                    e.printStackTrace();
221:                    fail();
222:                }
223:            }
224:
225:            public void testInclude() {
226:                try {
227:                    Template template = null;
228:                    SiteContext siteContext = null;
229:
230:                    //
231:                    // include a template from the default site context
232:                    //
233:                    template = new Template();
234:                    template.setSiteContext(SiteContext.getDefaultContext());
235:                    template.include(request, response, "template3.jsp");
236:
237:                    //
238:                    // include a template from a specific site context
239:                    //
240:                    siteContext = new SiteContext();
241:                    siteContext.setInt("id", 1);
242:                    template.setSiteContext(siteContext);
243:                    template.include(request, response, "template2.jsp");
244:                } catch (Exception e) {
245:                    e.printStackTrace();
246:                    fail();
247:                }
248:            }
249:
250:            public void endInclude(WebResponse response) {
251:                assertEquals("This is a template.\nThis is also a template.\n",
252:                        response.getText());
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.