View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.scxml2;
18  
19  import java.util.Set;
20  
21  import org.apache.commons.scxml2.model.EnterableState;
22  import org.junit.Assert;
23  import org.junit.Test;
24  /**
25   * Unit tests {@link org.apache.commons.scxml2.SCXMLExecutor}.
26   * Testing wildcard event matching (*)
27   */
28  public class WildcardTest {
29  
30      /**
31       * Test the SCXML documents, usage of "_event.data"
32       */
33      @Test
34      public void testWildcard01Sample() throws Exception {
35      	SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/env/jexl/wildcard-01.xml");
36          exec.go();
37          Set<EnterableState> currentStates = exec.getStatus().getStates();
38          Assert.assertEquals(1, currentStates.size());
39          Assert.assertEquals("state1", currentStates.iterator().next().getId());
40          exec = SCXMLTestHelper.testInstanceSerializability(exec);
41          currentStates = SCXMLTestHelper.fireEvent(exec, "foo.bar.baz");
42          Assert.assertEquals(1, currentStates.size());
43          Assert.assertEquals("state4", currentStates.iterator().next().getId());
44      }
45  
46      @Test
47      public void testWildcard02Sample() throws Exception {
48          SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/env/jexl/wildcard-02.xml");
49          exec.go();
50          Set<EnterableState> currentStates = exec.getStatus().getStates();
51          Assert.assertEquals(1, currentStates.size());
52          Assert.assertEquals("state2", currentStates.iterator().next().getId());
53      }
54  }