Tell OpenEJB to ignore MDB

2.5k views Asked by At

I wrote an unit-test for an activity which finally puts a message into a queue. As soon as a message is put into that queue, a message driven bean starts processing. But I don't want to test MDBs in a unit test. How can I tell OpenEJB to ignore them?

I set up OpenEJB with several properties:

    p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
            "org.apache.openejb.client.LocalInitialContextFactory");
    p.setProperty("openejb.deployments.classpath.include", ".*");
    p.setProperty("openejb.localcopy", "false");

    // Messaging
    p.put("MyJmsResourceAdapter",
            "new://Resource?type=ActiveMQResourceAdapter");
    // Do not start the ActiveMQ broker
    p.put("MyJmsResourceAdapter.BrokerXmlConfig", "");
    p.put("MyJmsConnectionFactory",
            "new://Resource?type=javax.jms.ConnectionFactory");
    p.put("MyJmsConnectionFactory.ResourceAdapter", "MyJmsResourceAdapter");
    p.put("queue/MyQueue",
            "new://Resource?type=javax.jms.Queue");

I know I must set openejb.deployments.classpath.exclude, but I can't figure out the right value:

    p.setProperty("openejb.deployments.classpath.exclude", "org.example.mdb.*");

For example my class is named org.example.mdb.MyMDB.

2

There are 2 answers

1
topchef On BEST ANSWER

just my 2 cents:

  • try ".*org/example/mdb.*" or ".*org.example.mdb.*"
  • from Loading Deployments from the Classpath:

    Note by default these settings will only affect which jars OpenEJB will scan for annotated components when no descriptor is found. If you would like to use these settings to also filter out jars that do contain descriptors, set the

    openejb.deployments.classpath.filter.descriptors

    property to true. The default is false

0
David Blevins On

We don't have that feature, but it could easily be added if you wanted to do a little hacking -- new contributions and contributors are always welcome.

This class will do exactly what you want... and a few things you probably don't want :) It strips out all MDBs and JMS resource references (the good part) and it strips out all entity beans and persistence unit references (the part you probably don't want). We wrote it due to some debugging issues we were having when either ActiveMQ or OpenJPA were loaded. If you cleaned it up we'd happily take it back and support it as a feature.

There is a similar feature which strips out all web services. It is installed in the ConfigurationFactory if a specific system property is set. Should be easy to plug an "MDB & JMS" remover using a similar flag at basically that same place in ConfigurationFactory

In fact since in OpenEJB all annotation and xml meta-data is merged into one object tree (which is also a JAXB tree), you could do pretty powerful transformations of the app prior to it being actually deployed. Say for example swap out specific beans for mock versions.

One of those things I think would make an excellent feature but haven't yet had the time to work on. I.e. making some clean hook for people to mess with the tree just before we send it off for deployment. Anyone reading this is welcome to jump in and take a stab at it (yay open source!).