test_class.declarator: loginResultToView = new DefaultLoginResultToView()
test_class.modifier: private
test_class.original_string: private DefaultLoginResultToView loginResultToView = new DefaultLoginResultToView();
test_class.type: DefaultLoginResultToView
test_class.var_name: loginResultToView
test_class.file: ki4so-web/src/test/java/com/github/ebnew/ki4so/web/action/DefaultLoginResultToViewTest.java
test_class.identifier: DefaultLoginResultToViewTest
test_case.body: @Test
  	public void testLoginResultToView(){
  		
  		/**
  		 * 测试输入null的情况。
  		 */
  		Assert.assertNotNull(loginResultToView.loginResultToView(null, null, null, null));
  		/**
  		 * 测试输入null的情况。
  		 */
  		Assert.assertNotNull(loginResultToView.loginResultToView(new ModelAndView(), null, null, null));
  		
  		/**
  		 * 测试输入null的情况。
  		 */
  		Assert.assertNotNull(loginResultToView.loginResultToView(new ModelAndView(), new LoginResult(), null, null));
  		
  		/**
  		 * 测试输入null的情况。
  		 */
  		Assert.assertNotNull(loginResultToView.loginResultToView(new ModelAndView(), new LoginResult(), new MockHttpServletRequest(), null));
  		
  		
  		/**
  		 * 测试登录失败的情况。
  		 */
  		//准备测试输入数据。
  		ModelAndView mv = new ModelAndView();
  		MockHttpServletRequest request = new MockHttpServletRequest();
  		MockHttpServletResponse response = new MockHttpServletResponse();
  		LoginResult result = new LoginResult();
  		result.setSuccess(false);
  		result.setCode(InvalidCredentialException.CODE);
  		result.setMsgKey(InvalidCredentialException.MSG_KEY);
  		request.setCookies(new Cookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY, "test"));
  		ModelAndView mvResult = loginResultToView.loginResultToView(mv, result, request, response);
  		//检查输出结果。
  		Assert.assertNotNull(mvResult);
  		Assert.assertEquals(InvalidCredentialException.CODE, mvResult.getModel().get("code"));
  		Assert.assertEquals(MessageUtils.getMessage(InvalidCredentialException.MSG_KEY), mvResult.getModel().get("msg"));
  		Assert.assertEquals("test", response.getCookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY).getValue());
  		
  		
  		/**
  		 * 测试登录成功的情况，不存在service参数的情况。
  		 */
  		//准备测试输入数据。
  		mv = new ModelAndView();
  		request = new MockHttpServletRequest();
  		response = new MockHttpServletResponse();
  		result = new LoginResult();
  		request.getSession().setAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION, "service");
  		result.setSuccess(true);
  		AuthenticationImpl authentication = new AuthenticationImpl();
  		Map<String, Object> attributes = new HashMap<String, Object>();
  		authentication.setAttributes(attributes);
  		attributes.put(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY, "ki4so-sever-key");
  		result.setAuthentication(authentication);
  		mvResult = loginResultToView.loginResultToView(mv, result, request, response);
  		//检查输出结果。
  		Assert.assertNotNull(mvResult);
  		Assert.assertNull(request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION));
  		Assert.assertEquals("loginSucess", mvResult.getViewName());
  		Assert.assertEquals(authentication, mvResult.getModel().get("authentication"));
  		Assert.assertEquals("ki4so-sever-key", response.getCookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY).getValue());
  		
  		
  
  		/**
  		 * 测试登录成功的情况，结果中存在service参数，则应该跳转到该地址去。
  		 */
  		mv = new ModelAndView();
  		request = new MockHttpServletRequest();
  		response = new MockHttpServletResponse();
  		result = new LoginResult();
  		result.setSuccess(true);
  		authentication = new AuthenticationImpl();
  		attributes = new HashMap<String, Object>();
  		authentication.setAttributes(attributes);
  		attributes.put(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY, "ki4so-sever-key");
  		attributes.put(AuthenticationPostHandler.KI4SO_CLIENT_EC_KEY, "ki4so-client-key");
  		attributes.put(WebConstants.SERVICE_PARAM_NAME, "htpp://localhost:8080/space-web/hello.jsp");
  		result.setAuthentication(authentication);
  		mvResult = loginResultToView.loginResultToView(mv, result, request, response);
  		//检查输出结果。
  		Assert.assertNotNull(mvResult);
  		Assert.assertNull(request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION));
  		Assert.assertTrue(mvResult.getView() instanceof RedirectView);
  		RedirectView view = (RedirectView)mvResult.getView();
  		Assert.assertEquals("htpp://localhost:8080/space-web/hello.jsp?"+WebConstants.KI4SO_CLIENT_ENCRYPTED_CREDENTIAL_COOKIE_KEY+"=ki4so-client-key",view.getUrl());
  		Assert.assertEquals(authentication, mvResult.getModel().get("authentication"));
  		Assert.assertEquals("ki4so-sever-key", response.getCookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY).getValue());
  		
  		
  		/**
  		 * 测试登录成功的情况，结果中存在service参数，且URL地址中是带"?"的。
  		 */
  		mv = new ModelAndView();
  		request = new MockHttpServletRequest();
  		response = new MockHttpServletResponse();
  		result = new LoginResult();
  		result.setSuccess(true);
  		authentication = new AuthenticationImpl();
  		attributes = new HashMap<String, Object>();
  		authentication.setAttributes(attributes);
  		attributes.put(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY, "ki4so-sever-key");
  		attributes.put(AuthenticationPostHandler.KI4SO_CLIENT_EC_KEY, "ki4so-client-key");
  		attributes.put(WebConstants.SERVICE_PARAM_NAME, "htpp://localhost:8080/space-web/hello.jsp?hello=word");
  		result.setAuthentication(authentication);
  		mvResult = loginResultToView.loginResultToView(mv, result, request, response);
  		//检查输出结果。
  		Assert.assertNotNull(mvResult);
  		Assert.assertNull(request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION));
  		Assert.assertTrue(mvResult.getView() instanceof RedirectView);
  		view = (RedirectView)mvResult.getView();
  		Assert.assertEquals("htpp://localhost:8080/space-web/hello.jsp?hello=word&"+WebConstants.KI4SO_CLIENT_ENCRYPTED_CREDENTIAL_COOKIE_KEY+"=ki4so-client-key",view.getUrl());
  		Assert.assertEquals(authentication, mvResult.getModel().get("authentication"));
  		Assert.assertEquals("ki4so-sever-key", response.getCookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY).getValue());
  	}
test_case.class_method_signature: DefaultLoginResultToViewTest.testLoginResultToView()
test_case.full_signature: @Test public void testLoginResultToView()
test_case.identifier: testLoginResultToView
test_case.invocations: assertNotNull loginResultToView assertNotNull loginResultToView assertNotNull loginResultToView assertNotNull loginResultToView setSuccess setCode setMsgKey setCookies loginResultToView assertNotNull assertEquals get getModel assertEquals getMessage get getModel assertEquals getValue getCookie setAttribute getSession setSuccess setAttributes put setAuthentication loginResultToView assertNotNull assertNull getAttribute getSession assertEquals getViewName assertEquals get getModel assertEquals getValue getCookie setSuccess setAttributes put put put setAuthentication loginResultToView assertNotNull assertNull getAttribute getSession assertTrue getView getView assertEquals getUrl assertEquals get getModel assertEquals getValue getCookie setSuccess setAttributes put put put setAuthentication loginResultToView assertNotNull assertNull getAttribute getSession assertTrue getView getView assertEquals getUrl assertEquals get getModel assertEquals getValue getCookie
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testLoginResultToView()
focal_class.file: ki4so-web/src/main/java/com/github/ebnew/ki4so/web/action/DefaultLoginResultToView.java
focal_class.identifier: DefaultLoginResultToView
focal_class.interfaces: implements LoginResultToView
focal_class.class_method_signature: DefaultLoginResultToView.loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_class.full_signature: @Override public ModelAndView loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_class.identifier: loginResultToView
focal_class.modifiers: @Override public
focal_class.parameters: (ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_class.return: ModelAndView
focal_class.signature: ModelAndView loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_class.class_method_signature: DefaultLoginResultToView.buildRedirectView(String service,
  			String encryCredential)
focal_class.full_signature: private RedirectView buildRedirectView(String service,
  			String encryCredential)
focal_class.identifier: buildRedirectView
focal_class.modifiers: private
focal_class.parameters: (String service,
  			String encryCredential)
focal_class.return: RedirectView
focal_class.signature: RedirectView buildRedirectView(String service,
  			String encryCredential)
focal_method.body: @Override
  	public ModelAndView loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response) {
  		// 若登录成功，则返回成功页面。
  		if(mv==null){
  			mv = new ModelAndView();
  		}
  		if(result==null || request==null || response==null){
  			return mv;
  		}
  		if (result.isSuccess()) {
  			//登录结果对象。
  			Authentication authentication = result.getAuthentication();
  
  			//清除session中的状态信息service值。
  			request.getSession().removeAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION);
  			
  			// 如果有加密凭据信息，则写入加密凭据值到cookie中。
  			if (authentication != null
  					&& authentication.getAttributes() != null) {
  				Map<String, Object> attributes = authentication.getAttributes();
  				// ki4so服务端加密的凭据存在，则写入cookie中。
  				if (attributes
  						.get(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY) != null) {
  					response.addCookie(new Cookie(
  							WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY,
  							attributes
  									.get(AuthenticationPostHandler.KI4SO_SERVER_EC_KEY)
  									.toString()));
  				}
  				// ki4so客户端加密的凭据和参数service存在，则跳转到对应的页面中。
  				if (attributes
  						.get(AuthenticationPostHandler.KI4SO_CLIENT_EC_KEY) != null
  						&& !StringUtils.isEmpty(attributes.get(WebConstants.SERVICE_PARAM_NAME))) {
  					mv.getModel().put("authentication", authentication);
  					mv.setView(this
  							.buildRedirectView(
  									attributes.get(WebConstants.SERVICE_PARAM_NAME).toString(),
  									attributes
  											.get(AuthenticationPostHandler.KI4SO_CLIENT_EC_KEY)
  											.toString()));
  					return mv;
  				}
  			}
  			mv.getModel().put("authentication", authentication);
  			mv.setViewName("loginSucess");
  		} else {
  			//删除以前不合法的凭据信息。
  			//清除cookie值。
  			Cookie[] cookies = request.getCookies();
  			if(cookies!=null && cookies.length>0){
  				for(Cookie cookie:cookies){
  					if(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY.equals(cookie.getName())){
  						//设置过期时间为立即。
  						cookie.setMaxAge(0);
  						response.addCookie(cookie);
  					}
  				}
  			}
  			mv.getModel().put("code", result.getCode());
  			mv.getModel().put("msg",
  					MessageUtils.getMessage(result.getMsgKey()));
  		}
  		return mv;
  	}
focal_method.class_method_signature: DefaultLoginResultToView.loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_method.full_signature: @Override public ModelAndView loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_method.identifier: loginResultToView
focal_method.invocations: isSuccess getAuthentication removeAttribute getSession getAttributes getAttributes get addCookie toString get get isEmpty get put getModel setView buildRedirectView toString get toString get put getModel setViewName getCookies equals getName setMaxAge addCookie put getModel getCode put getModel getMessage getMsgKey
focal_method.modifiers: @Override public
focal_method.parameters: (ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)
focal_method.return: ModelAndView
focal_method.signature: ModelAndView loginResultToView(ModelAndView mv, LoginResult result, HttpServletRequest request,
  			HttpServletResponse response)