tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quintin Beukes <quin...@last.za.net>
Subject Problem with Testing OpenEJB Security - Examples
Date Tue, 08 Sep 2009 15:02:39 GMT
Hey,

I am trying to make unit tests for my security. So I try implementing
the example in my code, but it's not working.

I worked from the first example, as it seems more robust/legible for
testing different security scenarios. Problem is that the static
classes aren't being loaded as EJBs by OpenEJB.

I attached my context properties, unit test code, and the log output.
What's wrong here? I am sure I didn't miss anything in the example.

Here is my IC properties:
java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory
testPool.UserName=kms
testPool=new://Resource?type=DataSource
testPool.Password=kms
testPool.JdbcUrl=jdbc:postgresql://localhost:5432/test_kms
testPool.JdbcDriver=org.postgresql.Driver

Here is my code:
public class TestBeanTest
{
  private static LocalTestFramework framework;

  @BeforeClass
  public static void setUpClass() throws Exception
  {
    framework = new LocalTestFramework(TestBeanTest.class);
  }

  /**
   * Test of openMethod method, of class TestBean.
   */
  @Test
  public void testAsStandardUser() throws Exception
  {
    Caller bean = framework.lookupEJB(Caller.class, "StandardUserBeanLocal");
    bean.call(new Callable() {
      public Object call() throws Exception
      {
        return null;
      }
    });
  }

  /**
   * Test of openMethod method, of class TestBean.
   */
  @Test
  public void testAsAdmin() throws Exception
  {
    Caller bean = framework.lookupEJB(Caller.class, "AdminBeanLocal");
    bean.call(new Callable() {
      public Object call() throws Exception
      {
        return null;
      }
    });
  }

  /**
   * Security EJBs interface
   */
  @Local
  public static interface Caller
  {
    public <T> T call(Callable<T> callable) throws Exception;
  }

  @Stateless
  @RunAs("Admin")
  public static class AdminBean implements Caller
  {
    public <T> T call(Callable<T> callable) throws Exception
    {
      return callable.call();
    }
  }

  @Stateless
  @RunAs("Standard User")
  public static class StandardUserBean implements Caller
  {
    public <T> T call(Callable<T> callable) throws Exception
    {
      return callable.call();
    }
  }
}

And finally my log output:
Apache OpenEJB 3.0    build: 20080408-04:13
http://openejb.apache.org/
INFO - openejb.home = /home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb
INFO - openejb.base = /home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb
INFO - Configuring Service(id=Default Security Service,
type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager,
type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=testPool, type=Resource,
provider-id=Default JDBC Database)
INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory,
type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
INFO - Found EjbModule in classpath:
/home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb/build/jar
INFO - Configuring app:
/home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb/build/jar
INFO - Configuring Service(id=Default Stateless Container,
type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean PersonnelBean:
Container(type=STATELESS, id=Default Stateless Container)
INFO - Configuring PersistenceUnit(name=KMSPlatform-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Auto-creating a Resource with id 'testPoolNonJta' of type
'DataSource for 'KMSPlatform-PU'.
INFO - Configuring Service(id=testPoolNonJta, type=Resource,
provider-id=testPool)
INFO - Adjusting KMSPlatform-PU <non-jta-data-source> to 'testPoolNonJta'
INFO - Loaded Module:
/home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb/build/jar
INFO - Assembling app:
/home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb/build/jar
INFO - PersistenceUnit(name=KMSPlatform-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Jndi(name=PersonnelBeanLocal) --> Ejb(deployment-id=PersonnelBean)
INFO - Jndi(name=PersonnelBeanRemote) --> Ejb(deployment-id=PersonnelBean)
INFO - Jndi(name=TestBeanLocal) --> Ejb(deployment-id=TestBean)
INFO - Jndi(name=TestBeanRemote) --> Ejb(deployment-id=TestBean)
INFO - Jndi(name=SiteBeanLocal) --> Ejb(deployment-id=SiteBean)
INFO - Jndi(name=SiteBeanRemote) --> Ejb(deployment-id=SiteBean)
INFO - Jndi(name=SpringContextBeanLocal) -->
Ejb(deployment-id=SpringContextBean)
INFO - Created Ejb(deployment-id=PersonnelBean,
ejb-name=PersonnelBean, container=Default Stateless Container)
INFO - Created Ejb(deployment-id=TestBean, ejb-name=TestBean,
container=Default Stateless Container)
INFO - Created Ejb(deployment-id=SiteBean, ejb-name=SiteBean,
container=Default Stateless Container)
INFO - Created Ejb(deployment-id=SpringContextBean,
ejb-name=SpringContextBean, container=Default Stateless Container)
INFO - Deployed
Application(path=/home/quintin/dev/kms/KMSPlatform/KMSPlatform-ejb/build/jar)
------------- ---------------- ---------------
------------- Standard Error -----------------
log4j:WARN No appenders could be found for logger
(org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
------------- ---------------- ---------------
Testcase: testAsStandardUser(net.kunye.test.TestBeanTest):
Caused an ERROR
Failed to lookup bean 'StandardUserBeanLocalLocal'
(net.kunye.test.TestBeanTest$Caller)
java.lang.RuntimeException: Failed to lookup bean
'StandardUserBeanLocalLocal' (net.kunye.test.TestBeanTest$Caller)
        at net.kunye.platform.appclient.test.LocalTestFramework.lookupEJB(LocalTestFramework.java:92)
        at net.kunye.test.TestBeanTest.testAsStandardUser(TestBeanTest.java:75)


-- 
Quintin Beukes

Mime
View raw message