Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
a6dd63f9
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
a6dd63f9
编写于
11月 08, 2019
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23938
上级
c7b99880
0e1a2371
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
6 deletion
+77
-6
spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolverTests.java
...otation/support/PrincipalMethodArgumentResolverTests.java
+73
-0
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PrincipalMethodArgumentResolverTests.java
...thod/annotation/PrincipalMethodArgumentResolverTests.java
+4
-6
未找到文件。
spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolverTests.java
0 → 100644
浏览文件 @
a6dd63f9
/*
* Copyright 2002-2019 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
*
* https://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.messaging.simp.annotation.support
;
import
java.security.Principal
;
import
java.util.Collections
;
import
java.util.Optional
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.messaging.Message
;
import
org.springframework.messaging.handler.invocation.ResolvableMethod
;
import
org.springframework.messaging.simp.SimpMessageHeaderAccessor
;
import
org.springframework.messaging.support.GenericMessage
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Unit tests for {@link PrincipalMethodArgumentResolver}.
*
* @author Rossen Stoyanchev
* @author Johnny Lim
*/
public
class
PrincipalMethodArgumentResolverTests
{
private
final
PrincipalMethodArgumentResolver
resolver
=
new
PrincipalMethodArgumentResolver
();
private
final
ResolvableMethod
testMethod
=
ResolvableMethod
.
on
(
getClass
()).
named
(
"handle"
).
build
();
@Test
public
void
supportsParameter
()
{
assertThat
(
this
.
resolver
.
supportsParameter
(
this
.
testMethod
.
arg
(
Principal
.
class
))).
isTrue
();
assertThat
(
this
.
resolver
.
supportsParameter
(
this
.
testMethod
.
arg
(
Optional
.
class
,
Principal
.
class
))).
isTrue
();
}
@Test
public
void
resolverArgument
()
{
Principal
user
=
()
->
"Joe"
;
Message
<
String
>
message
=
new
GenericMessage
<>(
"Hello, world!"
,
Collections
.
singletonMap
(
SimpMessageHeaderAccessor
.
USER_HEADER
,
user
));
MethodParameter
param
=
this
.
testMethod
.
arg
(
Principal
.
class
);
Object
actual
=
this
.
resolver
.
resolveArgument
(
param
,
message
);
assertThat
(
actual
).
isSameAs
(
user
);
param
=
this
.
testMethod
.
arg
(
Optional
.
class
,
Principal
.
class
);
actual
=
this
.
resolver
.
resolveArgument
(
param
,
message
);
assertThat
(
actual
).
isInstanceOf
(
Optional
.
class
).
extracting
(
o
->
((
Optional
<?>)
o
).
get
()).
isSameAs
(
user
);
}
@SuppressWarnings
(
"unused"
)
void
handle
(
Principal
user
,
Optional
<
Principal
>
optionalUser
)
{
}
}
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PrincipalMethodArgumentResolverTests.java
浏览文件 @
a6dd63f9
...
...
@@ -42,7 +42,7 @@ public class PrincipalMethodArgumentResolverTests {
private
final
PrincipalMethodArgumentResolver
resolver
=
new
PrincipalMethodArgumentResolver
(
ReactiveAdapterRegistry
.
getSharedInstance
());
private
ResolvableMethod
testMethod
=
ResolvableMethod
.
on
(
getClass
()).
named
(
"handle"
).
build
();
private
final
ResolvableMethod
testMethod
=
ResolvableMethod
.
on
(
getClass
()).
named
(
"handle"
).
build
();
@Test
...
...
@@ -55,24 +55,22 @@ public class PrincipalMethodArgumentResolverTests {
@Test
public
void
resolverArgument
()
{
BindingContext
context
=
new
BindingContext
();
Principal
user
=
()
->
"Joe"
;
ServerWebExchange
exchange
=
MockServerWebExchange
.
from
(
MockServerHttpRequest
.
get
(
"/"
))
.
mutate
().
principal
(
Mono
.
just
(
user
)).
build
();
BindingContext
context
=
new
BindingContext
();
MethodParameter
param
=
this
.
testMethod
.
arg
(
Principal
.
class
);
Object
actual
=
this
.
resolver
.
resolveArgument
(
param
,
context
,
exchange
).
block
();
assertThat
(
actual
).
isSameAs
(
user
);
param
=
this
.
testMethod
.
arg
(
Mono
.
class
,
Principal
.
class
);
actual
=
this
.
resolver
.
resolveArgument
(
param
,
context
,
exchange
).
block
();
assertThat
(
Mono
.
class
.
isAssignableFrom
(
actual
.
getClass
())).
isTrue
();
assertThat
(((
Mono
<?>)
actual
).
block
()).
isSameAs
(
user
);
assertThat
(
actual
).
isInstanceOf
(
Mono
.
class
).
extracting
(
o
->
((
Mono
<?>)
o
).
block
()).
isSameAs
(
user
);
param
=
this
.
testMethod
.
arg
(
Single
.
class
,
Principal
.
class
);
actual
=
this
.
resolver
.
resolveArgument
(
param
,
context
,
exchange
).
block
();
assertThat
(
Single
.
class
.
isAssignableFrom
(
actual
.
getClass
())).
isTrue
();
assertThat
(((
Single
<?>)
actual
).
blockingGet
()).
isSameAs
(
user
);
assertThat
(
actual
).
isInstanceOf
(
Single
.
class
).
extracting
(
o
->
((
Single
<?>)
o
).
blockingGet
()).
isSameAs
(
user
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录