/** Test of logon method, of class DefaultLogonService. */ @Test public void testLogon() throws Exception { System.out.println("logon"); final String password = EncryptionUtil.encryptWithPassword("pass", "pass"); LogonVO logonVO = new LogonVO("roy", "pass"); DefaultLogonService instance = new DefaultLogonService(); UserSecurityProfileVO expResult = new UserSecurityProfileVOBuilder() .setId(Long.MIN_VALUE) .setPassword(password) .createUserSecurityProfileVO(); final LoggedOnSessionProvider loggedOnSessionProviderMock = mock(LoggedOnSessionProvider.class); final LoggedOnSession loggedOnSession = mock(LoggedOnSession.class); final SessionSecurityChecker sessionSecurityChecker = mock(SessionSecurityChecker.class); instance.setLoggedOnSessionProvider(loggedOnSessionProviderMock); final SystemSecurityManagerDecorator systemSecurityManager = mock(SystemSecurityManagerDecorator.class); instance.setSystemSecurityManager(systemSecurityManager); instance.setSessionSecurityChecker(sessionSecurityChecker); when(systemSecurityManager.findSecurityProfileWithLogonIDandPassword( logonVO.getLogonID(), logonVO.getPassword())) .thenReturn(expResult); when(loggedOnSessionProviderMock.getLoggedOnSession()).thenReturn(loggedOnSession); UserSecurityProfileVO result = instance.logon(logonVO); assertEquals(expResult, result); }
@Test(expected = SecurityAuthenticationException.class) public void testFailedLogonBecauseUserIsNotFound() throws Exception { System.out.println("FailedLogonBecauseUserIsNotFound"); LogonVO logonVO = new LogonVO("roy", "passed"); DefaultLogonService instance = new DefaultLogonService(); final LoggedOnSessionProvider loggedOnSessionProviderMock = mock(LoggedOnSessionProvider.class); final LoggedOnSession loggedOnSession = mock(LoggedOnSession.class); instance.setLoggedOnSessionProvider(loggedOnSessionProviderMock); final SystemSecurityManagerDecorator systemSecurityManager = mock(SystemSecurityManagerDecorator.class); instance.setSystemSecurityManager(systemSecurityManager); when(systemSecurityManager.findSecurityProfileWithLogonIDandPassword( logonVO.getLogonID(), logonVO.getPassword())) .thenReturn(null); when(systemSecurityManager.createDefaultAdminSecurityProfile()) .thenThrow(DefaultAdminSecurityProfileAlreadyExist.class); when(loggedOnSessionProviderMock.getLoggedOnSession()).thenReturn(loggedOnSession); instance.logon(logonVO); }