forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#16342 from geoand/quarkusio#16321
Add test for case where @ResponseStatus is used along with @ExceptionHandler
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...yment/src/test/java/io/quarkus/spring/web/test/ResponseStatusAndExceptionHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.spring.web.test; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ResponseStatusAndExceptionHandlerTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ExceptionController.class, RestExceptionHandler.class)); | ||
|
||
@Test | ||
public void testRootResource() { | ||
when().get("/exception").then().statusCode(400); | ||
} | ||
|
||
@RestController | ||
@RequestMapping("/exception") | ||
public static class ExceptionController { | ||
|
||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
public String throwException() { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
@RestControllerAdvice | ||
public static class RestExceptionHandler { | ||
|
||
@ExceptionHandler(RuntimeException.class) | ||
public ResponseEntity<Object> handleException(Exception ex) { | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
} |