File tree 3 files changed +16
-7
lines changed
client/src/main/java/nl/altindag/client/stepdefs
main/java/nl/altindag/server/controller
test/java/nl/altindag/server/controller
3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ public void iExpectToReceiveStatusCodeStatusCode(int statusCode) {
71
71
72
72
@ Then ("I expect to receive {string} message" )
73
73
public void iExpectToReceiveBody (String body ) {
74
- assertThat (testScenario .getClientResponse ().getResponseBody ()).isEqualTo (body );
74
+ assertThat (testScenario .getClientResponse ().getResponseBody ()).contains (body );
75
75
}
76
76
77
77
@ And ("I display the time it took to get the message" )
Original file line number Diff line number Diff line change 15
15
*/
16
16
package nl .altindag .server .controller ;
17
17
18
+ import org .springframework .http .HttpHeaders ;
18
19
import org .springframework .http .MediaType ;
19
20
import org .springframework .http .ResponseEntity ;
20
21
import org .springframework .stereotype .Controller ;
21
22
import org .springframework .web .bind .annotation .GetMapping ;
22
23
23
24
import nl .altindag .server .aspect .LogCertificate ;
24
25
import nl .altindag .server .aspect .LogClientType ;
26
+ import org .springframework .web .bind .annotation .RequestHeader ;
25
27
26
28
@ Controller
27
29
public class HelloWorldController {
28
30
29
31
@ LogClientType
30
32
@ LogCertificate (detailed = true )
31
33
@ GetMapping (value = "/api/hello" , produces = MediaType .TEXT_PLAIN_VALUE )
32
- public ResponseEntity <String > hello () {
33
- return ResponseEntity .ok ("Hello" );
34
+ public ResponseEntity <String > hello (@ RequestHeader ( name = HttpHeaders . FROM , required = false ) String from ) {
35
+ return from == null ? ResponseEntity .ok ("Hello" ) : ResponseEntity . ok ( String . format ( "Hello %s!" , from ) );
34
36
}
35
37
36
38
}
Original file line number Diff line number Diff line change @@ -37,29 +37,36 @@ public void setUp() {
37
37
38
38
@ Test
39
39
void returnHelloMessage () {
40
- ResponseEntity <String > response = victim .hello ();
40
+ ResponseEntity <String > response = victim .hello (null );
41
41
42
42
assertThat (response .getBody ()).isEqualTo ("Hello" );
43
43
}
44
44
45
+ @ Test
46
+ void returnHelloWithFromHeaderValueMessage () {
47
+ ResponseEntity <String > response = victim .hello ("Foo" );
48
+
49
+ assertThat (response .getBody ()).isEqualTo ("Hello Foo!" );
50
+ }
51
+
45
52
@ Test
46
53
void returnStatusCode200 () {
47
- ResponseEntity <String > response = victim .hello ();
54
+ ResponseEntity <String > response = victim .hello (null );
48
55
49
56
assertThat (response .getStatusCode ().value ()).isEqualTo (200 );
50
57
}
51
58
52
59
@ Test
53
60
void annotatedWithLogCertificate () throws NoSuchMethodException {
54
- Method helloMethod = HelloWorldController .class .getMethod ("hello" );
61
+ Method helloMethod = HelloWorldController .class .getMethod ("hello" , String . class );
55
62
LogCertificate annotation = helloMethod .getAnnotation (LogCertificate .class );
56
63
57
64
assertThat (annotation ).isNotNull ();
58
65
}
59
66
60
67
@ Test
61
68
void annotatedWithLogClientType () throws NoSuchMethodException {
62
- Method helloMethod = HelloWorldController .class .getMethod ("hello" );
69
+ Method helloMethod = HelloWorldController .class .getMethod ("hello" , String . class );
63
70
LogClientType annotation = helloMethod .getAnnotation (LogClientType .class );
64
71
65
72
assertThat (annotation ).isNotNull ();
You can’t perform that action at this time.
0 commit comments