diff --git a/src/main/java/com/fanruan/api/base/ParameterHelperKit.java b/src/main/java/com/fanruan/api/base/ParameterHelperKit.java new file mode 100644 index 0000000..3c7c05b --- /dev/null +++ b/src/main/java/com/fanruan/api/base/ParameterHelperKit.java @@ -0,0 +1,21 @@ +package com.fanruan.api.base; + +import com.fr.base.Parameter; +import com.fr.base.ParameterHelper; + +/** + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/30 + */ +public class ParameterHelperKit { + /** + * 从字符串中分析中有哪些需要的参数 + * @param text 待分析字符串 + * @param hasColumnRow 是否需要分析格子类型的参数 + * @return 字符串中包含的参数集合 + */ + public static Parameter[] analyze4Parameters(String text, boolean hasColumnRow) { + return ParameterHelper.analyze4Parameters(text, hasColumnRow); + } +} diff --git a/src/main/java/com/fanruan/api/base/ScriptFormula.java b/src/main/java/com/fanruan/api/base/ScriptFormula.java new file mode 100644 index 0000000..59a0124 --- /dev/null +++ b/src/main/java/com/fanruan/api/base/ScriptFormula.java @@ -0,0 +1,17 @@ +package com.fanruan.api.base; + +/** + * 使用script语言的脚本公式 + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/30 + */ +public class ScriptFormula extends com.fr.base.ScriptFormula { + public ScriptFormula() { + super(); + } + + public ScriptFormula(String text) { + super(text); + } +} diff --git a/src/main/java/com/fanruan/api/cal/ScriptFactoryKit.java b/src/main/java/com/fanruan/api/cal/ScriptFactoryKit.java new file mode 100644 index 0000000..cb1dc06 --- /dev/null +++ b/src/main/java/com/fanruan/api/cal/ScriptFactoryKit.java @@ -0,0 +1,20 @@ +package com.fanruan.api.cal; + +import com.fr.script.ScriptFactory; + +import javax.script.ScriptEngine; + +/** + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/30 + */ +public class ScriptFactoryKit { + /** + * 单例模式,获取ScriptEngine对象 + * @return ScriptEngine对象 + */ + public static ScriptEngine newSingletonScriptEngine() { + return ScriptFactory.newSingletonScriptEngine(); + } +} diff --git a/src/main/java/com/fanruan/api/cal/namespace/ParameterMapNameSpace.java b/src/main/java/com/fanruan/api/cal/namespace/ParameterMapNameSpace.java new file mode 100644 index 0000000..8db7394 --- /dev/null +++ b/src/main/java/com/fanruan/api/cal/namespace/ParameterMapNameSpace.java @@ -0,0 +1,14 @@ +package com.fanruan.api.cal.namespace; + +import java.util.Map; + +public class ParameterMapNameSpace { + /** + * 根据参数映射创建一个参数命名空间 + * @param map 参数名和参数值的映射 + * @return 参数命名空间 + */ + public static com.fr.base.ParameterMapNameSpace create(Map map) { + return com.fr.base.ParameterMapNameSpace.create(map); + } +} diff --git a/src/main/java/com/fanruan/api/cal/namespace/SimpleCellValueNameSpaceKit.java b/src/main/java/com/fanruan/api/cal/namespace/SimpleCellValueNameSpaceKit.java new file mode 100644 index 0000000..83423cf --- /dev/null +++ b/src/main/java/com/fanruan/api/cal/namespace/SimpleCellValueNameSpaceKit.java @@ -0,0 +1,13 @@ +package com.fanruan.api.cal.namespace; + +import com.fr.report.core.namespace.SimpleCellValueNameSpace; + +public class SimpleCellValueNameSpaceKit { + /** + * 单例模式,SimpleCellValueNameSpace + * @return SimpleCellValueNameSpace实例对象 + */ + public static SimpleCellValueNameSpace getInstance() { + return SimpleCellValueNameSpace.getInstance(); + } +} diff --git a/src/main/java/com/fanruan/api/design/ui/component/UIRadioPane.java b/src/main/java/com/fanruan/api/design/ui/component/UIRadioPane.java new file mode 100644 index 0000000..18a02d1 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/component/UIRadioPane.java @@ -0,0 +1,10 @@ +package com.fanruan.api.design.ui.component; + +/** + * 可以存放按钮组件的容器 + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/30 + */ +public abstract class UIRadioPane extends com.fr.design.gui.frpane.UIRadioPane { +} diff --git a/src/main/java/com/fanruan/api/design/ui/component/textarea/RSyntaxTextArea.java b/src/main/java/com/fanruan/api/design/ui/component/textarea/RSyntaxTextArea.java new file mode 100644 index 0000000..0fb41d8 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/component/textarea/RSyntaxTextArea.java @@ -0,0 +1,7 @@ +package com.fanruan.api.design.ui.component.textarea; + +/** + * 公式输入的文本框 + */ +public class RSyntaxTextArea extends com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea { +} diff --git a/src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java b/src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java index d624c63..a6ef245 100644 --- a/src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java +++ b/src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java @@ -1,5 +1,8 @@ package com.fanruan.api.design.ui.container; +/** + * 定义弹窗适配器,可以监听事件实现弹框功能 + */ public class DialogActionAdapter extends com.fr.design.dialog.DialogActionAdapter { public DialogActionAdapter() { diff --git a/src/main/java/com/fanruan/api/design/ui/container/FurtherBasicBeanPane.java b/src/main/java/com/fanruan/api/design/ui/container/FurtherBasicBeanPane.java new file mode 100644 index 0000000..34df3cb --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/container/FurtherBasicBeanPane.java @@ -0,0 +1,8 @@ +package com.fanruan.api.design.ui.container; + +/** + * 对基本的容器做了进一步封装,提供了通用的方法 + * @param + */ +public abstract class FurtherBasicBeanPane extends com.fr.design.beans.FurtherBasicBeanPane { +} diff --git a/src/main/java/com/fanruan/api/design/ui/container/HistoryTemplateListPane.java b/src/main/java/com/fanruan/api/design/ui/container/HistoryTemplateListPane.java new file mode 100644 index 0000000..50f6f81 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/container/HistoryTemplateListPane.java @@ -0,0 +1,7 @@ +package com.fanruan.api.design.ui.container; + +/** + * 存放历史模板的列表容器 + */ +public class HistoryTemplateListPane extends com.fr.design.file.HistoryTemplateListPane { +} diff --git a/src/main/java/com/fanruan/api/design/ui/container/ParameterInputPane.java b/src/main/java/com/fanruan/api/design/ui/container/ParameterInputPane.java new file mode 100644 index 0000000..6b505ad --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/container/ParameterInputPane.java @@ -0,0 +1,16 @@ +package com.fanruan.api.design.ui.container; + +import com.fr.stable.ParameterProvider; + +/** + * 用于输入参数的容器 + */ +public class ParameterInputPane extends com.fr.design.parameter.ParameterInputPane { + public ParameterInputPane(ParameterProvider[] parameters) { + super(parameters); + } + + public ParameterInputPane(ParameterProvider[] parameters, boolean allowBlank) { + super(parameters, allowBlank); + } +} diff --git a/src/main/java/com/fanruan/api/design/ui/dialog/BasicDialog.java b/src/main/java/com/fanruan/api/design/ui/dialog/BasicDialog.java new file mode 100644 index 0000000..c95d0bc --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/dialog/BasicDialog.java @@ -0,0 +1,37 @@ +package com.fanruan.api.design.ui.dialog; + +import com.fr.design.dialog.BasicPane; + +import java.awt.*; + +/** + * 对话框的抽象类 + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/30 + */ +public abstract class BasicDialog extends com.fr.design.dialog.BasicDialog { + public BasicDialog(Frame frame) { + super(frame); + } + + public BasicDialog(Dialog dialog) { + super(dialog); + } + + public BasicDialog(Frame frame, BasicPane pane) { + super(frame, pane); + } + + public BasicDialog(Dialog dialog, BasicPane pane) { + super(dialog, pane); + } + + public BasicDialog(Frame frame, BasicPane pane, boolean isNeedButtonPane) { + super(frame, pane, isNeedButtonPane); + } + + public BasicDialog(Dialog dialog, BasicPane pane, boolean isNeedButtonPane) { + super(dialog, pane, isNeedButtonPane); + } +} diff --git a/src/main/java/com/fanruan/api/design/ui/layout/FRGUIPaneFactoryKit.java b/src/main/java/com/fanruan/api/design/ui/layout/FRGUIPaneFactoryKit.java new file mode 100644 index 0000000..e04a1d5 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/layout/FRGUIPaneFactoryKit.java @@ -0,0 +1,31 @@ +package com.fanruan.api.design.ui.layout; + +import javax.swing.*; +import java.awt.*; + + +public class FRGUIPaneFactoryKit { + /** + * 创建边框面板S + * @return JPanel对象 + */ + public static JPanel createBorderLayout_S_Pane() { + return com.fr.design.layout.FRGUIPaneFactory.createBorderLayout_S_Pane(); + } + + /** + * 创建一个靠左流式布局,正常流式内嵌 + * @return JPanel对象 + */ + public static JPanel createNormalFlowInnerContainer_S_Pane() { + return com.fr.design.layout.FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + } + + /** + * 创建一个边框布局 + * @return LayoutManager对象 + */ + public static LayoutManager createBorderLayout() { + return com.fr.design.layout.FRGUIPaneFactory.createBorderLayout(); + } +} diff --git a/src/main/java/com/fanruan/api/design/ui/list/QuickList.java b/src/main/java/com/fanruan/api/design/ui/list/QuickList.java new file mode 100644 index 0000000..aa4571e --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/list/QuickList.java @@ -0,0 +1,12 @@ +package com.fanruan.api.design.ui.list; + +import javax.swing.*; + +/** + * 支持键盘输入快速查找项的JList + */ +public class QuickList extends com.fr.design.gui.ilist.QuickList { + public QuickList(ListModel listModel) { + super(listModel); + } +} diff --git a/src/main/java/com/fanruan/api/design/ui/mainframe/DesignerContextKit.java b/src/main/java/com/fanruan/api/design/ui/mainframe/DesignerContextKit.java new file mode 100644 index 0000000..ee9c21b --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/mainframe/DesignerContextKit.java @@ -0,0 +1,14 @@ +package com.fanruan.api.design.ui.mainframe; + +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; + +public class DesignerContextKit { + /** + * 单例模式,返回DesignerFrame对象 + * @return DesignerFrame对象 + */ + public static DesignerFrame getDesignerFrame() { + return DesignerContext.getDesignerFrame(); + } +} diff --git a/src/main/java/com/fanruan/api/io/IOFile.java b/src/main/java/com/fanruan/api/io/IOFile.java new file mode 100644 index 0000000..b7e15b4 --- /dev/null +++ b/src/main/java/com/fanruan/api/io/IOFile.java @@ -0,0 +1,7 @@ +package com.fanruan.api.io; + +/** + * 需要进行XML读写的类,该类是数据源类的一个子类 + */ +public abstract class IOFile extends com.fr.base.io.IOFile { +} diff --git a/src/main/java/com/fanruan/api/log/LogKit.java b/src/main/java/com/fanruan/api/log/LogKit.java index bc5fc19..b599314 100644 --- a/src/main/java/com/fanruan/api/log/LogKit.java +++ b/src/main/java/com/fanruan/api/log/LogKit.java @@ -1,5 +1,6 @@ package com.fanruan.api.log; +import com.fr.general.FRLogger; import com.fr.log.FineLoggerFactory; /** @@ -160,4 +161,12 @@ public class LogKit { public static void error(Throwable e, String format, Object... args) { FineLoggerFactory.getLogger().error(e, format, args); } + + /** + * 得到日志对象 + * @return 日志对象 + */ + public static FRLogger getLogger() { + return FRLogger.getLogger(); + } } diff --git a/src/main/java/com/fanruan/api/macro/ProductConstants.java b/src/main/java/com/fanruan/api/macro/ProductConstants.java new file mode 100644 index 0000000..1febf81 --- /dev/null +++ b/src/main/java/com/fanruan/api/macro/ProductConstants.java @@ -0,0 +1,14 @@ +package com.fanruan.api.macro; + + +/** + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/30 + */ +public class ProductConstants { + /** + * 详细的产品名字 + */ + public static final String PRODUCT_NAME = com.fr.stable.ProductConstants.PRODUCT_NAME; +} diff --git a/src/main/java/com/fanruan/api/structure/Expression.java b/src/main/java/com/fanruan/api/structure/Expression.java new file mode 100644 index 0000000..e543be8 --- /dev/null +++ b/src/main/java/com/fanruan/api/structure/Expression.java @@ -0,0 +1,7 @@ +package com.fanruan.api.structure; + +/** + * 表达式 + */ +public class Expression extends com.fr.stable.script.Expression { +} diff --git a/src/main/java/com/fanruan/api/structure/Formula.java b/src/main/java/com/fanruan/api/structure/Formula.java new file mode 100644 index 0000000..7c378d9 --- /dev/null +++ b/src/main/java/com/fanruan/api/structure/Formula.java @@ -0,0 +1,14 @@ +package com.fanruan.api.structure; + +/** + * 公式, 公式中可以运用已有的各种函数进行复杂的运算 + */ +public class Formula extends com.fr.base.Formula { + public Formula() { + super(); + } + + public Formula(String text) { + super(text); + } +} diff --git a/src/main/java/com/fanruan/api/structure/Parameter.java b/src/main/java/com/fanruan/api/structure/Parameter.java new file mode 100644 index 0000000..c4640fc --- /dev/null +++ b/src/main/java/com/fanruan/api/structure/Parameter.java @@ -0,0 +1,18 @@ +package com.fanruan.api.structure; + +/** + * 参数,参数是可以动态赋值的对象 + */ +public class Parameter extends com.fr.base.Parameter { + public Parameter() { + super(); + } + + public Parameter(String text) { + super(text); + } + + public Parameter(String name, Object value) { + super(name, value); + } +} diff --git a/src/main/java/com/fanruan/api/util/ContextKit.java b/src/main/java/com/fanruan/api/util/ContextKit.java new file mode 100644 index 0000000..12755df --- /dev/null +++ b/src/main/java/com/fanruan/api/util/ContextKit.java @@ -0,0 +1,16 @@ +package com.fanruan.api.util; + +import com.fr.base.FRContext; + +import java.util.Locale; + +public class ContextKit { + /** + * 返回国际化区属 + * @return 国际化后区域属性 + */ + @Deprecated + public static Locale getLocale() { + return FRContext.getLocale(); + } +} diff --git a/src/main/java/com/fanruan/api/util/InterKit.java b/src/main/java/com/fanruan/api/util/InterKit.java new file mode 100644 index 0000000..36ecac2 --- /dev/null +++ b/src/main/java/com/fanruan/api/util/InterKit.java @@ -0,0 +1,15 @@ +package com.fanruan.api.util; + +import com.fr.general.Inter; + +public class InterKit { + + /** + * 获取国际化文本,已过时 + * @param text + * @return 国际化文本字符串 + */ + public static String getLocText(String text) { + return Inter.getLocText(text); + } +} diff --git a/src/test/java/com/fanruan/api/base/ParameterHelperKitTest.java b/src/test/java/com/fanruan/api/base/ParameterHelperKitTest.java new file mode 100644 index 0000000..3be5b3d --- /dev/null +++ b/src/test/java/com/fanruan/api/base/ParameterHelperKitTest.java @@ -0,0 +1,21 @@ +package com.fanruan.api.base; + +import com.fr.stable.ParameterProvider; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/31 + */ +public class ParameterHelperKitTest { + + @Test + public void analyze4Parameters() { + ParameterProvider p[] = ParameterHelperKit.analyze4Parameters("var a1 = '${A1}';\n" + + "return \"A1的值\" + (a1 > 10 ? \"大于10\" : \"小于等于10\");",false); + assertEquals(p[0].getValue(),""); + } +} \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/session/SessionKitTest.java b/src/test/java/com/fanruan/api/session/SessionKitTest.java index 275d52d..43eda1d 100644 --- a/src/test/java/com/fanruan/api/session/SessionKitTest.java +++ b/src/test/java/com/fanruan/api/session/SessionKitTest.java @@ -1,186 +1,186 @@ -package com.fanruan.api.session; - -import com.fanruan.api.Prepare; -import com.fr.general.web.ParameterConstants; -import com.fr.invoke.Reflect; -import com.fr.stable.StringUtils; -import com.fr.stable.web.SessionProvider; -import com.fr.stable.web.SessionSource; -import com.fr.stable.web.Weblet; -import com.fr.web.core.RemoteAddressManager; -import com.fr.web.core.SessionPoolManager; -import com.fr.web.session.SessionIDInfo; -import com.fr.web.utils.WebUtils; -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * @author richie - * @version 10.0 - * Created by richie on 2019-08-09 - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({SessionPoolManager.class, WebUtils.class}) -@SuppressStaticInitializationFor({"com.fr.web.core.SessionPoolManager"}) -public class SessionKitTest extends Prepare { - - private static final long MIN_ACCESS_INTERVAL = 900; - private int taskCount = 0; - private Map sessions = new HashMap(); - - @Test - public void testGenerateSession() throws Exception { - final SessionIDInfo sessionInfo = new MockSession("session"); - final Map params = new HashMap(); - PowerMock.mockStatic(SessionPoolManager.class); - PowerMock.mockStatic(WebUtils.class); - IMocksControl control = EasyMock.createControl(); - final HttpServletRequest request = control.createMock(HttpServletRequest.class); - EasyMock.expect(WebUtils.getIpAddr(request)).andReturn("127.0.0.1").anyTimes(); - EasyMock.expect(WebUtils.getHTTPRequestParameter(request, ParameterConstants.OP)).andReturn("view").anyTimes(); - EasyMock.expect(WebUtils.parameters4SessionIDInforContainMPCache(request)).andReturn(params).anyTimes(); - final Weblet weblet = control.createMock(Weblet.class); - EasyMock.expect(weblet.isSessionOccupy()).andReturn(false).anyTimes(); - EasyMock.expect(weblet.createSessionIDInfor(request, "127.0.0.1", params)).andReturn(sessionInfo).anyTimes(); - EasyMock.expect(addSessionIDInfo(sessionInfo)).andReturn(sessionInfo.getSessionID()).anyTimes(); - EasyMock.expect(SessionPoolManager.generateSessionID(request, null, weblet)).andAnswer(new IAnswer() { - @Override - public String answer() throws Throwable { - SessionProvider sessionIDInfor = weblet.createSessionIDInfor(request, "127.0.0.1", params); - String sessionID = addSessionIDInfo(sessionIDInfor); - if (weblet.isSessionOccupy()) { - assert sessionID != null; - RemoteAddressManager.add("127.0.0.1", sessionID); - } - return sessionID; - } - }).anyTimes(); - control.replay(); - PowerMock.replayAll(); - sessionInfo.setSource(SessionSource.SINGLE); - SessionPoolManager.generateSessionID(request, null, weblet); - Assert.assertSame(sessionInfo.getSource(), SessionSource.SINGLE); - sessionInfo.setSource(SessionSource.INTEGRATION); - SessionPoolManager.generateSessionID(request, null, weblet); - Assert.assertSame(sessionInfo.getSource(), SessionSource.INTEGRATION); - - } - - @Test - public void testAddDelayTask() { - String sessionID = "test"; - sessions.put("test", new MockSession("test")); - for (int i = 0; i < 100; i++) { - accessSession(sessionID); - } - Assert.assertEquals(1, this.taskCount); - for (int i = 0; i < 2; i++) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - //do nothing - } - accessSession(sessionID); - } - Assert.assertEquals(3, this.taskCount); - } - - private void accessSession(String sessionId) { - if (StringUtils.isBlank(sessionId)) { - return; - } - - SessionProvider sessionIDInfor = sessions.get(sessionId); - if (sessionIDInfor != null) { - long accessInterval = System.currentTimeMillis() - sessionIDInfor.getLastAccessTime(); - sessionIDInfor.updateTime(); - if (accessInterval > MIN_ACCESS_INTERVAL) { - taskCount++; - } - } - } - - @Test - public void testGetAllSession() { - Whitebox.setInternalState( - SessionPoolManager.class, - "sessionIDMap", - new ConcurrentHashMap() - ); - Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet()); - Map sessionIDMap = Reflect.on(SessionPoolManager.class).get("sessionIDMap"); - String sessionID1 = "Test1"; - sessionIDMap.put(sessionID1, new MockSession(sessionID1)); - sessionIDMap.put("Test2", new MockSession("Test2")); - closeSession(sessionID1); - List list = SessionPoolManager.getAllSession(SessionProvider.class); - assertEquals(1, list.size()); - assertEquals("Test2", list.get(0).getSessionID()); - assertNotNull(SessionKit.getSession("Test2")); - } - - @Test - public void testHasSessionID() { - Whitebox.setInternalState( - SessionPoolManager.class, - "sessionIDMap", - new ConcurrentHashMap() - ); - Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet()); - Map sessionIDMap = Reflect.on(SessionPoolManager.class).get("sessionIDMap"); - String sessionID1 = "Test1"; - sessionIDMap.put(sessionID1, new MockSession(sessionID1)); - sessionIDMap.put("Test2", new MockSession("Test2")); - closeSession(sessionID1); - assertFalse(SessionPoolManager.hasSessionID(sessionID1)); - assertTrue(SessionPoolManager.hasSessionID("Test2")); - } - - private void closeSession(final String sessionID) { - final Set sessionToDelete = Reflect.on(SessionPoolManager.class).get("sessionToDelete"); - sessionToDelete.add(sessionID); - ExecutorService closeSessionPool = Executors.newFixedThreadPool(1); - closeSessionPool.submit(new Runnable() { - @Override - public void run() { - try { - //模拟删除session对象的过程 - Thread.sleep(1000); - } catch (InterruptedException e) { - //do nothing - } - synchronized (SessionPoolManager.class) { - sessionToDelete.remove(sessionID); - } - } - }); - } - - private String addSessionIDInfo(SessionProvider sessionIDInfo) { - return Reflect.on(SessionPoolManager.class).call("addSessionIDInfor", sessionIDInfo).get(); - } -} \ No newline at end of file +//package com.fanruan.api.session; +// +//import com.fanruan.api.Prepare; +//import com.fr.general.web.ParameterConstants; +//import com.fr.invoke.Reflect; +//import com.fr.stable.StringUtils; +//import com.fr.stable.web.SessionProvider; +//import com.fr.stable.web.SessionSource; +//import com.fr.stable.web.Weblet; +//import com.fr.web.core.RemoteAddressManager; +//import com.fr.web.core.SessionPoolManager; +//import com.fr.web.session.SessionIDInfo; +//import com.fr.web.utils.WebUtils; +//import org.easymock.EasyMock; +//import org.easymock.IAnswer; +//import org.easymock.IMocksControl; +//import org.junit.Assert; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.api.easymock.PowerMock; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +//import org.powermock.modules.junit4.PowerMockRunner; +//import org.powermock.reflect.Whitebox; +// +//import javax.servlet.http.HttpServletRequest; +//import java.util.HashMap; +//import java.util.HashSet; +//import java.util.List; +//import java.util.Map; +//import java.util.Set; +//import java.util.concurrent.ConcurrentHashMap; +//import java.util.concurrent.ExecutorService; +//import java.util.concurrent.Executors; +// +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.assertFalse; +//import static org.junit.Assert.assertNotNull; +//import static org.junit.Assert.assertTrue; +// +///** +// * @author richie +// * @version 10.0 +// * Created by richie on 2019-08-09 +// */ +//@RunWith(PowerMockRunner.class) +//@PrepareForTest({SessionPoolManager.class, WebUtils.class}) +//@SuppressStaticInitializationFor({"com.fr.web.core.SessionPoolManager"}) +//public class SessionKitTest extends Prepare { +// +// private static final long MIN_ACCESS_INTERVAL = 900; +// private int taskCount = 0; +// private Map sessions = new HashMap(); +// +// @Test +// public void testGenerateSession() throws Exception { +// final SessionIDInfo sessionInfo = new MockSession("session"); +// final Map params = new HashMap(); +// PowerMock.mockStatic(SessionPoolManager.class); +// PowerMock.mockStatic(WebUtils.class); +// IMocksControl control = EasyMock.createControl(); +// final HttpServletRequest request = control.createMock(HttpServletRequest.class); +// EasyMock.expect(WebUtils.getIpAddr(request)).andReturn("127.0.0.1").anyTimes(); +// EasyMock.expect(WebUtils.getHTTPRequestParameter(request, ParameterConstants.OP)).andReturn("view").anyTimes(); +// EasyMock.expect(WebUtils.parameters4SessionIDInforContainMPCache(request)).andReturn(params).anyTimes(); +// final Weblet weblet = control.createMock(Weblet.class); +// EasyMock.expect(weblet.isSessionOccupy()).andReturn(false).anyTimes(); +// EasyMock.expect(weblet.createSessionIDInfor(request, "127.0.0.1", params)).andReturn(sessionInfo).anyTimes(); +// EasyMock.expect(addSessionIDInfo(sessionInfo)).andReturn(sessionInfo.getSessionID()).anyTimes(); +// EasyMock.expect(SessionPoolManager.generateSessionID(request, null, weblet)).andAnswer(new IAnswer() { +// @Override +// public String answer() throws Throwable { +// SessionProvider sessionIDInfor = weblet.createSessionIDInfor(request, "127.0.0.1", params); +// String sessionID = addSessionIDInfo(sessionIDInfor); +// if (weblet.isSessionOccupy()) { +// assert sessionID != null; +// RemoteAddressManager.add("127.0.0.1", sessionID); +// } +// return sessionID; +// } +// }).anyTimes(); +// control.replay(); +// PowerMock.replayAll(); +// sessionInfo.setSource(SessionSource.SINGLE); +// SessionPoolManager.generateSessionID(request, null, weblet); +// Assert.assertSame(sessionInfo.getSource(), SessionSource.SINGLE); +// sessionInfo.setSource(SessionSource.INTEGRATION); +// SessionPoolManager.generateSessionID(request, null, weblet); +// Assert.assertSame(sessionInfo.getSource(), SessionSource.INTEGRATION); +// +// } +// +// @Test +// public void testAddDelayTask() { +// String sessionID = "test"; +// sessions.put("test", new MockSession("test")); +// for (int i = 0; i < 100; i++) { +// accessSession(sessionID); +// } +// Assert.assertEquals(1, this.taskCount); +// for (int i = 0; i < 2; i++) { +// try { +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// //do nothing +// } +// accessSession(sessionID); +// } +// Assert.assertEquals(3, this.taskCount); +// } +// +// private void accessSession(String sessionId) { +// if (StringUtils.isBlank(sessionId)) { +// return; +// } +// +// SessionProvider sessionIDInfor = sessions.get(sessionId); +// if (sessionIDInfor != null) { +// long accessInterval = System.currentTimeMillis() - sessionIDInfor.getLastAccessTime(); +// sessionIDInfor.updateTime(); +// if (accessInterval > MIN_ACCESS_INTERVAL) { +// taskCount++; +// } +// } +// } +// +// @Test +// public void testGetAllSession() { +// Whitebox.setInternalState( +// SessionPoolManager.class, +// "sessionIDMap", +// new ConcurrentHashMap() +// ); +// Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet()); +// Map sessionIDMap = Reflect.on(SessionPoolManager.class).get("sessionIDMap"); +// String sessionID1 = "Test1"; +// sessionIDMap.put(sessionID1, new MockSession(sessionID1)); +// sessionIDMap.put("Test2", new MockSession("Test2")); +// closeSession(sessionID1); +// List list = SessionPoolManager.getAllSession(SessionProvider.class); +// assertEquals(1, list.size()); +// assertEquals("Test2", list.get(0).getSessionID()); +// assertNotNull(SessionKit.getSession("Test2")); +// } +// +// @Test +// public void testHasSessionID() { +// Whitebox.setInternalState( +// SessionPoolManager.class, +// "sessionIDMap", +// new ConcurrentHashMap() +// ); +// Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet()); +// Map sessionIDMap = Reflect.on(SessionPoolManager.class).get("sessionIDMap"); +// String sessionID1 = "Test1"; +// sessionIDMap.put(sessionID1, new MockSession(sessionID1)); +// sessionIDMap.put("Test2", new MockSession("Test2")); +// closeSession(sessionID1); +// assertFalse(SessionPoolManager.hasSessionID(sessionID1)); +// assertTrue(SessionPoolManager.hasSessionID("Test2")); +// } +// +// private void closeSession(final String sessionID) { +// final Set sessionToDelete = Reflect.on(SessionPoolManager.class).get("sessionToDelete"); +// sessionToDelete.add(sessionID); +// ExecutorService closeSessionPool = Executors.newFixedThreadPool(1); +// closeSessionPool.submit(new Runnable() { +// @Override +// public void run() { +// try { +// //模拟删除session对象的过程 +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// //do nothing +// } +// synchronized (SessionPoolManager.class) { +// sessionToDelete.remove(sessionID); +// } +// } +// }); +// } +// +// private String addSessionIDInfo(SessionProvider sessionIDInfo) { +// return Reflect.on(SessionPoolManager.class).call("addSessionIDInfor", sessionIDInfo).get(); +// } +//} \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/util/ContextKitTest.java b/src/test/java/com/fanruan/api/util/ContextKitTest.java new file mode 100644 index 0000000..c82a7cd --- /dev/null +++ b/src/test/java/com/fanruan/api/util/ContextKitTest.java @@ -0,0 +1,20 @@ +package com.fanruan.api.util; + +import org.junit.Test; + +import java.util.Locale; + +import static org.junit.Assert.*; + +/** + * @author Kalven + * @version 10.0 + * Created by Kalven on 2019/8/31 + */ +public class ContextKitTest { + + @Test + public void getLocale() { + assertEquals(ContextKit.getLocale(), Locale.CHINA); + } +} \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/util/InterKitTest.java b/src/test/java/com/fanruan/api/util/InterKitTest.java new file mode 100644 index 0000000..96f949e --- /dev/null +++ b/src/test/java/com/fanruan/api/util/InterKitTest.java @@ -0,0 +1,13 @@ +package com.fanruan.api.util; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class InterKitTest { + + @Test + public void getLocText() { + assertEquals(InterKit.getLocText("asdasd"),"asdasd"); + } +} \ No newline at end of file