forked from fanruan/finekit
lidongy
5 years ago
6 changed files with 179 additions and 0 deletions
@ -0,0 +1,20 @@
|
||||
package com.fanruan.api.decision; |
||||
|
||||
import com.fr.decision.config.AppearanceConfig; |
||||
|
||||
/** |
||||
* @author lidongy |
||||
* @version 10.0 |
||||
* Created by lidongy on 2019/10/24 |
||||
*/ |
||||
public class AppearanceKit { |
||||
|
||||
/** |
||||
* 获取选择的登录页插件id |
||||
* |
||||
* @return id |
||||
*/ |
||||
public static String getLoginPageId() { |
||||
return AppearanceConfig.getInstance().getLoginPageId(); |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.fanruan.api.decision.webservice; |
||||
|
||||
/** |
||||
* @author lidongy |
||||
* @version 10.0 |
||||
* Created by lidongy on 2019/10/24 |
||||
*/ |
||||
public class Response extends com.fr.decision.webservice.Response { |
||||
public Response() { |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fanruan.api.decision.webservice; |
||||
|
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.third.socketio.SocketIOClient; |
||||
|
||||
/** |
||||
* @author lidongy |
||||
* @version 10.0 |
||||
* Created by lidongy on 2019/10/24 |
||||
*/ |
||||
public class WebServiceKit { |
||||
|
||||
/** |
||||
* 刷新用户名对应的token,如果非保持登录,会使用tokenTimeout参数设置时长 |
||||
* |
||||
* @param oldJwt 老的token |
||||
* @param socketIOClient socket客户端 |
||||
* @param tokenTimeout 设置的超时时长,仅对非保持登录有用,0<= tokenTimeOut <= LoginConfig.LoginTimeOut |
||||
* @return 新的token |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public static Response refreshToken(String oldJwt, long tokenTimeout, SocketIOClient socketIOClient) throws Exception{ |
||||
return (Response) LoginService.getInstance().refreshToken(oldJwt, tokenTimeout, socketIOClient); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.fanruan.api.decision; |
||||
|
||||
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.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/24 |
||||
*/ |
||||
public class AppearenceKitTest { |
||||
@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 TestGetLoginPageId() { |
||||
AppearanceConfig.getInstance().setLoginPageId("111"); |
||||
Assert.assertEquals(AppearanceKit.getLoginPageId(), "111"); |
||||
|
||||
AppearanceConfig.getInstance().setLoginPageId("aaa"); |
||||
Assert.assertEquals(AppearanceKit.getLoginPageId(), "aaa"); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fanruan.api.decision.webservice; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* @author lidongy |
||||
* @version 10.0 |
||||
* Created by lidongy on 2019/10/25 |
||||
*/ |
||||
public class ResponseTest { |
||||
@Test |
||||
public void testResponse() throws Exception{ |
||||
Response response = new Response(); |
||||
|
||||
response.setData("data"); |
||||
response.setErrorCode("404"); |
||||
response.setErrorMsg("fail to connect"); |
||||
response.setStatus(3); |
||||
|
||||
Assert.assertEquals(response.getData(), "data"); |
||||
Assert.assertEquals(response.getErrorCode(), "404"); |
||||
Assert.assertEquals(response.getErrorMsg(), "fail to connect"); |
||||
Assert.assertEquals(response.getStatus(), 3); |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
package com.fanruan.api.decision.webservice; |
||||
|
||||
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.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/24 |
||||
*/ |
||||
public class WebServiceKitTest { |
||||
|
||||
@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"); |
||||
try { |
||||
Response response = WebServiceKit.refreshToken(jwtString, 1000 * 60, null); |
||||
} catch (Exception e) { |
||||
Assert.assertTrue(e instanceof LoginInfoNotAvailableException); |
||||
} |
||||
LoginClientBean loginClientBean = new LoginClientBean(); |
||||
DecisionStatusService.loginStatusService().put(jwtString, loginClientBean); |
||||
try { |
||||
Response response = WebServiceKit.refreshToken(jwtString, 1000 * 60, null); |
||||
} catch (Exception e) { |
||||
Assert.assertFalse(e instanceof LoginInfoNotAvailableException); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue