Package com.github.ebnew.ki4so.core.exception

Examples of com.github.ebnew.ki4so.core.exception.InvalidCredentialException


    //测试认证失败的情况。
    Credential credential = Mockito.mock(Credential.class);
    //当调用认证方法则抛出异常信息。模拟测试数据。
    AuthenticationManager authenticationManager = Mockito.mock(AuthenticationManager.class);
    this.ki4soService.setAuthenticationManager(authenticationManager);
    InvalidCredentialException exception = Mockito.mock(InvalidCredentialException.class);
    String code = "message code";
    String msgKey ="message key";
    Mockito.when(exception.getCode()).thenReturn(code);
    Mockito.when(exception.getMsgKey()).thenReturn(msgKey);
    Mockito.when(authenticationManager.authenticate(credential)).thenThrow(exception);
    LoginResult loginResult = ki4soService.login(credential);
    LoginResult expected = new LoginResult();
    expected.setSuccess(false);
    expected.setCode(code);
    expected.setMsgKey(msgKey);
    //比较结果。
    this.assertLoginResult(expected, loginResult);
   
    //测试认证成功。
    credential = Mockito.mock(Credential.class);
    //当调用认证方法则抛出异常信息。模拟测试数据。
    authenticationManager = Mockito.mock(AuthenticationManager.class);
    this.ki4soService.setAuthenticationManager(authenticationManager);
   
   
    Authentication authentication = Mockito.mock(Authentication.class);
    Mockito.when(exception.getCode()).thenReturn(msgKey);
    Mockito.when(exception.getCode()).thenReturn(code);
    Mockito.when(authenticationManager.authenticate(credential)).thenReturn(authentication);
    loginResult = ki4soService.login(credential);
    expected = new LoginResult();
    expected.setSuccess(true);
    expected.setAuthentication(authentication);
View Full Code Here

TOP

Related Classes of com.github.ebnew.ki4so.core.exception.InvalidCredentialException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.