From 74400ef6b90294f76e827032cfb84b13f8da5ad7 Mon Sep 17 00:00:00 2001 From: lidongy <1879087903@qq.com> Date: Fri, 25 Oct 2019 11:21:56 +0800 Subject: [PATCH] test Signed-off-by: lidongy <1879087903@qq.com> --- .../api/decision/login/LoginKitTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/java/com/fanruan/api/decision/login/LoginKitTest.java diff --git a/src/test/java/com/fanruan/api/decision/login/LoginKitTest.java b/src/test/java/com/fanruan/api/decision/login/LoginKitTest.java new file mode 100644 index 0000000..76bf3c3 --- /dev/null +++ b/src/test/java/com/fanruan/api/decision/login/LoginKitTest.java @@ -0,0 +1,69 @@ +package com.fanruan.api.decision.login; + +import com.fanruan.api.security.JwtKit; +import com.fr.config.dao.DaoContext; +import com.fr.config.dao.impl.LocalClassHelperDao; +import com.fr.config.dao.impl.LocalEntityDao; +import com.fr.config.dao.impl.LocalXmlEntityDao; +import com.fr.decision.config.AppearanceConfig; +import com.fr.decision.webservice.Response; +import com.fr.decision.webservice.bean.authentication.LoginClientBean; +import com.fr.decision.webservice.exception.login.LoginInfoNotAvailableException; +import com.fr.decision.webservice.utils.DecisionStatusService; +import com.fr.runtime.FineRuntime; +import com.fr.store.StateHubManager; +import com.fr.store.impl.MemoryLock; +import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author lidongy + * @version 10.0 + * Created by lidongy on 2019/10/25 + */ +public class LoginKitTest { + + @Before + public void start() { + FineRuntime.start(); + DaoContext.setEntityDao(new LocalEntityDao()); + DaoContext.setClassHelperDao(new LocalClassHelperDao()); + DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + Configurations.setHelper(new LocalConfigurationHelper()); + StateHubManager.setStorage(new MemoryStore()); + StateHubManager.setLock(new MemoryLock()); + } + + @Test + public void testRefreshToken() throws Exception{ + String jwtString = JwtKit.createDefaultJWT("123"); + Object responseData = new Object(); + String errorCode = ""; + String errorMsg = ""; + try { + Response response = (Response) LoginKit.refreshToken(jwtString, 1000 * 60, null, responseData, errorCode, errorMsg); + } catch (Exception e) { + Assert.assertTrue(e instanceof LoginInfoNotAvailableException); + } + LoginClientBean loginClientBean = new LoginClientBean(); + DecisionStatusService.loginStatusService().put(jwtString, loginClientBean); + try { + Response response = (Response) LoginKit.refreshToken(jwtString, 1000 * 60, null, responseData, errorCode, errorMsg); + } catch (Exception e) { + Assert.assertFalse(e instanceof LoginInfoNotAvailableException); + } + } + + @Test + public void TestGetLoginPageId() { + AppearanceConfig.getInstance().setLoginPageId("111"); + Assert.assertEquals(LoginKit.getLoginPageId(), "111"); + + AppearanceConfig.getInstance().setLoginPageId("aaa"); + Assert.assertEquals(LoginKit.getLoginPageId(), "aaa"); + } +}