Source Code Cross Referenced for StatelessModelTest.java in  » Library » Apache-commons-scxml-0.6-src » org » apache » commons » scxml » model » 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 scxml 0.6 src » org.apache.commons.scxml.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.scxml.model;
018:
019:        import java.net.URL;
020:        import java.util.Set;
021:
022:        import junit.framework.Test;
023:        import junit.framework.TestCase;
024:        import junit.framework.TestSuite;
025:        import junit.textui.TestRunner;
026:
027:        import org.apache.commons.scxml.SCXMLExecutor;
028:        import org.apache.commons.scxml.SCXMLTestHelper;
029:        import org.apache.commons.scxml.TriggerEvent;
030:        import org.apache.commons.scxml.env.jsp.ELContext;
031:        import org.apache.commons.scxml.env.jsp.ELEvaluator;
032:
033:        /**
034:         * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
035:         */
036:        public class StatelessModelTest extends TestCase {
037:            /**
038:             * Construct a new instance of SCXMLExecutorTest with
039:             * the specified name
040:             */
041:            public StatelessModelTest(String name) {
042:                super (name);
043:            }
044:
045:            public static Test suite() {
046:                TestSuite suite = new TestSuite(StatelessModelTest.class);
047:                suite.setName("SCXML Executor Tests");
048:                return suite;
049:            }
050:
051:            // Test data
052:            private URL stateless01jexl, stateless01jsp;
053:            private SCXML scxml01jexl, scxml01jsp;
054:            private SCXMLExecutor exec01, exec02;
055:
056:            /**
057:             * Set up instance variables required by this test case.
058:             */
059:            public void setUp() {
060:                stateless01jexl = this .getClass().getClassLoader().getResource(
061:                        "org/apache/commons/scxml/env/jexl/stateless-01.xml");
062:                stateless01jsp = this .getClass().getClassLoader().getResource(
063:                        "org/apache/commons/scxml/env/jsp/stateless-01.xml");
064:                scxml01jexl = SCXMLTestHelper.digest(stateless01jexl);
065:                scxml01jsp = SCXMLTestHelper.digest(stateless01jsp);
066:            }
067:
068:            /**
069:             * Tear down instance variables required by this test case.
070:             */
071:            public void tearDown() {
072:                stateless01jexl = null;
073:            }
074:
075:            /**
076:             * Test the stateless model, simultaneous executions, JEXL expressions
077:             */
078:            public void testStatelessModelSimultaneousJexl() {
079:                // parse once, use many times
080:                exec01 = SCXMLTestHelper.getExecutor(scxml01jexl);
081:                assertNotNull(exec01);
082:                exec02 = SCXMLTestHelper.getExecutor(scxml01jexl);
083:                assertNotNull(exec02);
084:                assertFalse(exec01 == exec02);
085:                runSimultaneousTest();
086:            }
087:
088:            /**
089:             * Test the stateless model, sequential executions, JEXL expressions
090:             */
091:            public void testStatelessModelSequentialJexl() {
092:                // rinse and repeat
093:                for (int i = 0; i < 3; i++) {
094:                    exec01 = SCXMLTestHelper.getExecutor(scxml01jexl);
095:                    assertNotNull(exec01);
096:                    runSequentialTest();
097:                }
098:            }
099:
100:            /**
101:             * Test the stateless model, simultaneous executions, EL expressions
102:             */
103:            public void testStatelessModelSimultaneousEl() {
104:                // parse once, use many times
105:                exec01 = SCXMLTestHelper.getExecutor(scxml01jsp,
106:                        new ELContext(), new ELEvaluator());
107:                assertNotNull(exec01);
108:                exec02 = SCXMLTestHelper.getExecutor(scxml01jsp,
109:                        new ELContext(), new ELEvaluator());
110:                assertNotNull(exec02);
111:                assertFalse(exec01 == exec02);
112:                runSimultaneousTest();
113:            }
114:
115:            /**
116:             * Test the stateless model, sequential executions, EL expressions
117:             */
118:            public void testStatelessModelSequentialEl() {
119:                // rinse and repeat
120:                for (int i = 0; i < 3; i++) {
121:                    exec01 = SCXMLTestHelper.getExecutor(scxml01jsp,
122:                            new ELContext(), new ELEvaluator());
123:                    assertNotNull(exec01);
124:                    runSequentialTest();
125:                }
126:            }
127:
128:            private void runSimultaneousTest() {
129:                try {
130:                    //// Interleaved
131:                    // exec01
132:                    Set currentStates = exec01.getCurrentStatus().getStates();
133:                    assertEquals(1, currentStates.size());
134:                    assertEquals("ten", ((State) currentStates.iterator()
135:                            .next()).getId());
136:                    currentStates = fireEvent("ten.done", exec01);
137:                    assertEquals(1, currentStates.size());
138:                    assertEquals("twenty", ((State) currentStates.iterator()
139:                            .next()).getId());
140:                    // exec02
141:                    currentStates = exec02.getCurrentStatus().getStates();
142:                    assertEquals(1, currentStates.size());
143:                    assertEquals("ten", ((State) currentStates.iterator()
144:                            .next()).getId());
145:                    // exec01
146:                    currentStates = fireEvent("twenty.done", exec01);
147:                    assertEquals(1, currentStates.size());
148:                    assertEquals("thirty", ((State) currentStates.iterator()
149:                            .next()).getId());
150:                    // exec02
151:                    currentStates = fireEvent("ten.done", exec02);
152:                    assertEquals(1, currentStates.size());
153:                    assertEquals("twenty", ((State) currentStates.iterator()
154:                            .next()).getId());
155:                    currentStates = fireEvent("twenty.done", exec02);
156:                    assertEquals(1, currentStates.size());
157:                    assertEquals("thirty", ((State) currentStates.iterator()
158:                            .next()).getId());
159:                } catch (Exception e) {
160:                    fail(e.getMessage());
161:                }
162:            }
163:
164:            private void runSequentialTest() {
165:                try {
166:                    Set currentStates = exec01.getCurrentStatus().getStates();
167:                    assertEquals(1, currentStates.size());
168:                    assertEquals("ten", ((State) currentStates.iterator()
169:                            .next()).getId());
170:                    currentStates = fireEvent("ten.done", exec01);
171:                    assertEquals(1, currentStates.size());
172:                    assertEquals("twenty", ((State) currentStates.iterator()
173:                            .next()).getId());
174:                    currentStates = fireEvent("twenty.done", exec01);
175:                    assertEquals(1, currentStates.size());
176:                    assertEquals("thirty", ((State) currentStates.iterator()
177:                            .next()).getId());
178:                } catch (Exception e) {
179:                    fail(e.getMessage());
180:                }
181:            }
182:
183:            private Set fireEvent(String name, SCXMLExecutor exec) {
184:                TriggerEvent[] evts = { new TriggerEvent(name,
185:                        TriggerEvent.SIGNAL_EVENT, null) };
186:                try {
187:                    exec.triggerEvents(evts);
188:                } catch (Exception e) {
189:                    fail(e.getMessage());
190:                }
191:                return exec.getCurrentStatus().getStates();
192:            }
193:
194:            public static void main(String args[]) {
195:                TestRunner.run(suite());
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.