Author: rahul
Date: Fri Feb 3 20:54:44 2006
New Revision: 374829
URL: http://svn.apache.org/viewcvs?rev=374829&view=rev
Log:
BZ 38459 [scxml] JUnit tests for SCXML
More tests from Peter Costa <pcosta02 AT yahoo DOT com>
Many thanks Peter.
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java
(with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
(with props)
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java
(with props)
Modified:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/EnvTestSuite.java
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.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/env/EnvTestSuite.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/EnvTestSuite.java?rev=374829&r1=374828&r2=374829&view=diff
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/EnvTestSuite.java
(original)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/EnvTestSuite.java
Fri Feb 3 20:54:44 2006
@@ -47,6 +47,7 @@
public static Test suite() {
TestSuite suite = new TestSuite();
suite.setName("Commons-SCXML Environments Tests");
+ suite.addTest(TestLogUtils.suite());
suite.addTest(TestSimpleContext.suite());
return suite;
}
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java?rev=374829&view=auto
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java
(added)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java
Fri Feb 3 20:54:44 2006
@@ -0,0 +1,79 @@
+/*
+ * 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.env;
+
+import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.Transition;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestLogUtils extends TestCase {
+
+ public TestLogUtils(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestLogUtils.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = {TestLogUtils.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public void testGetTTPathParentNull() {
+ TransitionTarget target = new State();
+ target.setId("ID");
+
+ assertEquals("/ID", LogUtils.getTTPath(target));
+ }
+
+ public void testGetTTPathParent() {
+ TransitionTarget target = new State();
+ target.setId("ID");
+
+ TransitionTarget parent1 = new State();
+ parent1.setId("parent1");
+
+ TransitionTarget parent2 = new State();
+ parent2.setId("parent2");
+
+ parent1.setParent(parent2);
+ target.setParent(parent1);
+
+ assertEquals("/parent2/parent1/ID", LogUtils.getTTPath(target));
+ }
+
+ public void testTransToString() {
+ TransitionTarget targetTo = new State();
+ targetTo.setId("TO");
+
+ TransitionTarget targetFrom = new State();
+ targetFrom.setId("FROM");
+
+ Transition transition = new Transition();
+ transition.setCond("condition");
+ transition.setEvent("event happened");
+
+ assertEquals( "transition (event = event happened, cond = condition,
from = /FROM, to = /TO)",
+ LogUtils.transToString(targetFrom,
targetTo, transition));
+ }
+
+}
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestLogUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java?rev=374829&r1=374828&r2=374829&view=diff
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java
(original)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java
Fri Feb 3 20:54:44 2006
@@ -47,6 +47,7 @@
public static Test suite() {
TestSuite suite = new TestSuite();
suite.setName("Commons-SCXML IO Tests");
+ suite.addTest(TestSCXMLSerializer.suite());
return suite;
}
}
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java?rev=374829&view=auto
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
(added)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
Fri Feb 3 20:54:44 2006
@@ -0,0 +1,291 @@
+/*
+ * 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.io;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.scxml.model.Assign;
+import org.apache.commons.scxml.model.Cancel;
+import org.apache.commons.scxml.model.Else;
+import org.apache.commons.scxml.model.ElseIf;
+import org.apache.commons.scxml.model.Exit;
+import org.apache.commons.scxml.model.History;
+import org.apache.commons.scxml.model.If;
+import org.apache.commons.scxml.model.Log;
+import org.apache.commons.scxml.model.OnEntry;
+import org.apache.commons.scxml.model.OnExit;
+import org.apache.commons.scxml.model.SCXML;
+import org.apache.commons.scxml.model.Send;
+import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.TransitionTarget;
+import org.apache.commons.scxml.model.Var;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestSCXMLSerializer extends TestCase {
+
+ public TestSCXMLSerializer(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestSCXMLSerializer.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestSCXMLSerializer.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public void testSerializeSCXMLNoStates() {
+ SCXML scxml = new SCXML();
+ scxml.setXmlns("namespace");
+ scxml.setVersion("version1");
+ scxml.setInitialstate("off");
+ scxml.addState(new State());
+
+ String assertValue = "<scxml xmlns=\"namespace\" version=\"version1\"
initialstate=\"off\">\n <state>\n </state>\n</scxml>\n";
+
+ assertEquals(assertValue, SCXMLSerializer.serialize(scxml));
+ }
+
+ public void testSerializeSend() {
+ Send send = new Send();
+ send.setSendid("1");
+ send.setTarget("newTarget");
+ send.setTargettype("newTargetType");
+ send.setNamelist("names");
+ send.setDelay("4 secs");
+ send.setEvent("turnoff");
+ send.setHints("guess");
+
+ String assertValue = " <send sendid=\"1\" " +
+ "target=\"newTarget\" " +
+ "targetType=\"newTargetType\" " +
+ "namelist=\"names\" " +
+ "delay=\"4 secs\" " +
+ "events=\"turnoff\" " +
+ "hints=\"guess\">\n </send>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ SCXMLSerializer.serializeSend(returnValue, send, " ");
+
+ assertEquals(assertValue.toString(), returnValue.toString());
+ }
+
+ public void testSerializeActionsListNull() {
+ TransitionTarget target = new State();
+ target.setId("1");
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
null, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(0, returnValue.length());
+ }
+
+ public void testSerializeActionsVar() {
+ Var var = new Var();
+ var.setName("newName");
+ var.setExpr("newExpression");
+
+ List values = new ArrayList();
+ values.add(var);
+
+ String actualValue = " <var name=\"newName\"
expr=\"newExpression\"/>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeActionsAssign() {
+ Assign assign = new Assign();
+ assign.setName("newName");
+ assign.setExpr("newExpression");
+
+ List values = new ArrayList();
+ values.add(assign);
+
+ String actualValue = " <assign name=\"newName\"
expr=\"newExpression\"/>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeActionsCancel() {
+ Cancel cancel = new Cancel();
+ cancel.setSendid("1");
+
+ List values = new ArrayList();
+ values.add(cancel);
+
+ String actualValue = " <cancel sendid=\"1\"/>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeActionsLog() {
+ Log log = new Log();
+ log.setExpr("newExpression");
+
+ List values = new ArrayList();
+ values.add(log);
+
+ String actualValue = " <log expr=\"newExpression\"/>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeActionsExit() {
+ Exit exit = new Exit();
+ exit.setExpr("newExpression");
+ exit.setNamelist("names");
+
+ List values = new ArrayList();
+ values.add(exit);
+
+ String actualValue = " <exit expr=\"newExpression\"
namelist=\"names\"/>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertTrue(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeActionsElse() {
+ Else elseValue = new Else();
+
+ List values = new ArrayList();
+ values.add(elseValue);
+
+ String actualValue = " <else/>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeActionsElseIf() {
+ ElseIf elseIf = new ElseIf();
+ elseIf.setCond("newCondition");
+
+ List values = new ArrayList();
+ values.add(elseIf);
+
+ String actualValue = " <elseif cond=\"newCondition\" />\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeIf() {
+ If ifValue = new If();
+ ifValue.setCond("newCondition");
+
+ List values = new ArrayList();
+ values.add(ifValue);
+
+ String actualValue = " <if cond=\"newCondition\">\n </if>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue,
values, " ");
+
+ assertFalse(returnBoolean);
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeOnEntrySizeZero() {
+ TransitionTarget target = new State();
+ target.setOnEntry(new OnEntry());
+
+ String actualValue = "";
+
+ StringBuffer returnValue = new StringBuffer();
+ SCXMLSerializer.serializeOnEntry(returnValue, target, " ");
+
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeOnEntry() {
+ TransitionTarget target = new State();
+
+ OnEntry onEntry = new OnEntry();
+ onEntry.addAction(new Else());
+
+ target.setOnEntry(onEntry);
+
+ String actualValue = " <onentry>\n <else/>\n </onentry>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ SCXMLSerializer.serializeOnEntry(returnValue, target, " ");
+
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeOnExitSizeZero() {
+ TransitionTarget target = new State();
+ target.setOnExit(new OnExit());
+
+ String actualValue = "";
+
+ StringBuffer returnValue = new StringBuffer();
+ SCXMLSerializer.serializeOnExit(returnValue, target, " ");
+
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+ public void testSerializeOnExit() {
+ TransitionTarget target = new State();
+
+ OnExit onExit = new OnExit();
+ onExit.addAction(new Else());
+
+ target.setOnExit(onExit);
+
+ String actualValue = " <onexit>\n <else/>\n </onexit>\n";
+
+ StringBuffer returnValue = new StringBuffer();
+ SCXMLSerializer.serializeOnExit(returnValue, target, " ");
+
+ assertEquals(actualValue, returnValue.toString());
+ }
+
+}
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
------------------------------------------------------------------------------
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=374829&r1=374828&r2=374829&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
Fri Feb 3 20:54:44 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-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.
@@ -48,6 +48,7 @@
TestSuite suite = new TestSuite();
suite.setName("Commons-SCXML Model Tests");
suite.addTest(ActionsTest.suite());
+ suite.addTest(TestAction.suite());
return suite;
}
}
Added:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java?rev=374829&view=auto
==============================================================================
---
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java
(added)
+++
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java
Fri Feb 3 20:54:44 2006
@@ -0,0 +1,111 @@
+/*
+ * 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 TestAction extends TestCase {
+
+ public TestAction(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestAction.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestAction.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ private Action action;
+
+ public void setUp() {
+ action = new Assign();
+ }
+
+ public void testGetParentStateIsState() throws Exception {
+ Transition transition = new Transition();
+
+ State state = new State();
+ state.setId("on");
+
+ transition.setParent(state);
+ action.setParent(transition);
+
+ State returnValue = action.getParentState();
+
+ assertEquals("on", returnValue.getId());
+ }
+
+ public void testGetParentStateIsParallel() throws Exception {
+ Transition transition = new Transition();
+
+ Parallel parallel = new Parallel();
+ parallel.setId("on");
+
+ State state = new State();
+ state.setId("off");
+
+ parallel.setParent(state);
+
+ transition.setParent(parallel);
+ action.setParent(transition);
+
+ State returnValue = action.getParentState();
+
+ assertEquals("off", returnValue.getId());
+ }
+
+ public void testGetParentStateIsHistory() throws Exception {
+ Transition transition = new Transition();
+
+ History history = new History();
+ history.setId("on");
+
+ State state = new State();
+ state.setId("off");
+
+ history.setParent(state);
+
+ transition.setParent(history);
+ action.setParent(transition);
+
+ State returnValue = action.getParentState();
+
+ assertEquals("off", returnValue.getId());
+ }
+
+ public void testGetParentStateIsInitial() {
+ Transition transition = new Transition();
+
+ Initial initial = new Initial();
+ initial.setId("on");
+
+ transition.setParent(initial);
+ action.setParent(transition);
+
+ try{
+ action.getParentState();
+ fail("Unknown TransitionTarget subclass:Initial");
+ }
+ catch( ModelException e ){
+ }
+ }
+}
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]