Invoking Interceptors through StrutsSpringTestCase in Struts2 + Spring project

The requirement of Test case through StrutsSpringTestCase is: If i call any method of Action class then the interceptors, Validate, prep and prepare methods should be called automatically.

In real scenario only the method, which i am calling through proxy object, is called. I have added code snippet below.

import org.apache.struts2.StrutsSpringTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.opensymphony.xwork2.ActionProxy;

@ContextConfiguration(locations = { "classpath:test-applicationContext.xml", "classpath*:applicationContext.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class TestMyProfilePage extends StrutsSpringTestCase
{
    @Test
    public void testExecute() throws Exception
    {
        ActionProxy proxy = getActionProxy("/secure/profile_process.action");
        ProfileAction profileProxy = (ProfileAction) proxy.getAction();
        profileProxy.setAppointmentDateCode("09/27/2011:D:8AM-12PM");

        String result = profileProxy.execute();
        assertEquals(result, "success");
    }
}

Please help me out.

Answers


I have got the solution. Actually i was calling the method after typecasting proxy object into my action class object. But if i call it directly through proxy object then it calls all interceptor for given uri("/secure/profile_process.action") and even prep methods of my action class.

Code snippet is below.

 @Test
    public void testExecute() throws Exception
    {
        ActionProxy proxy = getActionProxy("/secure/profile_process.action");
        ProfileAction profileProxy = (ProfileAction) proxy.getAction();
        profileProxy.setAppointmentDateCode("09/27/2011:D:8AM-12PM");

        String result = proxy.execute();
        assertEquals(result, "success");
    }

Cheers..Thank you


Need Your Help

Upload Image in asp.net webapi using WebImage Class

asp.net asp.net-mvc asp.net-mvc-4 asp.net-web-api asp.net-web-api2

I want to upload an Image for my webapi project and i am using WebImage class in Asp.net MVC 4 for Saving, cropping, rotating image by using this class.

Asp.net XML to objects

c# asp.net

I have a XML file, with a structure like