<commit_before>/*
 * Copyright 2005 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;

import java.net.URL;
import java.util.Set;

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

import org.apache.commons.scxml.model.State;
/**
 * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
 */
public class SCXMLExecutorTest extends TestCase {
    /**
     * Construct a new instance of SCXMLExecutorTest with
     * the specified name
     */
    public SCXMLExecutorTest(String name) {
        super(name);
    }

    public static Test suite() {
        TestSuite suite = new TestSuite(SCXMLExecutorTest.class);
        suite.setName("SCXML Executor Tests");
        return suite;
    }

    // Test data
    private URL microwave01, microwave02, transitions01;
    private SCXMLExecutor exec;

    /**
     * Set up instance variables required by this test case.
     */
    public void setUp() {
        microwave01 = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/env/jsp/microwave-01.xml");
        microwave02 = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/env/jsp/microwave-02.xml");
        transitions01 = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/transitions-01.xml");
    }

    /**
     * Tear down instance variables required by this test case.
     */
    public void tearDown() {
        microwave01 = microwave02 = transitions01 = null;
    }

    /**
     * Test the implementation
     */
    public void testSCXMLExecutorMicrowave01Sample() {
        exec = SCXMLTestHelper.getExecutor(microwave01);
        assertNotNull(exec);
    }

    public void testSCXMLExecutorMicrowave02Sample() {
        exec = SCXMLTestHelper.getExecutor(microwave02);
        assertNotNull(exec);
    }

    public void testSCXMLExecutorTransitions01Sample() {
        exec = SCXMLTestHelper.getExecutor(transitions01);
        assertNotNull(exec);
        try {
            Set currentStates = fireEvent("ten.done");
            assertTrue(currentStates.size() == 1);
            assertEquals("twenty_one", ((State)currentStates.iterator().
                next()).getId());
            currentStates = fireEvent("twenty_one.done");
            assertTrue(currentStates.size() == 1);
            assertEquals("twenty_two", ((State)currentStates.iterator().
                next()).getId());
            currentStates = fireEvent("twenty_two.done");
            assertTrue(exec.getCurrentStatus().getStates().size() == 3);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    private Set fireEvent(String name) {
        TriggerEvent[] evts = {new TriggerEvent(name,
                TriggerEvent.SIGNAL_EVENT, null)};
        try {
            exec.triggerEvents(evts);
        } catch (Exception e) {
            fail(e.getMessage());
        }
        return exec.getCurrentStatus().getStates();
    }

    public static void main(String args[]) {
        TestRunner.run(suite());
    }
}
<commit_msg>Add couple of tests for the microwave samples that use JEXL expressions.<commit_after>/*
 * Copyright 2005 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;

import java.net.URL;
import java.util.Set;

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

import org.apache.commons.scxml.env.SimpleContext;
import org.apache.commons.scxml.env.jsp.ELEvaluator;
import org.apache.commons.scxml.model.State;
/**
 * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
 */
public class SCXMLExecutorTest extends TestCase {
    /**
     * Construct a new instance of SCXMLExecutorTest with
     * the specified name
     */
    public SCXMLExecutorTest(String name) {
        super(name);
    }

    public static Test suite() {
        TestSuite suite = new TestSuite(SCXMLExecutorTest.class);
        suite.setName("SCXML Executor Tests");
        return suite;
    }

    // Test data
    private URL microwave01jsp, microwave02jsp, microwave01jexl,
        microwave02jexl, transitions01;
    private SCXMLExecutor exec;

    /**
     * Set up instance variables required by this test case.
     */
    public void setUp() {
        microwave01jsp = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/env/jsp/microwave-01.xml");
        microwave02jsp = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/env/jsp/microwave-02.xml");
        microwave01jexl = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/env/jexl/microwave-01.xml");
        microwave02jexl = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/env/jexl/microwave-02.xml");
        transitions01 = this.getClass().getClassLoader().
            getResource("org/apache/commons/scxml/transitions-01.xml");
    }

    /**
     * Tear down instance variables required by this test case.
     */
    public void tearDown() {
        microwave01jsp = microwave02jsp = microwave01jexl = microwave02jexl =
            transitions01 = null;
    }

    /**
     * Test the implementation
     */
    public void testSCXMLExecutorMicrowave01JspSample() {
        exec = SCXMLTestHelper.getExecutor(microwave01jsp,
            new SimpleContext(), new ELEvaluator());
        assertNotNull(exec);
        checkMicrowave01Sample();
    }

    public void testSCXMLExecutorMicrowave02JspSample() {
        exec = SCXMLTestHelper.getExecutor(microwave02jsp,
            new SimpleContext(), new ELEvaluator());
        assertNotNull(exec);
        checkMicrowave02Sample();
    }

    public void testSCXMLExecutorMicrowave01JexlSample() {
        exec = SCXMLTestHelper.getExecutor(microwave01jexl);
        assertNotNull(exec);
        checkMicrowave01Sample();
    }

    public void testSCXMLExecutorMicrowave02JexlSample() {
        exec = SCXMLTestHelper.getExecutor(microwave02jexl);
        assertNotNull(exec);
        checkMicrowave02Sample();
    }

    public void testSCXMLExecutorTransitions01Sample() {
        exec = SCXMLTestHelper.getExecutor(transitions01);
        assertNotNull(exec);
        try {
            Set currentStates = fireEvent("ten.done");
            assertEquals(1, currentStates.size());
            assertEquals("twenty_one", ((State)currentStates.iterator().
                next()).getId());
            currentStates = fireEvent("twenty_one.done");
            assertEquals(1, currentStates.size());
            assertEquals("twenty_two", ((State)currentStates.iterator().
                next()).getId());
            currentStates = fireEvent("twenty_two.done");
            assertEquals(3, exec.getCurrentStatus().getStates().size());
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    private Set fireEvent(String name) {
        TriggerEvent[] evts = {new TriggerEvent(name,
                TriggerEvent.SIGNAL_EVENT, null)};
        try {
            exec.triggerEvents(evts);
        } catch (Exception e) {
            fail(e.getMessage());
        }
        return exec.getCurrentStatus().getStates();
    }

    private void checkMicrowave01Sample() {
        try {
            Set currentStates = fireEvent("turn_on");
            assertEquals(1, currentStates.size());
            assertEquals("cooking", ((State)currentStates.iterator().
                next()).getId());
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    private void checkMicrowave02Sample() {
        try {
            Set currentStates = fireEvent("turn_on");
            assertEquals(2, currentStates.size());
            String id = ((State)currentStates.iterator().next()).getId();
            assertTrue(id.equals("closed") || id.equals("cooking"));
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    public static void main(String args[]) {
        TestRunner.run(suite());
    }
}

{'fraction_non_alphanumeric': 0.11008186126669539, 'fraction_numerical': 0.014218009478672985, 'mean_word_length': 2.645465253239105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4554019', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2484, 'n_words': 589}