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/01 05:07:17 UTC

svn commit: r373983 - in /jakarta/commons/sandbox/scxml/trunk: ./ src/test/java/org/apache/commons/scxml/ src/test/java/org/apache/commons/scxml/env/

Author: rahul
Date: Tue Jan 31 20:07:11 2006
New Revision: 373983

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

Thanks to Peter Costa <pcosta02 AT yahoo DOT com>

Also added Peter to list of contributors.

Added:
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestBuiltin.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java   (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestSimpleContext.java   (with props)
Modified:
    jakarta/commons/sandbox/scxml/trunk/project.xml
    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/env/EnvTestSuite.java

Modified: jakarta/commons/sandbox/scxml/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/project.xml?rev=373983&r1=373982&r2=373983&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/project.xml (original)
+++ jakarta/commons/sandbox/scxml/trunk/project.xml Tue Jan 31 20:07:11 2006
@@ -87,6 +87,9 @@
     <contributor>
       <name>Jaroslav Gergic</name>
     </contributor>
+    <contributor>
+      <name>Peter Costa</name>
+    </contributor>
   </contributors>
   
   <dependencies>

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=373983&r1=373982&r2=373983&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 Tue Jan 31 20:07:11 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,8 @@
         suite.setName("Commons-SCXML Tests");
         suite.addTest(SCXMLDigesterTest.suite());
         suite.addTest(SCXMLExecutorTest.suite());
+        suite.addTest(TestBuiltin.suite());
+        suite.addTest(TestSCXMLHelper.suite());
         suite.addTest(TriggerEventTest.suite());
         return suite;
     }

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestBuiltin.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestBuiltin.java?rev=373983&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestBuiltin.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestBuiltin.java Tue Jan 31 20:07:11 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.scxml.model.State;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestBuiltin extends TestCase {
+
+    public TestBuiltin(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestBuiltin.class);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestBuiltin.class.getName()};
+        junit.textui.TestRunner.main(testCaseName);
+    }
+    
+    public void testIsMemberEmptySet() {
+        Set set = new HashSet();
+        
+        assertFalse(Builtin.isMember(set, "on"));
+    }
+    
+    public void testIsMemberFalse() {
+        TransitionTarget state = new State();
+        state.setId("off");
+        
+        Set set = new HashSet();
+        set.add(state);
+        
+        assertFalse(Builtin.isMember(set, "on"));
+    }
+    
+    public void testIsMemberTrue() {
+        TransitionTarget state = new State();
+        state.setId("on");
+        
+        Set set = new HashSet();
+        set.add(state);
+        
+        assertTrue(Builtin.isMember(set, "on"));
+    }
+
+}

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

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

Added: 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=373983&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/TestSCXMLHelper.java Tue Jan 31 20:07:11 2006
@@ -0,0 +1,160 @@
+/* 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;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.scxml.env.SimpleErrorReporter;
+import org.apache.commons.scxml.model.Parallel;
+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 TestSCXMLHelper extends TestCase {
+
+    public TestSCXMLHelper(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestSCXMLHelper.class);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestSCXMLHelper.class.getName()};
+        junit.textui.TestRunner.main(testCaseName);
+    }
+    
+    public void testIsStringEmptyNull() {
+        assertTrue(SCXMLHelper.isStringEmpty(null));
+    }
+    
+    public void testIsStringEmptyZeroLength() {
+        assertTrue(SCXMLHelper.isStringEmpty(""));
+    }
+
+    public void testIsStringEmpty() {
+        assertFalse(SCXMLHelper.isStringEmpty("value"));
+    }
+
+    public void testIsDescendantNullParent() {
+        TransitionTarget state = new State();
+        TransitionTarget context = new State();
+        
+        assertFalse(SCXMLHelper.isDescendant(state, context));
+    }
+    
+    public void testIsDescendantNotEqual() {
+        TransitionTarget state = new State();
+        state.setParent(new State());
+        TransitionTarget context = new State();
+        
+        assertFalse(SCXMLHelper.isDescendant(state, context));
+    }
+    
+    public void testIsDescendantEqual() {
+        TransitionTarget state = new State();
+        TransitionTarget context = new State();
+        state.setParent(context);
+        
+        assertTrue(SCXMLHelper.isDescendant(state, context));
+    }
+    
+    public void testIsDescendantParentEqual() {
+        TransitionTarget state = new State();
+        TransitionTarget context = new State();
+        TransitionTarget parent = new State();
+
+        parent.setParent(context);
+        state.setParent(parent);
+        
+        assertTrue(SCXMLHelper.isDescendant(state, context));
+    }
+    
+    public void testGetAncestorClosureEmptySet() {
+        Set states = new HashSet();
+        
+        Set returnValue = SCXMLHelper.getAncestorClosure(states, new HashSet());
+        
+        assertEquals(0, returnValue.size());
+    }
+    
+    public void testGetAncestorClosureUpperBoundNotNullAndContains() {
+        Set states = new HashSet();
+        TransitionTarget state = new State();
+        state.setId("1");
+        states.add(state);
+        
+        Set upperBounds = new HashSet();
+        upperBounds.add(state);
+        
+        Set returnValue = SCXMLHelper.getAncestorClosure(states, upperBounds);
+        
+        assertEquals(1, returnValue.size());
+        assertEquals("1", ((TransitionTarget)returnValue.toArray()[0]).getId());
+    }
+    
+    public void testGetAncestorClosureContainsParent() {
+        Set states = new HashSet();
+        TransitionTarget state = new State();
+        state.setId("1");
+        state.setParent(state);
+        states.add(state);
+        
+        Set upperBounds = new HashSet();
+        
+        Set returnValue = SCXMLHelper.getAncestorClosure(states, upperBounds);
+        
+        assertEquals(1, returnValue.size());
+        assertEquals("1", ((TransitionTarget)returnValue.toArray()[0]).getId());
+    }
+    
+    public void testIsLegalConfigNoStates() {
+        Set states = new HashSet();
+        
+        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();
+
+        State state1 = new State();
+        state1.setId("1");
+        State state2 = new State();
+        state2.setId("2");
+        
+        parent.addState(state1);
+        parent.addState(state2);
+        
+        parallel.setParent(parent);
+        
+        states.add(parallel);
+        
+        SimpleErrorReporter errorReporter = new SimpleErrorReporter();
+        
+        assertFalse(SCXMLHelper.isLegalConfig(states, errorReporter));
+    }
+
+}

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

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

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=373983&r1=373982&r2=373983&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 Tue Jan 31 20:07:11 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.
@@ -47,6 +47,7 @@
     public static Test suite() {
         TestSuite suite = new TestSuite();
         suite.setName("Commons-SCXML Environments Tests");
+        suite.addTest(TestSimpleContext.suite());
         return suite;
     }
 }

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestSimpleContext.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestSimpleContext.java?rev=373983&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestSimpleContext.java (added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/TestSimpleContext.java Tue Jan 31 20:07:11 2006
@@ -0,0 +1,184 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestSimpleContext extends TestCase {
+
+    public TestSimpleContext(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestSimpleContext.class);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestSimpleContext.class.getName()};
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    private SimpleContext context;
+
+    protected void setUp() throws Exception {
+        context = new SimpleContext();
+    }
+    
+    public void testHasTrue() {
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        
+        assertTrue(context.has("key"));
+    }
+
+    public void testHasNullParent() {
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        
+        assertFalse(context.has("differentKey"));
+    }
+    
+    public void testHasParentWrongKey() {
+        Map parentVars = new HashMap();
+        parentVars.put("key", "value");
+        
+        SimpleContext parentContext = new SimpleContext(parentVars);
+        
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        context = new SimpleContext(parentContext, parentVars);
+        
+        assertFalse(context.has("differentKey"));
+    }
+
+    public void testHasParentCorrectKey() {
+        Map parentVars = new HashMap();
+        parentVars.put("differentKey", "value");
+        
+        SimpleContext parentContext = new SimpleContext(parentVars);
+        
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        context = new SimpleContext(parentContext, parentVars);
+        
+        assertTrue(context.has("differentKey"));
+    }
+    
+    public void testGetNull() {
+        Object value = context.get("key");
+        
+        assertNull(value);
+    }
+    
+    public void testGetValue() {
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        
+        assertEquals("value", context.get("key"));
+    }
+    
+    public void testGetParentValue() {
+        Map parentVars = new HashMap();
+        parentVars.put("differentKey", "differentValue");
+        
+        SimpleContext parentContext = new SimpleContext(parentVars);
+        
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        context = new SimpleContext(parentContext, parentVars);
+        
+        assertEquals("differentValue", context.get("differentKey"));
+    }
+    
+    public void testGetParentNull() {
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        
+        assertNull(context.get("differentKey"));
+    }
+    
+    public void testGetParentWrongValue() {
+        Map parentVars = new HashMap();
+        parentVars.put("differentKey", "differentValue");
+        
+        SimpleContext parentContext = new SimpleContext(parentVars);
+        
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        context = new SimpleContext(parentContext, parentVars);
+        
+        assertNull(context.get("reallyDifferentKey"));
+    }
+
+    public void testSetVarsChangeValue() {
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        
+        context.set("key", "newValue");
+        
+        assertEquals("newValue", context.get("key"));
+    }
+
+    public void testSetVarsEmpty() {
+        Map vars = new HashMap();
+        context.setVars(vars);
+        
+        context.set("key", "newValue");
+        
+        assertEquals("newValue", context.get("key"));
+    }
+    
+    public void testSetVarsParent() {
+        Map parentVars = new HashMap();
+        parentVars.put("differentKey", "differentValue");
+        
+        SimpleContext parentContext = new SimpleContext(parentVars);
+        
+        Map vars = new HashMap();
+        vars.put("key", "value");
+        
+        context.setVars(vars);
+        context = new SimpleContext(parentContext, parentVars);
+        
+        context.set("differentKey", "newValue");
+        
+        assertEquals("newValue", context.get("differentKey"));
+    }
+}

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

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