commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r374574 - in /jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml: SCXMLTestSuite.java TestSCXMLHelper.java TestStatus.java env/MockErrorReporter.java
Date Fri, 03 Feb 2006 03:38:16 GMT
Author: rahul
Date: Thu Feb  2 19:38:13 2006
New Revision: 374574

URL: http://svn.apache.org/viewcvs?rev=374574&view=rev
Log:
BZ 38459 [scxml] JUnit tests for SCXML 

Thanks again to Peter Costa <pcosta02 AT yahoo DOT com>

Also contains a mock ErrorReporter implementation, which is quite useful for writing test
cases for the SCXML engine, amongst other things.

Added:
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
  (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.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/TestSCXMLHelper.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=374574&r1=374573&r2=374574&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  2 19:38:13 2006
@@ -50,6 +50,7 @@
         suite.addTest(SCXMLExecutorTest.suite());
         suite.addTest(TestBuiltin.suite());
         suite.addTest(TestSCXMLHelper.suite());
+        suite.addTest(TestStatus.suite());
         suite.addTest(TriggerEventTest.suite());
         return suite;
     }

Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java?rev=374574&r1=374573&r2=374574&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java
Thu Feb  2 19:38:13 2006
@@ -1,4 +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.
@@ -17,6 +18,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.commons.scxml.env.MockErrorReporter;
 import org.apache.commons.scxml.env.SimpleErrorReporter;
 import org.apache.commons.scxml.model.Parallel;
 import org.apache.commons.scxml.model.State;
@@ -131,14 +133,12 @@
         assertTrue(SCXMLHelper.isLegalConfig(states, new SimpleErrorReporter()));
     }
     
-    /*
-     * Not able to test the return values on ErrorReporter.
-     */
     public void testIsLegalConfigInvalidParallel() {
         Set states = new HashSet();
         Parallel parallel = new Parallel();
 
         Parallel parent = new Parallel();
+        parent.setId("4");
 
         State state1 = new State();
         state1.setId("1");
@@ -152,9 +152,120 @@
         
         states.add(parallel);
         
-        SimpleErrorReporter errorReporter = new SimpleErrorReporter();
+        MockErrorReporter errorReporter = new MockErrorReporter();
         
         assertFalse(SCXMLHelper.isLegalConfig(states, errorReporter));
+        assertEquals(ErrorReporter.ILLEGAL_CONFIG, errorReporter.getErrCode());
+        assertEquals("Not all AND states active for parallel 4", errorReporter.getErrDetail());
+    }
+    
+    public void testIsLegalConfigMultipleTopLevel() {
+        Set states = new HashSet();
+
+        State state1 = new State();
+        state1.setId("1");
+        State state2 = new State();
+        state2.setId("2");
+        
+        states.add(state1);
+        states.add(state2);
+        
+        MockErrorReporter errorReporter = new MockErrorReporter();
+        
+        assertTrue(SCXMLHelper.isLegalConfig(states, errorReporter));
+        assertEquals(ErrorReporter.ILLEGAL_CONFIG, errorReporter.getErrCode());
+        assertEquals("Multiple top-level OR states active!", errorReporter.getErrDetail());
+    }
+    
+    public void testIsLegalConfigMultipleStatesActive() {
+        Set states = new HashSet();
+
+        State state1 = new State();
+        state1.setId("1");
+        
+        State state2 = new State();
+        state2.setId("2");
+
+        State parent = new State();
+        parent.setId("parentid");
+        
+        state2.setParent(parent);
+        state1.setParent(parent);
+
+        states.add(state1);
+        states.add(state2);
+        
+        MockErrorReporter errorReporter = new MockErrorReporter();
+        
+        assertFalse(SCXMLHelper.isLegalConfig(states, errorReporter));
+        assertEquals(ErrorReporter.ILLEGAL_CONFIG, errorReporter.getErrCode());
+        assertEquals("Multiple OR states active for state parentid", errorReporter.getErrDetail());
+    }
+    
+    public void testGetLCASameTarget() {
+        TransitionTarget target = new State();
+        target.setId("1");
+        
+        TransitionTarget returnValue = SCXMLHelper.getLCA(target, target);
+        
+        assertEquals("1", returnValue.getId());
+    }
+
+    public void testGetLCAIsDescendant() {
+        TransitionTarget target = new State();
+        target.setId("1");
+
+        TransitionTarget parent = new State();
+        parent.setId("2");
+
+        target.setParent(parent);
+        
+        TransitionTarget returnValue = SCXMLHelper.getLCA(target, parent);
+        
+        assertEquals("2", returnValue.getId());
+    }
+    
+    public void testGetLCAIsDescendantReverse() {
+        TransitionTarget target = new State();
+        target.setId("1");
+
+        TransitionTarget parent = new State();
+        parent.setId("2");
+
+        parent.setParent(target); // reversed
+        
+        TransitionTarget returnValue = SCXMLHelper.getLCA(target, parent);
+        
+        assertEquals("1", returnValue.getId());
+    }
+
+    public void testGetLCANull() {
+        TransitionTarget target = new State();
+        target.setId("1");
+
+        TransitionTarget notParent = new State();
+        notParent.setId("2");
+
+        TransitionTarget returnValue = SCXMLHelper.getLCA(target, notParent);
+        
+        assertNull(returnValue);
     }
 
+    public void testGetLCADistantAncestor() {
+        TransitionTarget target1 = new State();
+        target1.setId("1");
+
+        TransitionTarget target2 = new State();
+        target2.setId("2");
+
+        TransitionTarget parent = new State();
+        parent.setId("3");
+
+        target1.setParent(parent);
+        target2.setParent(parent);
+        
+        TransitionTarget returnValue = SCXMLHelper.getLCA(target1, target2);
+        
+        assertEquals("3", returnValue.getId());
+    }
 }

Added: 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=374574&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
Thu Feb  2 19:38:13 2006
@@ -0,0 +1,80 @@
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.scxml.model.State;
+
+public class TestStatus extends TestCase {
+
+    public TestStatus(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(TestStatus.class);
+        suite.setName("TestStatus");
+        return suite;
+    }
+
+    private Status status;
+    
+    public void setUp() {
+        status = new Status();
+    }
+    
+    public void testIsFinalStateFalse() {
+        State state = new State();
+        state.setIsFinal(false);
+        
+        status.getStates().add(state);
+        
+        assertFalse(status.isFinal());
+    }
+    
+    public void testIsFinalStateHasParent() {
+        State state = new State();
+        state.setIsFinal(true);
+        state.setParent(new State());
+        
+        status.getStates().add(state);
+
+        assertFalse(status.isFinal());
+    }
+    
+    public void testIsFinalStateHasEvent() {
+        State state = new State();
+        state.setIsFinal(true);
+        
+        status.getStates().add(state);
+        status.getEvents().add(new TriggerEvent("name", TriggerEvent.CALL_EVENT));
+        
+        assertFalse(status.isFinal());
+    }
+    
+    public void testIsFinalState() {
+        State state = new State();
+        state.setIsFinal(true);
+        
+        status.getStates().add(state);
+        
+        assertTrue(status.isFinal());
+    }
+    
+}

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestStatus.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.java?rev=374574&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.java
Thu Feb  2 19:38:13 2006
@@ -0,0 +1,56 @@
+/*
+ * 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.ErrorReporter;
+
+public class MockErrorReporter implements ErrorReporter {
+
+    private String errCode;
+    private String errDetail;
+    private Object errCtx;
+    
+    public void onError( String errCode, String errDetail, Object errCtx ) {
+        this.errCode = errCode;
+        this.errDetail = errDetail;
+        this.errCtx = errCtx;
+    }
+
+    public String getErrCode() {
+        return errCode;
+    }
+
+    public void setErrCode( String errCode ) {
+        this.errCode = errCode;
+    }
+
+    public Object getErrCtx() {
+        return errCtx;
+    }
+
+    public void setErrCtx( Object errCtx ) {
+        this.errCtx = errCtx;
+    }
+
+    public String getErrDetail() {
+        return errDetail;
+    }
+
+    public void setErrDetail( String errDetail ) {
+        this.errDetail = errDetail;
+    }
+
+}

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/MockErrorReporter.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


Mime
View raw message