64
64
*/
65
65
public class ModelInitializerTests {
66
66
67
+ private static final Duration TIMEOUT = Duration .ofMillis (5000 );
68
+
69
+
67
70
private ModelInitializer modelInitializer ;
68
71
69
72
private final ServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/path" ));
@@ -93,7 +96,7 @@ public void initBinderMethod() {
93
96
94
97
Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
95
98
HandlerMethod handlerMethod = new HandlerMethod (controller , method );
96
- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
99
+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
97
100
98
101
WebExchangeDataBinder binder = context .createDataBinder (this .exchange , "name" );
99
102
assertThat (binder .getValidators ()).isEqualTo (Collections .singletonList (validator ));
@@ -107,7 +110,7 @@ public void modelAttributeMethods() {
107
110
108
111
Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
109
112
HandlerMethod handlerMethod = new HandlerMethod (controller , method );
110
- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
113
+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
111
114
112
115
Map <String , Object > model = context .getModel ().asMap ();
113
116
assertThat (model .size ()).isEqualTo (5 );
@@ -116,7 +119,7 @@ public void modelAttributeMethods() {
116
119
assertThat (((TestBean ) value ).getName ()).isEqualTo ("Bean" );
117
120
118
121
value = model .get ("monoBean" );
119
- assertThat (((Mono <TestBean >) value ).block (Duration . ofMillis ( 5000 ) ).getName ()).isEqualTo ("Mono Bean" );
122
+ assertThat (((Mono <TestBean >) value ).block (TIMEOUT ).getName ()).isEqualTo ("Mono Bean" );
120
123
121
124
value = model .get ("singleBean" );
122
125
assertThat (((Single <TestBean >) value ).toBlocking ().value ().getName ()).isEqualTo ("Single Bean" );
@@ -135,7 +138,7 @@ public void saveModelAttributeToSession() {
135
138
136
139
Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
137
140
HandlerMethod handlerMethod = new HandlerMethod (controller , method );
138
- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
141
+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
139
142
140
143
WebSession session = this .exchange .getSession ().block (Duration .ZERO );
141
144
assertThat (session ).isNotNull ();
@@ -148,7 +151,7 @@ public void saveModelAttributeToSession() {
148
151
149
152
@ Test
150
153
public void retrieveModelAttributeFromSession () {
151
- WebSession session = this .exchange .getSession ().block (Duration . ZERO );
154
+ WebSession session = this .exchange .getSession ().block (TIMEOUT );
152
155
assertThat (session ).isNotNull ();
153
156
154
157
TestBean testBean = new TestBean ("Session Bean" );
@@ -159,7 +162,7 @@ public void retrieveModelAttributeFromSession() {
159
162
160
163
Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
161
164
HandlerMethod handlerMethod = new HandlerMethod (controller , method );
162
- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
165
+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
163
166
164
167
context .saveModel ();
165
168
assertThat (session .getAttributes ().size ()).isEqualTo (1 );
@@ -174,13 +177,13 @@ public void requiredSessionAttributeMissing() {
174
177
Method method = ResolvableMethod .on (TestController .class ).annotPresent (PostMapping .class ).resolveMethod ();
175
178
HandlerMethod handlerMethod = new HandlerMethod (controller , method );
176
179
assertThatIllegalArgumentException ().isThrownBy (() ->
177
- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) ))
180
+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT ))
178
181
.withMessage ("Required attribute 'missing-bean' is missing." );
179
182
}
180
183
181
184
@ Test
182
185
public void clearModelAttributeFromSession () {
183
- WebSession session = this .exchange .getSession ().block (Duration . ZERO );
186
+ WebSession session = this .exchange .getSession ().block (TIMEOUT );
184
187
assertThat (session ).isNotNull ();
185
188
186
189
TestBean testBean = new TestBean ("Session Bean" );
@@ -191,7 +194,7 @@ public void clearModelAttributeFromSession() {
191
194
192
195
Method method = ResolvableMethod .on (TestController .class ).annotPresent (GetMapping .class ).resolveMethod ();
193
196
HandlerMethod handlerMethod = new HandlerMethod (controller , method );
194
- this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (Duration . ofMillis ( 5000 ) );
197
+ this .modelInitializer .initModel (handlerMethod , context , this .exchange ).block (TIMEOUT );
195
198
196
199
context .getSessionStatus ().setComplete ();
197
200
context .saveModel ();
0 commit comments