Browse Source

KERNEL-1117 根据插件增加了fineKit的部分文件,其中单例模式返回单例的方法没有进行单元测试

master
Kalven 5 years ago
parent
commit
36979667ed
  1. 21
      src/main/java/com/fanruan/api/base/ParameterHelperKit.java
  2. 17
      src/main/java/com/fanruan/api/base/ScriptFormula.java
  3. 20
      src/main/java/com/fanruan/api/cal/ScriptFactoryKit.java
  4. 14
      src/main/java/com/fanruan/api/cal/namespace/ParameterMapNameSpace.java
  5. 13
      src/main/java/com/fanruan/api/cal/namespace/SimpleCellValueNameSpaceKit.java
  6. 10
      src/main/java/com/fanruan/api/design/ui/component/UIRadioPane.java
  7. 7
      src/main/java/com/fanruan/api/design/ui/component/textarea/RSyntaxTextArea.java
  8. 3
      src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java
  9. 8
      src/main/java/com/fanruan/api/design/ui/container/FurtherBasicBeanPane.java
  10. 7
      src/main/java/com/fanruan/api/design/ui/container/HistoryTemplateListPane.java
  11. 16
      src/main/java/com/fanruan/api/design/ui/container/ParameterInputPane.java
  12. 37
      src/main/java/com/fanruan/api/design/ui/dialog/BasicDialog.java
  13. 31
      src/main/java/com/fanruan/api/design/ui/layout/FRGUIPaneFactoryKit.java
  14. 12
      src/main/java/com/fanruan/api/design/ui/list/QuickList.java
  15. 14
      src/main/java/com/fanruan/api/design/ui/mainframe/DesignerContextKit.java
  16. 7
      src/main/java/com/fanruan/api/io/IOFile.java
  17. 9
      src/main/java/com/fanruan/api/log/LogKit.java
  18. 14
      src/main/java/com/fanruan/api/macro/ProductConstants.java
  19. 7
      src/main/java/com/fanruan/api/structure/Expression.java
  20. 14
      src/main/java/com/fanruan/api/structure/Formula.java
  21. 18
      src/main/java/com/fanruan/api/structure/Parameter.java
  22. 16
      src/main/java/com/fanruan/api/util/ContextKit.java
  23. 15
      src/main/java/com/fanruan/api/util/InterKit.java
  24. 21
      src/test/java/com/fanruan/api/base/ParameterHelperKitTest.java
  25. 372
      src/test/java/com/fanruan/api/session/SessionKitTest.java
  26. 20
      src/test/java/com/fanruan/api/util/ContextKitTest.java
  27. 13
      src/test/java/com/fanruan/api/util/InterKitTest.java

21
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);
}
}

17
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);
}
}

20
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();
}
}

14
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);
}
}

13
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();
}
}

10
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<T> extends com.fr.design.gui.frpane.UIRadioPane<T> {
}

7
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 {
}

3
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() {

8
src/main/java/com/fanruan/api/design/ui/container/FurtherBasicBeanPane.java

@ -0,0 +1,8 @@
package com.fanruan.api.design.ui.container;
/**
* 对基本的容器做了进一步封装提供了通用的方法
* @param <T>
*/
public abstract class FurtherBasicBeanPane<T> extends com.fr.design.beans.FurtherBasicBeanPane<T> {
}

7
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 {
}

16
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);
}
}

37
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);
}
}

31
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();
}
}

12
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);
}
}

14
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();
}
}

7
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 {
}

9
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();
}
}

14
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;
}

7
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 {
}

14
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);
}
}

18
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);
}
}

16
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();
}
}

15
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);
}
}

21
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(),"");
}
}

372
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<String, SessionProvider> sessions = new HashMap<String, SessionProvider>();
@Test
public void testGenerateSession() throws Exception {
final SessionIDInfo sessionInfo = new MockSession("session");
final Map<String, Object> params = new HashMap<String, Object>();
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<String>() {
@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<String, SessionProvider>()
);
Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet<String>());
Map<String, SessionProvider> 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<SessionProvider> 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<String, SessionProvider>()
);
Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet<String>());
Map<String, SessionProvider> 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<String> 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();
}
}
//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<String, SessionProvider> sessions = new HashMap<String, SessionProvider>();
//
// @Test
// public void testGenerateSession() throws Exception {
// final SessionIDInfo sessionInfo = new MockSession("session");
// final Map<String, Object> params = new HashMap<String, Object>();
// 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<String>() {
// @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<String, SessionProvider>()
// );
// Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet<String>());
// Map<String, SessionProvider> 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<SessionProvider> 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<String, SessionProvider>()
// );
// Whitebox.setInternalState(SessionPoolManager.class, "sessionToDelete", new HashSet<String>());
// Map<String, SessionProvider> 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<String> 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();
// }
//}

20
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);
}
}

13
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");
}
}
Loading…
Cancel
Save