2
2
3
3
import com .google .common .collect .ImmutableMap ;
4
4
import com .google .common .collect .Lists ;
5
- import io .github .lvyahui8 .spring .aggregate .facade .DataBeanAggregateQueryFacade ;
6
5
import io .github .lvyahui8 .spring .aggregate .func .Function2 ;
7
6
import io .github .lvyahui8 .spring .aggregate .func .Function3 ;
8
7
import io .github .lvyahui8 .spring .annotation .DataConsumer ;
14
13
import io .github .lvyahui8 .spring .example .model .Category ;
15
14
import io .github .lvyahui8 .spring .example .model .Post ;
16
15
import io .github .lvyahui8 .spring .example .model .User ;
16
+ import io .github .lvyahui8 .spring .facade .DataFacade ;
17
17
import lombok .extern .slf4j .Slf4j ;
18
18
import org .junit .Test ;
19
19
import org .junit .runner .RunWith ;
@@ -37,9 +37,6 @@ public class DataBeanAggregateQueryFacadeTest {
37
37
38
38
private static final int NUM = 100 ;
39
39
40
- @ Autowired
41
- private DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade ;
42
-
43
40
@ Autowired
44
41
private BeanAggregateProperties beanAggregateProperties ;
45
42
@@ -49,7 +46,7 @@ public class DataBeanAggregateQueryFacadeTest {
49
46
@ Test
50
47
public void testSample () throws Exception {
51
48
{
52
- User user = dataBeanAggregateQueryFacade .get ("userWithPosts" , Collections .singletonMap ("userId" ,1L ), User .class );
49
+ User user = DataFacade .get ("userWithPosts" , Collections .singletonMap ("userId" ,1L ), User .class );
53
50
Assert .notNull (user ,"user not null" );
54
51
Assert .notNull (user .getPosts (),"user posts not null" );
55
52
log .info ("user.name:{},user.posts.size:{}" ,
@@ -67,7 +64,7 @@ public void testSample() throws Exception {
67
64
68
65
{
69
66
for (int i = 0 ; i < NUM ; i ++) {
70
- String s = dataBeanAggregateQueryFacade .get ("categoryTitle" , Collections .singletonMap ("categoryId" , 1L ), String .class );
67
+ String s = DataFacade .get ("categoryTitle" , Collections .singletonMap ("categoryId" , 1L ), String .class );
71
68
Assert .isTrue (org .apache .commons .lang3 .StringUtils .isNotEmpty (s ),"s not null" );
72
69
}
73
70
}
@@ -78,13 +75,13 @@ public void testExceptionProcessing() throws Exception {
78
75
boolean success = false ;
79
76
if (! beanAggregateProperties .isIgnoreException ()) {
80
77
try {
81
- dataBeanAggregateQueryFacade .get ("userWithPosts" ,
78
+ DataFacade .get ("userWithPosts" ,
82
79
Collections .singletonMap ("userId" , 1L ), User .class );
83
80
} catch (Exception e ) {
84
81
log .info ("default settings is SUSPEND, catch an exception: {}" ,e .getMessage (),e );
85
82
}
86
83
} else {
87
- User user = dataBeanAggregateQueryFacade .get ("userWithPosts" ,
84
+ User user = DataFacade .get ("userWithPosts" ,
88
85
Collections .singletonMap ("userId" , 1L ), User .class );
89
86
Assert .notNull (user ,"user must be not null!" );
90
87
}
@@ -93,7 +90,7 @@ public void testExceptionProcessing() throws Exception {
93
90
@ Test
94
91
public void testGetByMultipleArgumentsFunction () throws Exception {
95
92
Map <String , Object > singletonMap = Collections .singletonMap ("userId" , 1L );
96
- User user = dataBeanAggregateQueryFacade .get (singletonMap , new Function2 <User , List <Post >, User >() {
93
+ User user = DataFacade .get (singletonMap , new Function2 <User , List <Post >, User >() {
97
94
@ Override
98
95
public User apply (@ DataConsumer ("user" ) User user , @ DataConsumer ("posts" ) List <Post > posts ) {
99
96
user .setPosts (posts );
@@ -102,7 +99,7 @@ public User apply(@DataConsumer("user") User user, @DataConsumer("posts") List<P
102
99
},null );
103
100
Assert .notNull (user ,"user never not be null!" );
104
101
try {
105
- user = dataBeanAggregateQueryFacade .get (singletonMap , (Function2 <User , List <Post >, User >) (user1 , posts ) -> {
102
+ user = DataFacade .get (singletonMap , (Function2 <User , List <Post >, User >) (user1 , posts ) -> {
106
103
user1 .setPosts (posts );
107
104
return user1 ;
108
105
},null );
@@ -118,7 +115,7 @@ public void testInheritableThreadLocals() throws Exception {
118
115
user .setUsername ("bob" );
119
116
user .setId (100000L );
120
117
ExampleAppContext .setLoggedUser (user );
121
- dataBeanAggregateQueryFacade .get (null , new Function2 <String ,List <User >,User >() {
118
+ DataFacade .get (null , new Function2 <String ,List <User >,User >() {
122
119
@ Override
123
120
public User apply (@ DataConsumer ("loggedUsername" ) String loggedUsername ,
124
121
@ DataConsumer ("loggedUserFollowers" ) List <User > loggedUserFollowers ) {
@@ -138,7 +135,7 @@ public User apply(@DataConsumer("loggedUsername") String loggedUsername,
138
135
public void testThreadLocal () throws Exception {
139
136
try {
140
137
RequestContext .setTenantId (10000L );
141
- Object result = dataBeanAggregateQueryFacade .get (null ,
138
+ Object result = DataFacade .get (null ,
142
139
new Function3 <List <Category >, List <Post >, List <User >, Object >() {
143
140
@ Override
144
141
public Object apply (
@@ -161,7 +158,7 @@ public void testDynamicParameter() throws Exception {
161
158
.put ("userA_Id" , 1L )
162
159
.put ("userB_Id" , 2L )
163
160
.put ("userC_Id" , 3L ).build ();
164
- Object specialUserCollection = dataBeanAggregateQueryFacade .get (params ,
161
+ Object specialUserCollection = DataFacade .get (params ,
165
162
new Function3 <User ,User ,User ,Object >() {
166
163
@ Override
167
164
public Object apply (
@@ -181,7 +178,7 @@ public Object apply(
181
178
@ Test
182
179
public void testParameterTypeException () throws Exception {
183
180
try {
184
- dataBeanAggregateQueryFacade .get (Collections .singletonMap ("userId" , "1" ),
181
+ DataFacade .get (Collections .singletonMap ("userId" , "1" ),
185
182
new Function2 <User , List <Post >, User >() {
186
183
@ Override
187
184
public User apply (@ DataConsumer ("user" ) User user ,
@@ -209,7 +206,7 @@ public String apply(@DataConsumer("rootCategory") Category category,
209
206
Exception exp = null ;
210
207
for (int i = 0 ; i < 1000 ; i ++) {
211
208
try {
212
- String name = dataBeanAggregateQueryFacade .get (map ,userFunction );
209
+ String name = DataFacade .get (map ,userFunction );
213
210
} catch (Exception e ) {
214
211
exp = e ;
215
212
log .error ("exp:" + e .getMessage ());
0 commit comments