package org.jboss.test.webservice.exception;
import junit.framework.Test;
import org.jboss.test.webservice.WebserviceTestBase;
import javax.naming.InitialContext;
public class ExceptionTestCase extends WebserviceTestBase
{
public ExceptionTestCase(String name)
{
super(name);
}
public static Test suite() throws Exception
{
return getDeploySetup(ExceptionTestCase.class, "ws4ee-exception.jar, ws4ee-exception-client.jar");
}
public void testException() throws Exception
{
InitialContext iniCtx = getClientContext();
ExceptionService service = (ExceptionService)iniCtx.lookup("java:comp/env/service/ExceptionService");
ExceptionServiceInterface port = service.getPort();
try
{
port.throwException();
fail("Should have failed with UserException");
}
catch (UserException usrex)
{
}
catch (Exception e)
{
fail("Unexpected Exception: " + e);
}
}
public void testExceptionWithMessage() throws Exception
{
InitialContext iniCtx = getClientContext();
ExceptionService service = (ExceptionService)iniCtx.lookup("java:comp/env/service/ExceptionService");
ExceptionServiceInterface port = service.getPort();
String message = "Don't worry it's just a test";
try
{
port.throwExceptionWithMessage(message);
fail("Should have failed with UserException");
}
catch (UserMessageException usrex)
{
assertEquals(message, usrex.getMessage());
}
catch (Exception e)
{
fail("Unexpected Exception: " + e);
}
}
public void testComplexUserException() throws Exception
{
InitialContext iniCtx = getClientContext();
ExceptionService service = (ExceptionService)iniCtx.lookup("java:comp/env/service/ExceptionService");
ExceptionServiceInterface port = service.getPort();
String message = "Don't worry it's just a test";
try
{
port.throwComplexUserException(message, 200);
fail("Should have failed with UserException");
}
catch (ComplexUserException usrex)
{
assertEquals(message, usrex.getMessage());
assertEquals(200, usrex.getErrorCode());
}
catch (Exception e)
{
fail("Unexpected Exception: " + e);
}
}
}