Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
2f05d700
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2f05d700
编写于
8月 18, 2008
作者:
A
Andy Clement
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new function invocation tests for normal and error behaviour
上级
2fbb7ad3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
115 addition
and
2 deletion
+115
-2
org.springframework.expression/src/test/java/org/springframework/expression/spel/AllTests.java
...st/java/org/springframework/expression/spel/AllTests.java
+1
-0
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestCase.java
...g/springframework/expression/spel/ExpressionTestCase.java
+11
-2
org.springframework.expression/src/test/java/org/springframework/expression/spel/TestScenarioCreator.java
.../springframework/expression/spel/TestScenarioCreator.java
+25
-0
org.springframework.expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java
...ngframework/expression/spel/VariableAndFunctionTests.java
+78
-0
未找到文件。
org.springframework.expression/src/test/java/org/springframework/expression/spel/AllTests.java
浏览文件 @
2f05d700
...
...
@@ -32,6 +32,7 @@ public class AllTests {
suite
.
addTestSuite
(
BooleanExpressionTests
.
class
);
suite
.
addTestSuite
(
LiteralTests
.
class
);
suite
.
addTestSuite
(
ParsingTests
.
class
);
suite
.
addTestSuite
(
VariableAndFunctionTests
.
class
);
suite
.
addTestSuite
(
ParserErrorMessagesTests
.
class
);
suite
.
addTestSuite
(
EvaluationTests
.
class
);
suite
.
addTestSuite
(
OperatorTests
.
class
);
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestCase.java
浏览文件 @
2f05d700
...
...
@@ -34,6 +34,9 @@ public abstract class ExpressionTestCase extends TestCase {
private
final
static
boolean
DEBUG
=
false
;
protected
final
static
boolean
SHOULD_BE_WRITABLE
=
true
;
protected
final
static
boolean
SHOULD_NOT_BE_WRITABLE
=
false
;
protected
static
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
protected
static
StandardEvaluationContext
eContext
=
TestScenarioCreator
.
getTestEvaluationContext
();
...
...
@@ -159,8 +162,14 @@ public abstract class ExpressionTestCase extends TestCase {
null
);
}
Class
<?
extends
Object
>
resultType
=
value
.
getClass
();
assertEquals
(
"Did not get expected value for expression '"
+
expression
+
"'."
,
expectedValue
,
ExpressionTestCase
.
stringValueOf
(
value
));
if
(
expectedValue
instanceof
String
)
{
assertEquals
(
"Did not get expected value for expression '"
+
expression
+
"'."
,
expectedValue
,
ExpressionTestCase
.
stringValueOf
(
value
));
}
else
{
assertEquals
(
"Did not get expected value for expression '"
+
expression
+
"'."
,
expectedValue
,
value
);
}
// assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
// ExpressionTestCase.stringValueOf(value));
assertEquals
(
"Type of the result was not as expected. Expected '"
+
expectedClassOfResult
+
"' but result was of type '"
+
resultType
+
"'"
,
expectedClassOfResult
.
equals
/* isAssignableFrom */
(
resultType
),
true
);
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/TestScenarioCreator.java
浏览文件 @
2f05d700
...
...
@@ -61,6 +61,10 @@ public class TestScenarioCreator {
new
Class
[]
{
Integer
.
TYPE
,
Integer
.
TYPE
,
Integer
.
TYPE
}));
testContext
.
registerFunction
(
"reverseString"
,
TestScenarioCreator
.
class
.
getDeclaredMethod
(
"reverseString"
,
new
Class
[]
{
String
.
class
}));
testContext
.
registerFunction
(
"varargsFunctionReverseStringsAndMerge"
,
TestScenarioCreator
.
class
.
getDeclaredMethod
(
"varargsFunctionReverseStringsAndMerge"
,
new
Class
[]
{
String
[].
class
}));
testContext
.
registerFunction
(
"varargsFunctionReverseStringsAndMerge2"
,
TestScenarioCreator
.
class
.
getDeclaredMethod
(
"varargsFunctionReverseStringsAndMerge2"
,
new
Class
[]
{
Integer
.
TYPE
,
String
[].
class
}));
}
catch
(
SecurityException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchMethodException
e
)
{
...
...
@@ -200,4 +204,25 @@ public class TestScenarioCreator {
}
return
backwards
.
toString
();
}
public
static
String
varargsFunctionReverseStringsAndMerge
(
String
...
strings
)
{
StringBuilder
sb
=
new
StringBuilder
();
if
(
strings
!=
null
)
{
for
(
int
i
=
strings
.
length
-
1
;
i
>=
0
;
i
--)
{
sb
.
append
(
strings
[
i
]);
}
}
return
sb
.
toString
();
}
public
static
String
varargsFunctionReverseStringsAndMerge2
(
int
j
,
String
...
strings
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
j
);
if
(
strings
!=
null
)
{
for
(
int
i
=
strings
.
length
-
1
;
i
>=
0
;
i
--)
{
sb
.
append
(
strings
[
i
]);
}
}
return
sb
.
toString
();
}
}
org.springframework.expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java
0 → 100644
浏览文件 @
2f05d700
/*
* Copyright 2004-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.expression.spel
;
import
org.springframework.expression.spel.standard.StandardEvaluationContext
;
/**
* Tests the evaluation of expressions that access variables and functions (lambda/java).
*
* @author Andy Clement
*/
public
class
VariableAndFunctionTests
extends
ExpressionTestCase
{
public
void
testVariableAccess
()
{
evaluate
(
"#answer"
,
"42"
,
Integer
.
class
,
SHOULD_BE_WRITABLE
);
evaluate
(
"(#i=5;#i)"
,
5
,
Integer
.
class
,
SHOULD_BE_WRITABLE
);
evaluate
(
"#answer / 2"
,
21
,
Integer
.
class
,
SHOULD_NOT_BE_WRITABLE
);
}
public
void
testFunctionAccess01
()
{
evaluate
(
"#reverseInt(1,2,3)"
,
"int[3]{3,2,1}"
,
int
[].
class
);
evaluate
(
"#reverseInt('1',2,3)"
,
"int[3]{3,2,1}"
,
int
[].
class
);
// requires type conversion of '1' to 1
}
public
void
testFunctionAccess02
()
{
evaluate
(
"#reverseString('hello')"
,
"olleh"
,
String
.
class
);
evaluate
(
"#reverseString(37)"
,
"73"
,
String
.
class
);
// requires type conversion of 37 to '37'
}
public
void
testCallVarargsFunction
()
{
evaluate
(
"#varargsFunctionReverseStringsAndMerge('a','b','c')"
,
"cba"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('a')"
,
"a"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge()"
,
""
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge('b',25)"
,
"25b"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge(25)"
,
"25"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(1,'a','b','c')"
,
"1cba"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(2,'a')"
,
"2a"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(3)"
,
"3"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(4,'b',25)"
,
"425b"
,
String
.
class
);
evaluate
(
"#varargsFunctionReverseStringsAndMerge2(5,25)"
,
"525"
,
String
.
class
);
}
public
void
testCallingFunctionsIncorrectly
()
{
evaluateAndCheckError
(
"#varargsFunctionReverseStringsAndMerge(new StringBuilder())"
,
SpelMessages
.
TYPE_CONVERSION_ERROR
);
}
public
void
testCallingIllegalFunctions
()
throws
Exception
{
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
StandardEvaluationContext
ctx
=
new
StandardEvaluationContext
();
ctx
.
setVariable
(
"notStatic"
,
this
.
getClass
().
getMethod
(
"nonStatic"
));
try
{
@SuppressWarnings
(
"unused"
)
Object
v
=
parser
.
parseExpression
(
"#notStatic()"
).
getValue
(
ctx
);
fail
(
"Should have failed with exception - cannot call non static method that way"
);
}
catch
(
SpelException
se
)
{
if
(
se
.
getMessageUnformatted
()!=
SpelMessages
.
FUNCTION_MUST_BE_STATIC
)
{
se
.
printStackTrace
();
fail
(
"Should have failed a message about the function needing to be static, not: "
+
se
.
getMessageUnformatted
());
}
}
}
public
void
nonStatic
()
{}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录