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  
18  package org.apache.commons.scxml2.env.javascript;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.Set;
23  
24  import org.apache.commons.scxml2.SCXMLExecutor;
25  import org.apache.commons.scxml2.SCXMLExpressionException;
26  import org.apache.commons.scxml2.SCXMLTestHelper;
27  import org.apache.commons.scxml2.TriggerEvent;
28  import org.apache.commons.scxml2.model.Action;
29  import org.apache.commons.scxml2.ActionExecutionContext;
30  import org.apache.commons.scxml2.model.CustomAction;
31  import org.apache.commons.scxml2.model.EnterableState;
32  import org.apache.commons.scxml2.model.ModelException;
33  import org.apache.commons.scxml2.model.SCXML;
34  
35  import org.junit.Assert;
36  import org.junit.Test;
37  
38  /**
39   * SCXML application for the example JavaScript scripts.
40   *
41   */
42  public class JSExampleTest {
43  
44      // TEST METHODS
45      @Test
46      public void testExample01Sample() throws Exception {
47  
48          List<CustomAction> actions  = new ArrayList<CustomAction>();        
49          actions.add(new CustomAction("http://my.custom-actions.domain", "eventdatamaptest", EventDataMapTest.class));
50  
51          SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/env/javascript/example-01.xml", actions);
52          SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml);
53          exec.go();
54          Set<EnterableState> currentStates = exec.getStatus().getStates();
55          Assert.assertEquals(1, currentStates.size());
56          Assert.assertEquals("end", currentStates.iterator().next().getId());
57      }
58  
59      // INNER CLASSES
60      
61      public static class EventDataMapTest extends Action {
62          private static final long serialVersionUID = 1L;
63  
64          @Override
65          public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
66              exctx.getInternalIOProcessor().addEvent(new TriggerEvent("ok",TriggerEvent.SIGNAL_EVENT,"and its ok with me to"));
67          }
68      }
69  
70  }
71