Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit c9e9e3d

Browse files
committed
fix sessionStorage注解bug
1 parent cb8e90e commit c9e9e3d

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/main/java/org/suren/autotest/web/framework/annotation/AutoSessionStorage.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.lang.annotation.*;
2424

2525
/**
26-
* 用在登录方法上,第一次登录时,保存session信息;之后登录方法被调用时则会跳过
26+
* 用在方法上,第一次执行时,保存session信息;之后方法被调用时则会跳过
2727
* @author suren
2828
*/
2929
@Target(ElementType.METHOD)
@@ -32,12 +32,22 @@
3232
public @interface AutoSessionStorage
3333
{
3434
/**
35-
* @return 用户登录Page类
35+
* @return Page类
3636
*/
37-
Class<? extends Page> accountPage();
37+
Class<? extends Page> pageClazz();
3838

3939
/**
40-
* @return Page类中代表用户名的属性名称
40+
* @return Page类中代表的属性名称
4141
*/
42-
String accountName() default "userName";
42+
String sessionKey();
43+
44+
/**
45+
* @return 是否跳过目标方法
46+
*/
47+
boolean skipMethod() default true;
48+
49+
/**
50+
* @return 是否要执行打开页面操作
51+
*/
52+
boolean openInvoke() default false;
4353
}

src/main/java/org/suren/autotest/web/framework/settings/AutoModuleProxy.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public Object intercept(Object obj, Method method, Object[] args,
9292
if(autoSessionStorage != null)
9393
{
9494
sessionStorageConfig.setAutoLoad(true);
95-
Class<? extends Page> accountClz = autoSessionStorage.accountPage();
96-
String accountNameField = autoSessionStorage.accountName();
95+
Class<? extends Page> accountClz = autoSessionStorage.pageClazz();
96+
String accountNameField = autoSessionStorage.sessionKey();
9797

9898
Page page = util.getPage(accountClz);
9999
Field accountField = accountClz.getDeclaredField(accountNameField);
@@ -104,11 +104,16 @@ public Object intercept(Object obj, Method method, Object[] args,
104104
if(value instanceof Text)
105105
{
106106
String accountNameValue = ((Text) value).getValue();
107-
107+
sessionStorageConfig.setAccount(accountNameValue);
108+
108109
if(loadSessionStorage(accountNameValue))
109110
{
110111
sessionStorageConfig.setAccount(accountNameValue);
111-
sessionStorageConfig.setSkipLogin(true);
112+
113+
if(autoSessionStorage.skipMethod())
114+
{
115+
sessionStorageConfig.setSkipLogin(true);
116+
}
112117
}
113118
}
114119
else

src/main/java/org/suren/autotest/web/framework/util/PathUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public static void proStore(Properties pro, String fileName, String comment)
7474
*/
7575
public static boolean proLoad(Properties pro, String fileName)
7676
{
77-
try(InputStream in = new FileInputStream(new File(PathUtil.getRootDir(), fileName + PRO_SUFFIX)))
77+
File targetFile = new File(PathUtil.getRootDir(), fileName + PRO_SUFFIX);
78+
if(!targetFile.isFile())
79+
{
80+
return false;
81+
}
82+
83+
try(InputStream in = new FileInputStream(targetFile))
7884
{
7985
pro.load(in);
8086

0 commit comments

Comments
 (0)