Note that there are some explanatory texts on larger screens.

plurals
  1. POarquillian - how to get persistent session scoped beans across tests
    primarykey
    data
    text
    <p>Have been struggling with a test case where a service is dependent on having a session scoped bean being in the session fails;</p> <p>The class producing @SessionScoped User:</p> <pre><code>public class LoginService { private User user; public void login(String name) { if ("userA".equals(name)) { user = new User(name, "permissionA"); } else if ("userB".equals(name)) { user = new User(name, "permissionB"); } else { user = new User("anonymous", ""); } } @Produces @LoggedIn @SessionScoped public User getLoggedIn() { return this.user; } } </code></pre> <p>The service using the @LoggedIn User:</p> <pre><code>public class MediaService { @Inject @LoggedIn private User user; public void updateImage(){ if("permissionA".equals(user.getPermission())) { System.out.println("user can update image"); } else { System.out.println("user can not update image"); } } } </code></pre> <p>And the test:</p> <pre><code>@RunWith(Arquillian.class) public class ServiceTest { @Deployment public static WebArchive deployment() { return ShrinkWrap .create(WebArchive.class, "test.war") .addClass(LoggedIn.class) .addClass(LoginService.class) .addClass(MediaService.class) .addClass(User.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @Inject private LoginService lservice; @Inject private MediaService mservice; @Test public void testLogin() { lservice.login("userA"); } @Test public void testUpdateImage(){ mservice.updateImage(); } } </code></pre> <p>Testing with the arquillian remote container, first test (testLogin) passes and the testUpdateImage fails with null User in session.</p> <pre><code>WELD-000052 Cannot return null from a non-dependent producer method: [method] @Produces @LoggedIn @SessionScoped public org.arg.service.LoginService.getLoggedIn() </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload