Author: rahul
Date: Thu Mar 23 11:28:23 2006
New Revision: 388240
URL: http://svn.apache.org/viewcvs?rev=388240&view=rev
Log:
Add test cases to illustrate a stateless "model" package i.e. parse document
once, execute n times (simultaneously and/or sequentially).
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml
(with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml
(with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
(with props)
Modified:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml?rev=388240&view=auto
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml
(added)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml
Thu Mar 23 11:28:23 2006
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/SCXML"
+ version="1.0"
+ initialstate="main">
+
+ <state id="main">
+
+ <initial>
+ <transition target="ten"/>
+ </initial>
+
+ <onentry>
+ <var name="instancevar" expr="20" />
+ </onentry>
+
+ <state id="ten">
+ <transition event="ten.done" cond="instancevar eq 20"
+ target="twenty" />
+ <onexit>
+ <assign name="instancevar" expr="30" />
+ </onexit>
+ </state>
+
+ <state id="twenty">
+ <transition event="twenty.done" cond="instancevar eq 30"
+ target="thirty" />
+ </state>
+
+ <state id="thirty" final="true" />
+
+ </state>
+
+</scxml>
+
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/stateless-01.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml?rev=388240&view=auto
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml
(added)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml
Thu Mar 23 11:28:23 2006
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/SCXML"
+ version="1.0"
+ initialstate="main">
+
+ <state id="main">
+
+ <initial>
+ <transition target="ten"/>
+ </initial>
+
+ <onentry>
+ <var name="instancevar" expr="${20}" />
+ </onentry>
+
+ <state id="ten">
+ <transition event="ten.done" cond="${instancevar eq 20}"
+ target="twenty" />
+ <onexit>
+ <assign name="instancevar" expr="${30}" />
+ </onexit>
+ </state>
+
+ <state id="twenty">
+ <transition event="twenty.done" cond="${instancevar eq 30}"
+ target="thirty" />
+ </state>
+
+ <state id="thirty" final="true" />
+
+ </state>
+
+</scxml>
+
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/stateless-01.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java?rev=388240&r1=388239&r2=388240&view=diff
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
(original)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
Thu Mar 23 11:28:23 2006
@@ -53,6 +53,7 @@
suite.addTest(HistoryTest.suite());
suite.addTest(PathTest.suite());
suite.addTest(StateTest.suite());
+ suite.addTest(StatelessModelTest.suite());
suite.addTest(TransitionTest.suite());
return suite;
}
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java?rev=388240&view=auto
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
(added)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
Thu Mar 23 11:28:23 2006
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.scxml.model;
+
+import java.net.URL;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.apache.commons.scxml.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.TriggerEvent;
+import org.apache.commons.scxml.env.jsp.ELContext;
+import org.apache.commons.scxml.env.jsp.ELEvaluator;
+/**
+ * Unit tests [EMAIL PROTECTED] org.apache.commons.scxml.SCXMLExecutor}.
+ */
+public class StatelessModelTest extends TestCase {
+ /**
+ * Construct a new instance of SCXMLExecutorTest with
+ * the specified name
+ */
+ public StatelessModelTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(StatelessModelTest.class);
+ suite.setName("SCXML Executor Tests");
+ return suite;
+ }
+
+ // Test data
+ private URL stateless01jexl, stateless01jsp;
+ private SCXML scxml01jexl, scxml01jsp;
+ private SCXMLExecutor exec01, exec02;
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ stateless01jexl = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/env/jexl/stateless-01.xml");
+ stateless01jsp = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/env/jsp/stateless-01.xml");
+ scxml01jexl = SCXMLTestHelper.digest(stateless01jexl);
+ scxml01jsp = SCXMLTestHelper.digest(stateless01jsp);
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ stateless01jexl = null;
+ }
+
+ /**
+ * Test the stateless model, simultaneous executions, JEXL expressions
+ */
+ public void testStatelessModelSimultaneousJexl() {
+ // parse once, use many times
+ exec01 = SCXMLTestHelper.getExecutor(scxml01jexl);
+ assertNotNull(exec01);
+ exec02 = SCXMLTestHelper.getExecutor(scxml01jexl);
+ assertNotNull(exec02);
+ assertFalse(exec01 == exec02);
+ runSimultaneousTest();
+ }
+
+ /**
+ * Test the stateless model, sequential executions, JEXL expressions
+ */
+ public void testStatelessModelSequentialJexl() {
+ // rinse and repeat
+ for (int i = 0; i < 3; i++) {
+ exec01 = SCXMLTestHelper.getExecutor(scxml01jexl);
+ assertNotNull(exec01);
+ runSequentialTest();
+ }
+ }
+
+ /**
+ * Test the stateless model, simultaneous executions, EL expressions
+ */
+ public void testStatelessModelSimultaneousEl() {
+ // parse once, use many times
+ exec01 = SCXMLTestHelper.getExecutor(scxml01jsp,
+ new ELContext(), new ELEvaluator());
+ assertNotNull(exec01);
+ exec02 = SCXMLTestHelper.getExecutor(scxml01jsp,
+ new ELContext(), new ELEvaluator());
+ assertNotNull(exec02);
+ assertFalse(exec01 == exec02);
+ runSimultaneousTest();
+ }
+
+ /**
+ * Test the stateless model, sequential executions, EL expressions
+ */
+ public void testStatelessModelSequentialEl() {
+ // rinse and repeat
+ for (int i = 0; i < 3; i++) {
+ exec01 = SCXMLTestHelper.getExecutor(scxml01jsp,
+ new ELContext(), new ELEvaluator());
+ assertNotNull(exec01);
+ runSequentialTest();
+ }
+ }
+
+ private void runSimultaneousTest() {
+ try {
+ //// Interleaved
+ // exec01
+ Set currentStates = exec01.getCurrentStatus().getStates();
+ assertEquals(1, currentStates.size());
+ assertEquals("ten", ((State)currentStates.iterator().
+ next()).getId());
+ currentStates = fireEvent("ten.done", exec01);
+ assertEquals(1, currentStates.size());
+ assertEquals("twenty", ((State)currentStates.iterator().
+ next()).getId());
+ // exec02
+ currentStates = exec02.getCurrentStatus().getStates();
+ assertEquals(1, currentStates.size());
+ assertEquals("ten", ((State)currentStates.iterator().
+ next()).getId());
+ // exec01
+ currentStates = fireEvent("twenty.done", exec01);
+ assertEquals(1, currentStates.size());
+ assertEquals("thirty", ((State)currentStates.iterator().
+ next()).getId());
+ // exec02
+ currentStates = fireEvent("ten.done", exec02);
+ assertEquals(1, currentStates.size());
+ assertEquals("twenty", ((State)currentStates.iterator().
+ next()).getId());
+ currentStates = fireEvent("twenty.done", exec02);
+ assertEquals(1, currentStates.size());
+ assertEquals("thirty", ((State)currentStates.iterator().
+ next()).getId());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ private void runSequentialTest() {
+ try {
+ Set currentStates = exec01.getCurrentStatus().getStates();
+ assertEquals(1, currentStates.size());
+ assertEquals("ten", ((State)currentStates.iterator().
+ next()).getId());
+ currentStates = fireEvent("ten.done", exec01);
+ assertEquals(1, currentStates.size());
+ assertEquals("twenty", ((State)currentStates.iterator().
+ next()).getId());
+ currentStates = fireEvent("twenty.done", exec01);
+ assertEquals(1, currentStates.size());
+ assertEquals("thirty", ((State)currentStates.iterator().
+ next()).getId());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ private Set fireEvent(String name, SCXMLExecutor exec) {
+ TriggerEvent[] evts = {new TriggerEvent(name,
+ TriggerEvent.SIGNAL_EVENT, null)};
+ try {
+ exec.triggerEvents(evts);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ return exec.getCurrentStatus().getStates();
+ }
+
+ public static void main(String args[]) {
+ TestRunner.run(suite());
+ }
+}
+
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]