alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (AnotherActionComponentTest.java)

This example Struts source code file (AnotherActionComponentTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

abstracttagtest, actioncomponent, actioncomponent, anotheractioncomponenttest, anotheractioncomponenttest, exception, exception, strutsexception, strutsexception

The Struts AnotherActionComponentTest.java source code

package org.apache.struts2.components;

import org.apache.struts2.views.jsp.AbstractTagTest;
import org.apache.struts2.TestConfigurationProvider;
import org.apache.struts2.StrutsException;

/**
 * Describe your class here
 *
 * @author $Author$
 *         <p/>
 *         $Id$
 */
public class AnotherActionComponentTest extends AbstractTagTest  {

    public void testRethrowException() throws Exception {
        request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/"
                + "foo.action" );
        ActionComponent ac = new ActionComponent(stack, request, response) ;
        container.inject(ac);
        ac.setNamespace(TestConfigurationProvider.TEST_NAMESPACE);
        ac.setName(TestConfigurationProvider.TEST_ACTION_NAME + "!executeThrowsException");
        ac.setRethrowException(true);
        boolean exceptionCaught = false;
        try {
            ac.executeAction();
        }
        catch (Exception e) {
            if (e instanceof StrutsException)
                exceptionCaught = true;
        }
        assertTrue(exceptionCaught);
    }

    public void testDoesNotThrowException() throws Exception {
        request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/"
                + "foo.action" );
        ActionComponent ac = new ActionComponent(stack, request, response) ;
        container.inject(ac);
        ac.setNamespace(TestConfigurationProvider.TEST_NAMESPACE);
        ac.setName(TestConfigurationProvider.TEST_ACTION_NAME+ "!executeThrowsException");
        ac.setRethrowException(false);
        boolean exceptionCaught = false;
        try {
            ac.executeAction();
        }
        catch (Exception e) {
            if (e instanceof StrutsException)
                exceptionCaught = true;
        }
        assertTrue(! exceptionCaught);    
    }
}

Other Struts examples (source code examples)

Here is a short list of links related to this Struts AnotherActionComponentTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.