Skip to content

Commit 3508dd7

Browse files
committed
Added from header
1 parent f5ed533 commit 3508dd7

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

client/src/main/java/nl/altindag/client/stepdefs/HelloStepDefs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void iExpectToReceiveStatusCodeStatusCode(int statusCode) {
7171

7272
@Then("I expect to receive {string} message")
7373
public void iExpectToReceiveBody(String body) {
74-
assertThat(testScenario.getClientResponse().getResponseBody()).isEqualTo(body);
74+
assertThat(testScenario.getClientResponse().getResponseBody()).contains(body);
7575
}
7676

7777
@And("I display the time it took to get the message")

server/src/main/java/nl/altindag/server/controller/HelloWorldController.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@
1515
*/
1616
package nl.altindag.server.controller;
1717

18+
import org.springframework.http.HttpHeaders;
1819
import org.springframework.http.MediaType;
1920
import org.springframework.http.ResponseEntity;
2021
import org.springframework.stereotype.Controller;
2122
import org.springframework.web.bind.annotation.GetMapping;
2223

2324
import nl.altindag.server.aspect.LogCertificate;
2425
import nl.altindag.server.aspect.LogClientType;
26+
import org.springframework.web.bind.annotation.RequestHeader;
2527

2628
@Controller
2729
public class HelloWorldController {
2830

2931
@LogClientType
3032
@LogCertificate(detailed = true)
3133
@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));
3436
}
3537

3638
}

server/src/test/java/nl/altindag/server/controller/HelloWorldControllerShould.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,36 @@ public void setUp() {
3737

3838
@Test
3939
void returnHelloMessage() {
40-
ResponseEntity<String> response = victim.hello();
40+
ResponseEntity<String> response = victim.hello(null);
4141

4242
assertThat(response.getBody()).isEqualTo("Hello");
4343
}
4444

45+
@Test
46+
void returnHelloWithFromHeaderValueMessage() {
47+
ResponseEntity<String> response = victim.hello("Foo");
48+
49+
assertThat(response.getBody()).isEqualTo("Hello Foo!");
50+
}
51+
4552
@Test
4653
void returnStatusCode200() {
47-
ResponseEntity<String> response = victim.hello();
54+
ResponseEntity<String> response = victim.hello(null);
4855

4956
assertThat(response.getStatusCode().value()).isEqualTo(200);
5057
}
5158

5259
@Test
5360
void annotatedWithLogCertificate() throws NoSuchMethodException {
54-
Method helloMethod = HelloWorldController.class.getMethod("hello");
61+
Method helloMethod = HelloWorldController.class.getMethod("hello", String.class);
5562
LogCertificate annotation = helloMethod.getAnnotation(LogCertificate.class);
5663

5764
assertThat(annotation).isNotNull();
5865
}
5966

6067
@Test
6168
void annotatedWithLogClientType() throws NoSuchMethodException {
62-
Method helloMethod = HelloWorldController.class.getMethod("hello");
69+
Method helloMethod = HelloWorldController.class.getMethod("hello", String.class);
6370
LogClientType annotation = helloMethod.getAnnotation(LogClientType.class);
6471

6572
assertThat(annotation).isNotNull();

0 commit comments

Comments
 (0)