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 */ 017 018package org.apache.commons.scxml2.env.javascript; 019 020import java.util.ArrayList; 021import java.util.List; 022import java.util.Set; 023 024import org.apache.commons.scxml2.SCXMLExecutor; 025import org.apache.commons.scxml2.SCXMLExpressionException; 026import org.apache.commons.scxml2.SCXMLTestHelper; 027import org.apache.commons.scxml2.TriggerEvent; 028import org.apache.commons.scxml2.model.Action; 029import org.apache.commons.scxml2.ActionExecutionContext; 030import org.apache.commons.scxml2.model.CustomAction; 031import org.apache.commons.scxml2.model.EnterableState; 032import org.apache.commons.scxml2.model.ModelException; 033import org.apache.commons.scxml2.model.SCXML; 034 035import org.junit.Assert; 036import org.junit.Test; 037 038/** 039 * SCXML application for the example JavaScript scripts. 040 * 041 */ 042public class JSExampleTest { 043 044 // TEST METHODS 045 @Test 046 public void testExample01Sample() throws Exception { 047 048 List<CustomAction> actions = new ArrayList<CustomAction>(); 049 actions.add(new CustomAction("http://my.custom-actions.domain", "eventdatamaptest", EventDataMapTest.class)); 050 051 SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/env/javascript/example-01.xml", actions); 052 SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml); 053 exec.go(); 054 Set<EnterableState> currentStates = exec.getStatus().getStates(); 055 Assert.assertEquals(1, currentStates.size()); 056 Assert.assertEquals("end", currentStates.iterator().next().getId()); 057 } 058 059 // INNER CLASSES 060 061 public static class EventDataMapTest extends Action { 062 private static final long serialVersionUID = 1L; 063 064 @Override 065 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException { 066 exctx.getInternalIOProcessor().addEvent(new TriggerEvent("ok",TriggerEvent.SIGNAL_EVENT,"and its ok with me to")); 067 } 068 } 069 070} 071