001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.scxml2.model;
018
019import org.apache.commons.scxml2.SCXMLExecutor;
020import org.apache.commons.scxml2.SCXMLTestHelper;
021import org.junit.Assert;
022import org.junit.Test;
023
024public class ParallelTest {
025
026    @Test
027    public void testParallel01() throws Exception {
028        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/parallel-01.xml");
029        exec.go();
030        SCXMLTestHelper.assertPostTriggerState(exec, "foo", "end");
031    }
032    
033    @Test
034    public void testParallel02() throws Exception {
035        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/parallel-02.xml");
036        exec.go();
037        SCXMLTestHelper.assertPostTriggerStates(exec, "dummy.event", new String[] { "state01", "state02" });
038        SCXMLTestHelper.assertPostTriggerState(exec, "event1", "state1");
039    }
040    
041    @Test
042    public void testParallel03() throws Exception {
043        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/parallel-03.xml");
044        exec.go();
045        SCXMLTestHelper.assertPostTriggerStates(exec, "dummy.event", new String[] { "para11", "para21" });
046        Object count = exec.getEvaluator().eval(exec.getGlobalContext(),"Data('string(root/root/count)')");
047        Assert.assertEquals("5.0", count.toString());
048        SCXMLTestHelper.assertPostTriggerStates(exec, "foo", new String[] { "para12", "para21" });
049        count = exec.getEvaluator().eval(exec.getGlobalContext(),"Data('string(root/root/count)')");
050        Assert.assertEquals("7.0", count.toString());
051        SCXMLTestHelper.assertPostTriggerState(exec, "bar", "end");
052        count = exec.getEvaluator().eval(exec.getGlobalContext(),"Data('string(root/root/count)')");
053        Assert.assertEquals("14.0", count.toString());
054    }
055}