commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r375455 - in /jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml: io/TestSCXMLSerializer.java model/ModelTestSuite.java model/TestPath.java semantics/SemanticsTestSuite.java semantics/TestTransitionTargetComparator.java
Date Tue, 07 Feb 2006 03:33:31 GMT
Author: rahul
Date: Mon Feb  6 19:33:28 2006
New Revision: 375455

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

By: Peter Costa <pcosta02 AT yahoo DOT com>

(also cleans up imports in one the test classes)

Thanks Peter.


Added:
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestPath.java
  (with props)
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TestTransitionTargetComparator.java
  (with props)
Modified:
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/ModelTestSuite.java
    jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/SemanticsTestSuite.java

Modified: 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=375455&r1=375454&r2=375455&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/io/TestSCXMLSerializer.java
Mon Feb  6 19:33:28 2006
@@ -16,16 +16,17 @@
 package org.apache.commons.scxml.io;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
 
 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;
@@ -35,10 +36,6 @@
 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 {
 

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=375455&r1=375454&r2=375455&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
Mon Feb  6 19:33:28 2006
@@ -49,6 +49,7 @@
         suite.setName("Commons-SCXML Model Tests");
         suite.addTest(ActionsTest.suite());
         suite.addTest(TestAction.suite());
+        suite.addTest(TestPath.suite());
         return suite;
     }
 }

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestPath.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestPath.java?rev=375455&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestPath.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/model/TestPath.java
Mon Feb  6 19:33:28 2006
@@ -0,0 +1,277 @@
+/*
+ * 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 TestPath extends TestCase {
+
+    public TestPath(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestPath.class);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestPath.class.getName()};
+        junit.textui.TestRunner.main(testCaseName);
+    }
+    
+    public void testConstructorNull() {
+        Path path = new Path(null, null);
+        
+        assertNull(path.getScope());
+    }
+
+    public void testConstructorNullState() {
+        Path path = new Path(new State(), null);
+        
+        assertTrue(path.getScope() instanceof State);
+    }
+
+    public void testConstructorStates() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+        
+        assertNull(path.getScope());
+        assertEquals(1, path.getUpwardSegment().size());
+        assertEquals("1", ((State)path.getUpwardSegment().get(0)).getId());
+
+        assertEquals(1, path.getDownwardSegment().size());
+        assertEquals("2", ((State)path.getDownwardSegment().get(0)).getId());
+        
+        assertFalse(path.isCrossRegion());
+    }
+    
+    public void testConstructorSourceCrossRegion() {
+        Parallel region = new Parallel();
+        
+        TransitionTarget source = new State();
+        source.setId("1");
+        source.setParent(region);
+        
+        TransitionTarget target = new State();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+        
+        assertTrue(path.isCrossRegion());
+    }
+
+    public void testConstructorTargetCrossRegion() {
+        Parallel region = new Parallel();
+        
+        TransitionTarget source = new State();
+        source.setId("1");
+        
+        TransitionTarget target = new State();
+        target.setId("2");
+        target.setParent(region);
+        
+        Path path = new Path(source, target);
+        
+        assertTrue(path.isCrossRegion());
+    }
+
+    public void testConstructorParentTarget() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+
+        source.setParent(target);
+
+        Path path = new Path(source, target);
+
+        assertNull(path.getScope());
+    }
+
+    public void testConstructorParentSource() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+
+        target.setParent(source);
+
+        Path path = new Path(source, target);
+
+        assertNull(path.getScope());
+    }
+    
+    public void testConstructorParent() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+
+        State parent = new State();
+        parent.setId("parentid");
+        
+        target.setParent(parent);
+        source.setParent(parent);
+
+        Path path = new Path(source, target);
+
+        assertEquals("parentid", ((State)path.getScope()).getId());
+    }
+    
+    public void testConstructorParentParallel() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+
+        Parallel parent = new Parallel();
+        parent.setId("parentid");
+        
+        target.setParent(parent);
+        source.setParent(parent);
+
+        Path path = new Path(source, target);
+
+        assertNull(path.getScope());
+    }
+    
+    public void testConstructorParentParallelParent() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+
+        Parallel parent = new Parallel();
+        parent.setId("parentid");
+        
+        State parentOfParent = new State();
+        parentOfParent.setId("superParent");
+ 
+        parent.setParent(parentOfParent);
+        
+        target.setParent(parent);
+        source.setParent(parent);
+
+        Path path = new Path(source, target);
+
+        assertEquals("superParent", ((State)path.getScope()).getId());
+    }
+    
+    public void testGetRegionsExitedNull() {
+        Path path = new Path(new State(), null);
+
+        assertEquals(0, path.getRegionsExited().size());
+    }
+    
+    public void testGetRegionsExitedNotRegion() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+
+        assertEquals(0, path.getRegionsExited().size());
+    }
+    
+    public void testGetRegionsExitedParallel() {
+        TransitionTarget source = new Parallel();
+        source.setId("1");
+
+        TransitionTarget target = new Parallel();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+
+        assertEquals(0, path.getRegionsExited().size());
+    }
+    
+    public void testGetRegionsExited() {
+        Parallel region = new Parallel();
+        
+        TransitionTarget source = new State();
+        source.setId("1");
+        source.setParent(region);
+        
+        TransitionTarget target = new State();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+        
+        assertEquals(1, path.getRegionsExited().size());
+        assertEquals("1", ((State)path.getRegionsExited().get(0)).getId());
+    }
+
+    public void testGetRegionsEnteredNull() {
+        Path path = new Path(new State(), null);
+
+        assertEquals(0, path.getRegionsEntered().size());
+    }
+    
+    public void testGetRegionsEnteredNotRegion() {
+        TransitionTarget source = new State();
+        source.setId("1");
+
+        TransitionTarget target = new State();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+
+        assertEquals(0, path.getRegionsEntered().size());
+    }
+    
+    public void testGetRegionsEnteredParallel() {
+        TransitionTarget source = new Parallel();
+        source.setId("1");
+
+        TransitionTarget target = new Parallel();
+        target.setId("2");
+        
+        Path path = new Path(source, target);
+
+        assertEquals(0, path.getRegionsEntered().size());
+    }
+    
+    public void testGetRegionsEntered() {
+        Parallel region = new Parallel();
+        
+        TransitionTarget source = new State();
+        source.setId("1");
+        
+        TransitionTarget target = new State();
+        target.setId("2");
+        target.setParent(region);
+        
+        Path path = new Path(source, target);
+        
+        assertEquals(1, path.getRegionsEntered().size());
+        assertEquals("2", ((State)path.getRegionsEntered().get(0)).getId());
+    }
+
+}

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

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

Modified: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/SemanticsTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/SemanticsTestSuite.java?rev=375455&r1=375454&r2=375455&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/SemanticsTestSuite.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/SemanticsTestSuite.java
Mon Feb  6 19:33:28 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 Semantics Tests");
+        suite.addTest(TestTransitionTargetComparator.suite());
         return suite;
     }
 }

Added: jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TestTransitionTargetComparator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TestTransitionTargetComparator.java?rev=375455&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TestTransitionTargetComparator.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/semantics/TestTransitionTargetComparator.java
Mon Feb  6 19:33:28 2006
@@ -0,0 +1,115 @@
+/*
+ * 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.semantics;
+
+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 TestTransitionTargetComparator extends TestCase {
+
+    public TestTransitionTargetComparator(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestTransitionTargetComparator.class);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestTransitionTargetComparator.class.getName()};
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    private TransitionTargetComparator comparator;
+    
+    public void setUp() {
+        comparator = new TransitionTargetComparator();
+    }
+    
+    public void testComparatorEquals() {
+        TransitionTarget target = new State();
+        
+        assertEquals(0, comparator.compare(target, target));
+    }
+    
+    public void testComparatorNegative() {
+        TransitionTarget target1 = new State();
+        TransitionTarget target2 = new State();
+        
+        target1.setParent(target2);
+        
+        assertEquals(-1, comparator.compare(target1, target2));
+    }
+    
+    public void testComparatorPositive() {
+        TransitionTarget target1 = new State();
+        TransitionTarget target2 = new State();
+        
+        target2.setParent(target1);
+        
+        assertEquals(1, comparator.compare(target1, target2));
+    }
+    
+    public void testComparatorFirstMoreParents() {
+        TransitionTarget target1 = new State();
+        TransitionTarget parent1 = new State();
+        TransitionTarget parent2 = new State();
+
+        parent1.setParent(parent2);
+        target1.setParent(parent1);
+        
+        TransitionTarget target2 = new State();
+        TransitionTarget parent3 = new State();
+        
+        target2.setParent(parent3);
+        
+        assertEquals(-1, comparator.compare(target1, target2));
+    }
+    
+    public void testComparatorSecondMoreParents() {
+        TransitionTarget target1 = new State();
+        TransitionTarget parent1 = new State();
+        TransitionTarget parent2 = new State();
+
+        parent1.setParent(parent2);
+        target1.setParent(parent1);
+        
+        TransitionTarget target2 = new State();
+        TransitionTarget parent3 = new State();
+        
+        target2.setParent(parent3);
+        
+        assertEquals(1, comparator.compare(target2, target1)); // reversed
+    }
+    
+    public void testComparatorSameParents() {
+        TransitionTarget target1 = new State();
+        TransitionTarget parent1 = new State();
+
+        target1.setParent(parent1);
+        
+        TransitionTarget target2 = new State();
+        TransitionTarget parent2 = new State();
+        
+        target2.setParent(parent2);
+        
+        assertEquals(0, comparator.compare(target1, target2));
+    }
+}

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

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