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.xpath;
019
020import java.util.Set;
021
022import org.apache.commons.scxml2.SCXMLExecutor;
023import org.apache.commons.scxml2.SCXMLTestHelper;
024import org.apache.commons.scxml2.TriggerEvent;
025import org.apache.commons.scxml2.model.EnterableState;
026
027import org.junit.Assert;
028import org.junit.Test;
029
030/**
031 * SCXML application for the XPath example.
032 *
033 */
034public class XPathExampleTest {
035
036    @Test
037    public void testExample01Sample() throws Exception {
038
039        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/env/xpath/example-01.xml");
040        exec.go();
041        Set<EnterableState> currentStates = exec.getStatus().getStates();
042        Assert.assertEquals(1, currentStates.size());
043        Assert.assertEquals("mid", currentStates.iterator().next().getId());
044
045        String payload = "<test xmlns=''><status>complete</status></test>";
046        SCXMLTestHelper.assertPostTriggerState(exec,
047            new TriggerEvent("foo", TriggerEvent.SIGNAL_EVENT,
048                SCXMLTestHelper.stringToXMLDocument(payload)),
049            "end");
050
051    }
052    
053    @Test
054    public void testExample02Sample() throws Exception {
055
056        SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/env/xpath/example-02.xml");
057        exec.go();
058        Set<EnterableState> currentStates = exec.getStatus().getStates();
059        Assert.assertEquals(1, currentStates.size());
060        Assert.assertEquals("end", currentStates.iterator().next().getId());
061
062    }
063}
064