My JEE 6 Application is using CDI, as well as Arquillian with an embedded tomee (1.7.2) to test it. In a test-class with multiple test methods, the same Request Scoped Bean instance is being injected in multiple test methods. The problem is not occuring when the application is deployed on a stand-alone tomee plus 1.7.2.
According to the arquillian documentation a request scoped bean instance should only be used for one testmethod. Unfortunately tomee embedded itself it not mentioned in the Arquillian documentation. Is this a known limitation to tomee embedded? If not, how to fix it?
The Service Class:
@RequestScoped
public class SomeService
{
private String user;
public String execute(final String pNewUser)
{
if(user == null){
user = pNewUser;
}
return user;
}
}
The Test-Class:
@RunWith(Arquillian.class)
public class TestCase
{
@Inject
private SomeService someService;
@Deployment
public static WebArchive createDeployment()
{
return DefaultMicroDeploymenCreator.createDefaultMicroDeplymentWithFileName("TestCase.war");
}
@Test
public void testFirstTestMethod() throws Exception
{
String username = someService.execute("User A");
Assert.assertEquals(username, "User A");
}
@Test
public void testSecondTestMethod() throws Exception
{
String username = someService.execute("User B");
Assert.assertEquals(username, "User B");
}
}
The first test executed is success, the second one is failing.