DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39534>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39534

           Summary: External Digester does not addCustomActions
           Product: Commons
           Version: 1.0 Alpha
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SCXML
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: [EMAIL PROTECTED]


I was not sure where to put my test-case. So attaching it here.

/*
 * Copyright 2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.scxml.model;

import java.net.URL;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.commons.digester.Digester;
import org.apache.commons.scxml.Context;
import org.apache.commons.scxml.Evaluator;
import org.apache.commons.scxml.SCXMLExecutor;
import org.apache.commons.scxml.SCXMLTestHelper;
import org.apache.commons.scxml.env.jexl.JexlContext;
import org.apache.commons.scxml.env.jexl.JexlEvaluator;
import org.apache.commons.scxml.io.SCXMLDigester;
import org.apache.commons.scxml.model.SCXML;
import org.apache.commons.scxml.model.State;

public class ExternalCustomActionTest extends TestCase {

    public ExternalCustomActionTest(String testName) {
        super(testName);
    }

    public static Test suite() {
        return new TestSuite(ExternalCustomActionTest.class);
    }

    public static void main(String args[]) {
        String[] testCaseName = { ExternalCustomActionTest.class.getName()};
        junit.textui.TestRunner.main(testCaseName);
    }

    private URL externalhello01, custom01;
    private Digester digester;
    private SCXMLExecutor exec;

    /**
     * Set up instance variables required by this test case.
     */
    public void setUp() {
        externalhello01 = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/external-hello-world.xml");
        custom01 = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/custom-hello-world.xml");
    }

    /**
     * Tear down instance variables required by this test case.
     */
    public void tearDown() {
        externalhello01 = custom01 = null;
        digester = null;
        exec = null;
    }

    // Hello World example using the SCXML <log> action
    public void testHelloWorld() {
        // (1) Get Digester with "default" rules for parsing SCXML documents
        digester = SCXMLDigester.newInstance(null, null);
        // (2) Register the "custom" action(s)
        SCXMLDigester.addCustomAction(digester,
            "http://my.custom-actions.domain/CUSTOM";, "hello", Hello.class);
        // (3) Parse the SCXML document containing the custom action(s)
        SCXML scxml = null;
        try {
            scxml = (SCXML) digester.parse(externalhello01.toString());
        } catch (Exception e) {
                e.printStackTrace();
            fail(e.getMessage());
        }
        // (4) Wire up the object model for the SCXMLExecutor
        SCXMLDigester.updateSCXML(scxml);
        // (5) Get a SCXMLExecutor
        Context context = new JexlContext();
        Evaluator evaluator = new JexlEvaluator();
        exec = SCXMLTestHelper.getExecutor(scxml, context, evaluator);
        // (6) Single, final state
        assertEquals("external-hello", ((State) 
exec.getCurrentStatus().getStates().
                iterator().next()).getId());
        assertEquals ("external world", context.get("custom"));
    }

    // Hello World example using a custom <hello> action
    public void testCustomActionHelloWorld() {
        // (1) Get Digester with "default" rules for parsing SCXML documents
        digester = SCXMLDigester.newInstance(null, null);
        // (2) Register the "custom" action(s)
        SCXMLDigester.addCustomAction(digester,
            "http://my.custom-actions.domain/CUSTOM";, "hello", Hello.class);
        // (3) Parse the SCXML document containing the custom action(s)
        SCXML scxml = null;
        try {
            scxml = (SCXML) digester.parse(custom01.toString());
        } catch (Exception e) {
                e.printStackTrace();
            fail(e.getMessage());
        }
        // (4) Wire up the object model for the SCXMLExecutor
        SCXMLDigester.updateSCXML(scxml);
        // (5) Get a SCXMLExecutor
        Context context = new JexlContext();
        Evaluator evaluator = new JexlEvaluator();
        exec = SCXMLTestHelper.getExecutor(scxml, context, evaluator);
        // (6) Fire events, proceed as usual
        assertEquals("external-hello", ((State) 
exec.getCurrentStatus().getStates().
                iterator().next()).getId());
        assertEquals ("external world", context.get("custom"));
    }
}

<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/SCXML";
       xmlns:my="http://my.custom-actions.domain/CUSTOM";
       version="1.0"
       initialstate="external-hello">

    <state id="external-hello">
        <onentry>
            <my:hello name="external world"/>
        </onentry>
    </state>

</scxml>



<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/SCXML";
       xmlns:my="http://my.custom-actions.domain/CUSTOM";
       version="1.0"
       initialstate="custom">
        <datamodel/>
    <state id="custom" final="true"
src="test/org/apache/commons/scxml/external-hello-world.xml"/>
</scxml>

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to