Nullpointer exception in embedded JBoss unit test when I use
webmarck May 30, 2006 10:55 AMEnvironment:
JBoss embedded Alpha 7
Java 1.5.0_06
Eclipse 3.1.2
JUnit 4.0 (but writing old school test since Maven doesn?t understand annotations tests)
The Case
I have written a unit test that behaves ?funny? because it correctly throws a EJBAccessException: Authentication failure when I use a wrong password or unknown user ? but throws a NullPointerException when I use the correct user/password.
Is this a known problem or have I done an environment setup error? All help is more then welcome.
Details:
The exception
javax.ejb.EJBException: java.lang.NullPointerException
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
The test class (ripe)
public class MpSupportBeanTest extends TestCase {
protected void setUp () {
EJB3StandaloneBootstrap.boot(null);
EJB3StandaloneBootstrap.deployXmlResource("security-beans.xml");
EJB3StandaloneBootstrap.scanClasspath();
}
public static InitialContext getInitialContext() throws Exception {
Hashtable props = getInitialContextProperties();
return new InitialContext(props);
}
private static Properties getInitialContextProperties() {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.security.jndi.JndiLoginInitialContextFactory");
props.setProperty(Context.SECURITY_PRINCIPAL, "firstuser");
props.setProperty(Context.SECURITY_CREDENTIALS, "validpassword");
return props;
}
public void testGetSubscriberDetails() throws Exception {
InitialContext ctx = getInitialContext();
MpSupport support = (MpSupportLocal) ctx.lookup("MpSupport/locale");
Subscriber s = support.getSubscriberDetails();
assertNotNull(s);
}
}The session bean (ripe)
@Stateless
@SecurityDomain("other")
public class MpSupportBean implements MpSupport{
@RolesAllowed("subsciber")
public Subscriber getSubscriberDetails() {
}Besides that I have copied default.persistence.properties
ejb3-interceptors-aop.xml
embedded-jboss-beans.xml
jboss-jms-beans.xml
log4j.xml
login-config.xml
roles.properties
security-beans.xml
users.properties
and modifed the user and roles files so they contain a subscriber role and a firstuser with password validpassword