Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6643167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:01:06+00:00 2026-05-26T00:01:06+00:00

I have managed to get alternate descriptors to work with my unit-tests running on

  • 0

I have managed to get alternate descriptors to work with my unit-tests running on OpenEJB using stubs for dependant EJB components, when each test is executed on their own. But once I introduce a test suite, it seems that deployment descriptor is taken from the first test added to the suite.

Some code to explain it better. Beans under test are something like

@Stateless
@Local(A.class)
public class ABean implements A {
     // Bean implementation, no dependencies
}


@Stateless
@Local(B.class)
public class BBean implements B {

     @EJB
     A aBean;  // Dependency to ABean

     // Rest of the implementation
}

And testcase for B (testcase for A is similar, except it does not set the property for using alternate descriptor)

public class BBeanTest {
    private B bean;

    @Before
    public void bootContainer() throws Exception {
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY,
               "org.apache.openejb.client.LocalInitialContextFactory");
        props.put("openejb.altdd.prefix", "test");  // Use stubs

        System.out.println("boot B: " + props);

        context = new InitialContext(props);
        bean = (B) context.lookup("BBeanLocal");
    } 
}

And as said, this all works just fine when executed alone. The alternate descriptor injects a stub implementation of A interface.

When using the following test suite, things start to fall apart.

 @RunWith(Suite.class)
 @Suite.SuiteClasses({
   ABeanTest.class, 
   BBeanTest.class
 })
 public class MySuite {
      // Empty on purpose, annotations do the trick
 }

When running this suite, the alternate descriptor for testing B is not taken into use. Although, the output shows that at least the property is set before each test

 boot A: {java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory}
 boot A: {java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory}
 boot A: {java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory}
 boot B: {java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory, openejb.altdd.prefix=test}
 boot B: {java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory, openejb.altdd.prefix=test}

If I reverse the order of loading tests to suite, i.e. add BBeanTest.class before ABeanTest.class, it’ll use the alternate descriptor. As the ABean has no dependencies, this’ll work fine in this case, but probably causes problems with bigger setups with multiple alternate descriptors.

Any pointers?

Thanks in advance.

EDIT Based on the log output, the container is actually booted only once for the first test as it takes approx. 2,5 seconds to execute while the others take around 0,001 seconds.

EDIT2 OpenEJB version is Apache OpenEJB 3.1.4 build: 20101112-03:32

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:01:07+00:00Added an answer on May 26, 2026 at 12:01 am

    Based on the log output, the container is actually booted only once for the first test as it takes approx. 2,5 seconds to execute while the others take around 0,001 seconds.

    As you rightly noticed, the initialization happens only once.

    
    @RunWith(Suite.class)
     @Suite.SuiteClasses({
       ABeanTest.class, 
       BBeanTest.class
     })
    

    Hence in this case, both ABeanTest and BBeanTest ran within the same container instance, with the same initial context properties as set by ABeanTest.

    In your case, since you need different settings for the two test classes, I think dumping the container instance at ABeanTest @AfterClass and using a new one in BBeanTest should do it.

    This blog post shows how

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning basics of EJB 3.0. I have managed to get a sample
I'm writing a MVC website and using jqGrid. I have managed to get it
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have managed to get a custom very basic extension running in Firefox. What
I have managed to get a cron job to run a rake task by
Ok so I have managed to get the format of the date presented in
So far I have managed to get the background image to stretch: XHTML: <div
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I have finally managed to get javan-whenever gem working on my site5 server, and
I have somehow managed to get a really screwed up Eclipse project. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.