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;
018
019import java.util.Set;
020
021import org.apache.commons.scxml2.model.EnterableState;
022import org.junit.Assert;
023import org.junit.Test;
024/**
025 * Unit tests {@link org.apache.commons.scxml2.SCXMLExecutor}.
026 * Testing wildcard event matching (*)
027 */
028public class WildcardTest {
029
030    /**
031     * Test the SCXML documents, usage of "_event.data"
032     */
033    @Test
034    public void testWildcard01Sample() throws Exception {
035        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/env/jexl/wildcard-01.xml");
036        exec.go();
037        Set<EnterableState> currentStates = exec.getStatus().getStates();
038        Assert.assertEquals(1, currentStates.size());
039        Assert.assertEquals("state1", currentStates.iterator().next().getId());
040        exec = SCXMLTestHelper.testInstanceSerializability(exec);
041        currentStates = SCXMLTestHelper.fireEvent(exec, "foo.bar.baz");
042        Assert.assertEquals(1, currentStates.size());
043        Assert.assertEquals("state4", currentStates.iterator().next().getId());
044    }
045
046    @Test
047    public void testWildcard02Sample() throws Exception {
048        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/env/jexl/wildcard-02.xml");
049        exec.go();
050        Set<EnterableState> currentStates = exec.getStatus().getStates();
051        Assert.assertEquals(1, currentStates.size());
052        Assert.assertEquals("state2", currentStates.iterator().next().getId());
053    }
054}