Source Code Cross Referenced for LookupCommandTestCase.java in  » Library » Apache-commons-chain-1.1-src » org » apache » commons » chain » generic » 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 » Library » Apache commons chain 1.1 src » org.apache.commons.chain.generic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.chain.generic;
017:
018:        import junit.framework.Test;
019:        import junit.framework.TestCase;
020:        import junit.framework.TestSuite;
021:        import org.apache.commons.chain.Context;
022:        import org.apache.commons.chain.Catalog;
023:        import org.apache.commons.chain.impl.CatalogBase;
024:        import org.apache.commons.chain.impl.ContextBase;
025:        import org.apache.commons.chain.impl.ChainBase;
026:        import org.apache.commons.chain.impl.CatalogFactoryBase;
027:        import org.apache.commons.chain.impl.DelegatingCommand;
028:        import org.apache.commons.chain.impl.NonDelegatingCommand;
029:
030:        /**
031:         * <p>Test case for the <code>LookupCommand</code> class.</p>
032:         *
033:         * @author Sean Schofield
034:         * @version $Revision: 155403 $
035:         */
036:
037:        public class LookupCommandTestCase extends TestCase {
038:
039:            // ---------------------------------------------------- Instance Variables
040:
041:            /**
042:             * The instance of {@link Catalog} to use when looking up commands
043:             */
044:            protected Catalog catalog;
045:
046:            /**
047:             * The {@link LookupCommand} instance under test.
048:             */
049:            protected LookupCommand command;
050:
051:            /**
052:             * The {@link Context} instance on which to execute the chain.
053:             */
054:            protected Context context = null;
055:
056:            // ---------------------------------------------------------- Constructors
057:
058:            /**
059:             * Construct a new instance of this test case.
060:             *
061:             * @param name Name of the test case
062:             */
063:            public LookupCommandTestCase(String name) {
064:                super (name);
065:            }
066:
067:            // -------------------------------------------------- Overall Test Methods
068:
069:            /**
070:             * Set up instance variables required by this test case.
071:             */
072:            public void setUp() {
073:                catalog = new CatalogBase();
074:                CatalogFactoryBase.getInstance().setCatalog(catalog);
075:                command = new LookupCommand();
076:                context = new ContextBase();
077:            }
078:
079:            /**
080:             * Return the tests included in this test suite.
081:             */
082:            public static Test suite() {
083:                return (new TestSuite(LookupCommandTestCase.class));
084:            }
085:
086:            /**
087:             * Tear down instance variables required by this test case.
088:             */
089:            public void tearDown() {
090:                catalog = null;
091:                CatalogFactoryBase.getInstance().clear();
092:                command = null;
093:                context = null;
094:            }
095:
096:            // ------------------------------------------------ Individual Test Methods
097:
098:            // Test ability to lookup and execute single non-delegating command
099:            public void testExecuteMethodLookup_1a() {
100:
101:                // use default catalog
102:                catalog.addCommand("foo", new NonDelegatingCommand("1a"));
103:                command.setName("foo");
104:
105:                try {
106:                    assertTrue("Command should return true", command
107:                            .execute(context));
108:                } catch (Exception e) {
109:                    fail("Threw exception: " + e);
110:                }
111:                checkExecuteLog("1a");
112:            }
113:
114:            // Test ability to lookup and execute a chain
115:            public void testExecuteMethodLookup_1b() {
116:
117:                ChainBase chain = new ChainBase();
118:                chain.addCommand(new DelegatingCommand("1b1"));
119:                chain.addCommand(new DelegatingCommand("1b2"));
120:                chain.addCommand(new NonDelegatingCommand("1b3"));
121:
122:                // use default catalog
123:                catalog.addCommand("foo", chain);
124:                command.setName("foo");
125:
126:                try {
127:                    assertTrue("Command should return true", command
128:                            .execute(context));
129:                } catch (Exception e) {
130:                    fail("Threw exception: " + e);
131:                }
132:                checkExecuteLog("1b1/1b2/1b3");
133:            }
134:
135:            // Test ability to lookup and execute single non-delegating command
136:            // using the context
137:            public void testExecuteMethodLookup_2a() {
138:
139:                // use default catalog
140:                catalog.addCommand("foo", new NonDelegatingCommand("2a"));
141:                command.setNameKey("nameKey");
142:                context.put("nameKey", "foo");
143:
144:                try {
145:                    assertTrue("Command should return true", command
146:                            .execute(context));
147:                } catch (Exception e) {
148:                    fail("Threw exception: " + e);
149:                }
150:                checkExecuteLog("2a");
151:            }
152:
153:            // Test ability to lookup and execute a chain using the context 
154:            public void testExecuteMethodLookup_2b() {
155:
156:                ChainBase chain = new ChainBase();
157:                chain.addCommand(new DelegatingCommand("2b1"));
158:                chain.addCommand(new DelegatingCommand("2b2"));
159:                chain.addCommand(new NonDelegatingCommand("2b3"));
160:
161:                // use default catalog
162:                catalog.addCommand("foo", chain);
163:                command.setNameKey("nameKey");
164:                context.put("nameKey", "foo");
165:
166:                try {
167:                    assertTrue("Command should return true", command
168:                            .execute(context));
169:                } catch (Exception e) {
170:                    fail("Threw exception: " + e);
171:                }
172:                checkExecuteLog("2b1/2b2/2b3");
173:            }
174:
175:            // Test ability to lookup and execute single non-delegating command, ignoring its result
176:            public void testExecuteMethodLookup_3a() {
177:
178:                // use default catalog
179:                catalog.addCommand("foo", new NonDelegatingCommand("3a"));
180:                command.setIgnoreExecuteResult(true);
181:                command.setName("foo");
182:
183:                try {
184:                    assertFalse("Command should return false", command
185:                            .execute(context));
186:                } catch (Exception e) {
187:                    fail("Threw exception: " + e);
188:                }
189:                checkExecuteLog("3a");
190:            }
191:
192:            // -------------------------------------------------------- Support Methods
193:
194:            // Verify the contents of the execution log
195:            protected void checkExecuteLog(String expected) {
196:                StringBuffer log = (StringBuffer) context.get("log");
197:                assertNotNull("Context failed to return log", log);
198:                assertEquals("Context returned correct log", expected, log
199:                        .toString());
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.