You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ra...@apache.org on 2006/02/09 17:27:34 UTC
svn commit: r376338 - in
/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml:
SCXMLTestSuite.java TestSCInstance.java TestStatus.java
model/ModelTestSuite.java model/TestHistory.java model/TestState.java
model/TestTransition.java
Author: rahul
Date: Thu Feb 9 08:27:32 2006
New Revision: 376338
URL: http://svn.apache.org/viewcvs?rev=376338&view=rev
Log:
BZ 38459 [scxml] JUnit tests for SCXML
By: Peter Costa <pcosta02 AT yahoo DOT com>
Tests for History, State, Transition and SCInstance classes. Thanks Peter.
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java (with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java (with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java (with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java (with props)
Modified:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java?rev=376338&r1=376337&r2=376338&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java Thu Feb 9 08:27:32 2006
@@ -49,6 +49,7 @@
suite.addTest(SCXMLDigesterTest.suite());
suite.addTest(SCXMLExecutorTest.suite());
suite.addTest(TestBuiltin.suite());
+ suite.addTest(TestSCInstance.suite());
suite.addTest(TestSCXMLHelper.suite());
suite.addTest(TestStatus.suite());
suite.addTest(TriggerEventTest.suite());
Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java?rev=376338&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java Thu Feb 9 08:27:32 2006
@@ -0,0 +1,178 @@
+/*
+ * 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.
+ */
+package org.apache.commons.scxml;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.scxml.env.SimpleContext;
+import org.apache.commons.scxml.env.jexl.JexlEvaluator;
+import org.apache.commons.scxml.model.History;
+import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestSCInstance extends TestCase {
+
+ public TestSCInstance(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestSCInstance.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestSCInstance.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ private SCInstance instance;
+
+ public void setUp() {
+ instance = new SCInstance();
+ }
+
+ public void testGetRootContextNull() {
+ assertNull(instance.getRootContext());
+ }
+
+ public void testGetRootContext() {
+ Context context = new SimpleContext();
+ context.set("name", "value");
+
+ instance.setRootContext(context);
+ assertEquals("value", ((Context)instance.getRootContext()).get("name"));
+ }
+
+ public void testGetRootContextEvaluator() {
+ Evaluator evaluator = new JexlEvaluator();
+
+ instance.setEvaluator(evaluator);
+
+ assertTrue(instance.getRootContext() instanceof JexlContext);
+ }
+
+ public void testGetContext() {
+ TransitionTarget target = new State();
+ target.setId("1");
+
+ Context context = new SimpleContext();
+ context.set("name", "value");
+
+ instance.setContext(target, context);
+
+ assertEquals("value", ((Context)instance.getContext(target)).get("name"));
+ }
+
+ public void testGetContextNullParent() {
+ TransitionTarget target = new State();
+ target.setId("1");
+
+ Context context = new SimpleContext();
+ context.set("name", "value");
+ instance.setRootContext(context);
+
+ Evaluator evaluator = new JexlEvaluator();
+ instance.setEvaluator(evaluator);
+
+ assertEquals("value", ((Context)instance.getContext(target)).get("name"));
+ assertEquals("value", ((Context)instance.lookupContext(target)).get("name"));
+ }
+
+ public void testGetContextParent() {
+ TransitionTarget target = new State();
+ target.setId("1");
+
+ State parent = new State();
+ parent.setId("parent");
+
+ target.setParent(parent);
+
+ Context context = new SimpleContext();
+ context.set("name", "value");
+ instance.setRootContext(context);
+
+ Evaluator evaluator = new JexlEvaluator();
+ instance.setEvaluator(evaluator);
+
+ assertEquals("value", ((Context)instance.getContext(target)).get("name"));
+ assertEquals("value", ((Context)instance.lookupContext(target)).get("name"));
+ }
+
+ public void testGetLastConfigurationNull() {
+ History history = new History();
+
+ Set returnConfiguration = instance.getLastConfiguration(history);
+
+ assertEquals(0, returnConfiguration.size());
+ }
+
+
+ public void testGetLastConfiguration() {
+ History history = new History();
+ history.setId("1");
+
+ Set configuration = new HashSet();
+ configuration.add("value1");
+ configuration.add("value2");
+
+ instance.setLastConfiguration(history, configuration);
+
+ Set returnConfiguration = instance.getLastConfiguration(history);
+
+ assertEquals(2, returnConfiguration.size());
+ assertTrue(returnConfiguration.contains("value1"));
+ assertTrue(returnConfiguration.contains("value2"));
+ }
+
+ public void testIsEmpty() {
+ assertTrue(instance.isEmpty(new History()));
+ }
+
+ public void testIsEmptyFalse() {
+ History history = new History();
+ history.setId("1");
+
+ Set configuration = new HashSet();
+ configuration.add("value1");
+ configuration.add("value2");
+
+ instance.setLastConfiguration(history, configuration);
+
+ assertFalse(instance.isEmpty(history));
+ }
+
+ public void testReset() {
+ History history = new History();
+ history.setId("1");
+
+ Set configuration = new HashSet();
+ configuration.add("value1");
+ configuration.add("value2");
+
+ instance.setLastConfiguration(history, configuration);
+
+ instance.reset(history);
+
+ assertTrue(instance.isEmpty(history));
+ }
+
+}
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCInstance.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java?rev=376338&r1=376337&r2=376338&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java Thu Feb 9 08:27:32 2006
@@ -33,6 +33,11 @@
return suite;
}
+ public static void main(String args[]) {
+ String[] testCaseName = { TestStatus.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
private Status status;
public void setUp() {
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=376338&r1=376337&r2=376338&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 Feb 9 08:27:32 2006
@@ -49,7 +49,10 @@
suite.setName("Commons-SCXML Model Tests");
suite.addTest(ActionsTest.suite());
suite.addTest(TestAction.suite());
+ suite.addTest(TestHistory.suite());
suite.addTest(TestPath.suite());
+ suite.addTest(TestState.suite());
+ suite.addTest(TestTransition.suite());
return suite;
}
}
Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java?rev=376338&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java Thu Feb 9 08:27:32 2006
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.commons.scxml.model;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestHistory extends TestCase {
+
+ public TestHistory(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestHistory.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHistory.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ private History history;
+
+ public void setUp() {
+ history = new History();
+ }
+
+ public void testSetTypeDeep() {
+ history.setType("deep");
+
+ assertTrue(history.isDeep());
+ }
+
+ public void testSetTypeNotDeep() {
+ history.setType("shallow");
+
+ assertFalse(history.isDeep());
+ }
+}
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestHistory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java?rev=376338&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java Thu Feb 9 08:27:32 2006
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ */
+package org.apache.commons.scxml.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestState extends TestCase {
+
+ public TestState(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestState.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestState.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ private State state;
+
+ public void setUp() {
+ state = new State();
+ }
+
+ public void testGetTransitionsListNull() {
+ assertNull(state.getTransitionsList("event"));
+ }
+
+ public void testGetTransitionsList() {
+ List values = new ArrayList();
+
+ state.getTransitions().put("event", values);
+
+ assertNotNull(state.getTransitionsList("event"));
+ }
+
+ public void testAddTransitionDoesNotContainKey() {
+ Transition transition = new Transition();
+ transition.setEvent("event");
+
+ state.addTransition(transition);
+
+ List events = (List)state.getTransitions().get("event");
+
+ assertEquals(1, events.size());
+ assertEquals("event", ((Transition)events.get(0)).getEvent());
+ }
+
+ public void testAddTransitionContainKey() {
+ Transition transition1 = new Transition();
+ transition1.setEvent("event");
+
+ Transition transition2 = new Transition();
+ transition2.setEvent("event");
+
+ state.addTransition(transition1);
+ state.addTransition(transition2);
+
+ List events = (List)state.getTransitions().get("event");
+
+ assertEquals(2, events.size());
+ }
+
+ public void testGetTransitionList() {
+ Transition transition1 = new Transition();
+ transition1.setEvent("event");
+
+ Transition transition2 = new Transition();
+ transition2.setEvent("event");
+
+ state.addTransition(transition1);
+ state.addTransition(transition2);
+
+ List events = state.getTransitionsList();
+
+ assertEquals(2, events.size());
+ }
+
+ public void testHasHistoryEmpty() {
+ assertFalse(state.hasHistory());
+ }
+
+ public void testHasHistory() {
+ History history = new History();
+
+ state.addHistory(history);
+
+ assertTrue(state.hasHistory());
+ }
+
+ public void testIsSimple() {
+ assertTrue(state.isSimple());
+ }
+
+ public void testIsSimpleParallel() {
+ Parallel parallel = new Parallel();
+
+ state.setParallel(parallel);
+
+ assertFalse(state.isSimple());
+ }
+
+ public void testIsSimpleHasChildren() {
+ State state1 = new State();
+
+ state.addChild(state);
+
+ assertFalse(state.isSimple());
+ }
+
+ public void testIsCompositeFalse() {
+ assertFalse(state.isComposite());
+ }
+
+ public void testIsCompositeParallel() {
+ Parallel parallel = new Parallel();
+
+ state.setParallel(parallel);
+
+ assertTrue(state.isComposite());
+ }
+
+ public void testIsCompositeHasChildren() {
+ State state1 = new State();
+
+ state.addChild(state);
+
+ assertTrue(state.isComposite());
+ }
+
+ public void testIsRegion() {
+ state.setParent(new Parallel());
+
+ assertTrue(state.isRegion());
+ }
+
+ public void testIsRegionNotParallel() {
+ state.setParent(new State());
+
+ assertFalse(state.isRegion());
+ }
+
+ public void testIsOrthogonal() {
+ Parallel parallel = new Parallel();
+
+ state.setParallel(parallel);
+
+ assertTrue(state.isOrthogonal());
+ }
+
+ public void testIsOrthogonalFalse() {
+ assertFalse(state.isOrthogonal());
+ }
+
+}
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestState.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java?rev=376338&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java Thu Feb 9 08:27:32 2006
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+package org.apache.commons.scxml.model;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestTransition extends TestCase {
+
+ public TestTransition(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestTransition.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestTransition.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ private Transition transition;
+
+ public void setUp() {
+ transition = new Transition();
+ }
+
+ public void testGetRuntimeTargetNullNoParent() {
+ transition.setTarget(null);
+
+ assertNull(transition.getRuntimeTarget());
+ }
+
+ public void testGetRuntimeTargetNullWithParent() {
+ State state = new State();
+ state.setId("1");
+
+ transition.setTarget(null);
+ transition.setParent(state);
+
+ assertEquals("1", transition.getRuntimeTarget().getId());
+ }
+
+ public void testGetRuntimeTarget() {
+ State state = new State();
+ state.setId("2");
+
+ transition.setTarget(state);
+
+ assertEquals("2", transition.getRuntimeTarget().getId());
+ }
+
+ public void testGetPath() {
+ assertNotNull(transition.getPath());
+ }
+}
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestTransition.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org