A simple call like #{authenticationList.resultList} will cause a ConcurrentAccessException in TestNG tests while it works perfectly in the runtime environment.
Here is how it can be reproduced:
@Name("authenticationList")
@Stateful
public class AuthenticationListBean extends EntityQuery<Authentication>
implements AuthenticationList {
private static final long serialVersionUID = 3302243104496804256L;
private static final String EJBQL = "select authentication "
+ "from Authentication authentication inner join fetch "
+ "authentication.user";
private static final String[] RESTRICTIONS =
{ "authentication.user.userId = #{authenticationList.userId}" };
private Long userId;
public AuthenticationListBean() {
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(15);
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getUserId() {
return userId;
}
@Remove
@Destroy
public void destroy() {
}
}Here is a simple TestNG test:
@Test
public void failingTest() throws Exception {
long countBefore;
new FacesRequest("/user/authenticationList.xhtml") {
@Override
protected void invokeApplication() throws Exception {
countBefore =
(Long) getValue("#{authenticationList.resultCount}");
}
}.run();
}
If I remove the restriction from the SFSB, everything works like a charm in the test. Here is the replacing line :
private static final String[] RESTRICTIONS = {};
It would be very handy to be able to test EntityQuery objects in TestNG. I know that it works if I transform my object into a pojo. But we have decided to use EJBs.
Thanks for any comments
Sylvain