You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Josh <ge...@gmail.com> on 2007/03/22 12:25:27 UTC

How to Unit test an axis service that extends Springs ServletEndpointSupport?

Hello,

I am trying to figure out how to write a JUnit test case that can test my
service endpoint outside of the servlet container. My axis service endpoint
extends springs ServletEndpointSupport but I cannot seem to find any mock
objects that will help me initialize this object correctly.

To initialize the servlet, I need to call the init method from the
ServiceLifecycle Interface:

init(Object context)

Trouble is, the context here is of the type
javax.xml.rpc.server.ServletEndpointContext. As I mentioned earlier, I have
been unable to find any Mock objects for this class. Can someone point me to
an example?

Regards,

Josh

Re: How to Unit test an axis service that extends Springs ServletEndpointSupport?

Posted by robert lazarski <ro...@gmail.com>.
You are talking about axis 1.x right and
javax.xml.rpc.server.ServiceLifecycle ? If so I can't help too much
since I'm pretty much axis2 only these days. What I can say is that it
is pretty common to do Spring unit tests by creating your own object
factory:

protected static void createBeanFactory() {
        ResourceBundle objFactoryBundle = ResourceBundle.
            getBundle("objectFactory");
        String path = objFactoryBundle.getString("paths");
        String[] paths = path.split(" ");
        ClassPathXmlApplicationContext appContext =
            new ClassPathXmlApplicationContext(paths);
        factory = (BeanFactory) appContext;

    }

Then you get your beans like so:

public static Object getObject(String name) {
        if (factory == null) {
            createBeanFactory();
        }
        Object bean = null;
        try {
            bean = factory.getBean(name);
        } catch (Exception e) {
            log.fatal("can't create bean: " + name, e);
            new IllegalParameterException(IllegalParameterException
                    .APPLICATION_RESOURCE_ERROR_INTERNAL, null, e);
        }
        return bean;
    }

So the unit tests don't actually configure the beans via a servlet.

HTH,
Robert

On 3/22/07, Josh <ge...@gmail.com> wrote:
> Hello,
>
> I am trying to figure out how to write a JUnit test case that can test my
> service endpoint outside of the servlet container. My axis service endpoint
> extends springs ServletEndpointSupport but I cannot seem to find any mock
> objects that will help me initialize this object correctly.
>
> To initialize the servlet, I need to call the init method from the
> ServiceLifecycle Interface:
>
> init(Object context)
>
> Trouble is, the context here is of the type
> javax.xml.rpc.server.ServletEndpointContext . As I
> mentioned earlier, I have been unable to find any Mock objects for this
> class. Can someone point me to an example?
>
> Regards,
>
> Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org