[seam-issues] [JBoss JIRA] Moved: (SEAMSECURITY-1) org.jboss.seam.security.Identity needs to be decoupled from system for testing purposes

Shane Bryzak (JIRA) jira-events at lists.jboss.org
Tue Apr 13 05:33:06 EDT 2010


     [ https://jira.jboss.org/jira/browse/SEAMSECURITY-1?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Shane Bryzak moved JBSEAM-3918 to SEAMSECURITY-1:
-------------------------------------------------

              Project: Seam Security  (was: Seam)
                  Key: SEAMSECURITY-1  (was: JBSEAM-3918)
          Component/s:     (was: Security)
    Affects Version/s:     (was: 2.1.1.GA)


> org.jboss.seam.security.Identity needs to be decoupled from system for testing purposes
> ---------------------------------------------------------------------------------------
>
>                 Key: SEAMSECURITY-1
>                 URL: https://jira.jboss.org/jira/browse/SEAMSECURITY-1
>             Project: Seam Security
>          Issue Type: Feature Request
>         Environment: JBoss Seam 2.1.1.GA 
>            Reporter: Dan Hinojosa
>            Assignee: Shane Bryzak
>
> org.jboss.seam.security.Identity cannot be used in unit testing.  Unit testing being defined as an isolated (no db, no app server) test.  If I provide an identity into a test, once I call assertTrue(identity.hasRole("xxx"));  I get an understandable NullPointerException because there is no Seam Context available. 
>  If I may recommend that org.jboss.seam.security.Identity be either an interface or a POJO with no dependencies as an API so TDD advocates can test their code easily.  This would also fulfill Seam's idea that everything for the end user is testable.
> Example Test
> @Test(groups = "unit")
>     public void testAuthenticateSuccessWithRoles() {
>         Log log = createMock(Log.class);
>         EntityManager entityManager = createMock(EntityManager.class);
>         Query query = createMock(Query.class);
>         Calendar createdDate = Calendar.getInstance();
>         Calendar updatedDate = Calendar.getInstance();
>         User user = new User();
>         user.setCreatedDate(createdDate);
>         user.setEmail("ricardo at aol.com");
>         user.setFirstName("Ricardo");
>         user.setLastName("Montalban");
>         user.setName("rmontalban");
>         user.setNotes("userNotes2");
>         user.setPassword("passw0rd");
>         user.setId(220L);
>         user.setUpdatedDate(updatedDate);
>         Role role = new Role();
>         role.setName("mgmt");
>         role.setId(665L);
>         Calendar createdDate2 = Calendar.getInstance();
>         createdDate2.set(2009, 1, 15, 12, 14, 15);
>         role.setCreatedDate(createdDate2);
>         Calendar updatedDate2 = Calendar.getInstance();
>         updatedDate2.set(2009, 1, 17, 13, 16, 20);
>         role.setUpdatedDate(updatedDate2);
>         role.setNotes("notes");
>         user.addRole(role);
>         role.addUser(user);
>         Credentials credentials = new Credentials();
>         credentials.setUsername("rmontalban");
>         credentials.setPassword("passw0rd");
>         Identity identity = new Identity();
>         log.info("authenticating #0", "rmontalban");
>         expect(entityManager.createQuery("SELECT u from User u " +
>                 "WHERE u.name = #{credentials.username} AND u.password = #{credentials.password}")).andReturn(query);
>         expect(query.getSingleResult()).andReturn(user);
>         replay(entityManager, query, log);
>         Authenticator authenticator = new Authenticator();
>         authenticator.setLog(log);
>         authenticator.setIdentity(identity);
>         authenticator.setEntityManager(entityManager);
>         authenticator.setCredentials(credentials);
>         assertTrue(authenticator.authenticate());
>         assertTrue(identity.hasRole("mgmt"));  //NullPointerException here
>         verify(entityManager, query, log);
>     }
> Output from the above test:
> java.lang.NullPointerException
> 	at org.jboss.seam.security.Identity.tryLogin(Identity.java:164)
> 	at org.jboss.seam.security.Identity.hasRole(Identity.java:444)
> 	at com.manning.mymanning.AuthenticatorTest.testAuthenticateSuccessWithRoles(AuthenticatorTest.java:128)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the seam-issues mailing list