<commit_before>/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package com.opensymphony.workflow;

import junit.framework.TestCase;

import java.net.URL;

import java.util.HashMap;


/**
 * @author <NAME> (<EMAIL>)
 * Date: May 10, 2003
 * Time: 1:58:48 PM
 */
public class ExceptionTestCase extends TestCase {
    //~ Constructors ///////////////////////////////////////////////////////////

    public ExceptionTestCase(String s) {
        super(s);
    }

    //~ Methods ////////////////////////////////////////////////////////////////

    public void testFactoryException() {
        TestWorkflow.configFile = "/osworkflow-badfactory.xml";

        //we expect an InternalWorkflowException (can't throw a checked exception in constructor, otherwise the ejb provider
        //will break spec by having a constructor
        try {
            TestWorkflow workflow = new TestWorkflow("testuser");
            fail("bad factory did not throw an error");
        } catch (InternalWorkflowException ex) {
            assertTrue("Expected FactoryException, but instead got " + ex.getRootCause(), ex.getRootCause() instanceof FactoryException);
        }
    }

    public void testStoreException() throws Exception {
        TestWorkflow.configFile = "/osworkflow-jdbc.xml";

        TestWorkflow workflow = new TestWorkflow("testuser");

        //correct behaviour is to get a store exception since we can't look up the DS
        URL url = getClass().getResource("/samples/auto1.xml");
        assertNotNull("Unable to find resource /samples/auto1.xml", url);

        try {
            workflow.initialize(url.toString(), 1, new HashMap());
        } catch (StoreException e) {
            return;
        }

        fail("Expected StoreException but did not get one for a bad JDBC datasource");
    }
}<commit_msg>Added tests for invalid actions<commit_after>/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package com.opensymphony.workflow;

import junit.framework.TestCase;

import java.net.URL;

import java.util.HashMap;


/**
 * @author <NAME> (<EMAIL>)
 * Date: May 10, 2003
 * Time: 1:58:48 PM
 */
public class ExceptionTestCase extends TestCase {
    //~ Constructors ///////////////////////////////////////////////////////////

    public ExceptionTestCase(String s) {
        super(s);
    }

    //~ Methods ////////////////////////////////////////////////////////////////

    public void testFactoryException() {
        TestWorkflow.configFile = "/osworkflow-badfactory.xml";

        //we expect an InternalWorkflowException (can't throw a checked exception in constructor, otherwise the ejb provider
        //will break spec by having a constructor
        try {
            TestWorkflow workflow = new TestWorkflow("testuser");
            fail("bad factory did not throw an error");
        } catch (InternalWorkflowException ex) {
            assertTrue("Expected FactoryException, but instead got " + ex.getRootCause(), ex.getRootCause() instanceof FactoryException);
        }
    }

    public void testInitializeInvalidActionException() throws Exception {
        TestWorkflow.configFile = "/osworkflow.xml";

        TestWorkflow workflow = new TestWorkflow("testuser");
        URL url = getClass().getResource("/samples/auto1.xml");
        assertNotNull("Unable to find resource /samples/auto1.xml", url);

        try {
            workflow.initialize(url.toString(), 2, new HashMap());
        } catch (InvalidActionException e) {
            return;
        }

        fail("Expected InvalidActionException but did not get one for a bad action in initialize");
    }

    public void testInvalidActionException() throws Exception {
        TestWorkflow.configFile = "/osworkflow.xml";

        TestWorkflow workflow = new TestWorkflow("testuser");
        URL url = getClass().getResource("/samples/auto1.xml");
        assertNotNull("Unable to find resource /samples/auto1.xml", url);

        long id = workflow.initialize(url.toString(), 1, new HashMap());

        try {
            workflow.doAction(id, 10, null);
        } catch (InvalidActionException e) {
            return;
        }

        fail("Expected InvalidActionException but did not get one for a bad action");
    }

    public void testStoreException() throws Exception {
        TestWorkflow.configFile = "/osworkflow-jdbc.xml";

        TestWorkflow workflow = new TestWorkflow("testuser");

        //correct behaviour is to get a store exception since we can't look up the DS
        URL url = getClass().getResource("/samples/auto1.xml");
        assertNotNull("Unable to find resource /samples/auto1.xml", url);

        try {
            workflow.initialize(url.toString(), 1, new HashMap());
        } catch (StoreException e) {
            return;
        }

        fail("Expected StoreException but did not get one for a bad JDBC datasource");
    }
}
{'fraction_non_alphanumeric': 0.14723801787164906, 'fraction_numerical': 0.010560519902518278, 'mean_word_length': 2.246539222148978, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '6269244', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1197, 'n_words': 381}