Skip to content

Commit

Permalink
Added from header
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakky54 committed Dec 18, 2024
1 parent f5ed533 commit 3508dd7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void iExpectToReceiveStatusCodeStatusCode(int statusCode) {

@Then("I expect to receive {string} message")
public void iExpectToReceiveBody(String body) {
assertThat(testScenario.getClientResponse().getResponseBody()).isEqualTo(body);
assertThat(testScenario.getClientResponse().getResponseBody()).contains(body);
}

@And("I display the time it took to get the message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@
*/
package nl.altindag.server.controller;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import nl.altindag.server.aspect.LogCertificate;
import nl.altindag.server.aspect.LogClientType;
import org.springframework.web.bind.annotation.RequestHeader;

@Controller
public class HelloWorldController {

@LogClientType
@LogCertificate(detailed = true)
@GetMapping(value = "/api/hello", produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> hello() {
return ResponseEntity.ok("Hello");
public ResponseEntity<String> hello(@RequestHeader(name = HttpHeaders.FROM, required = false) String from) {
return from == null ? ResponseEntity.ok("Hello") : ResponseEntity.ok(String.format("Hello %s!", from));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,36 @@ public void setUp() {

@Test
void returnHelloMessage() {
ResponseEntity<String> response = victim.hello();
ResponseEntity<String> response = victim.hello(null);

assertThat(response.getBody()).isEqualTo("Hello");
}

@Test
void returnHelloWithFromHeaderValueMessage() {
ResponseEntity<String> response = victim.hello("Foo");

assertThat(response.getBody()).isEqualTo("Hello Foo!");
}

@Test
void returnStatusCode200() {
ResponseEntity<String> response = victim.hello();
ResponseEntity<String> response = victim.hello(null);

assertThat(response.getStatusCode().value()).isEqualTo(200);
}

@Test
void annotatedWithLogCertificate() throws NoSuchMethodException {
Method helloMethod = HelloWorldController.class.getMethod("hello");
Method helloMethod = HelloWorldController.class.getMethod("hello", String.class);
LogCertificate annotation = helloMethod.getAnnotation(LogCertificate.class);

assertThat(annotation).isNotNull();
}

@Test
void annotatedWithLogClientType() throws NoSuchMethodException {
Method helloMethod = HelloWorldController.class.getMethod("hello");
Method helloMethod = HelloWorldController.class.getMethod("hello", String.class);
LogClientType annotation = helloMethod.getAnnotation(LogClientType.class);

assertThat(annotation).isNotNull();
Expand Down

0 comments on commit 3508dd7

Please sign in to comment.