summary |
shortlog | log |
commit |
commitdiff |
tree
first ⋅ prev ⋅ next
Kai Moritz [Sat, 3 Oct 2020 14:49:23 +0000 (16:49 +0200)]
Trimmed the example to showcase an unit-test for a simple exception-handler
Kai Moritz [Sun, 20 Sep 2020 12:43:32 +0000 (14:43 +0200)]
Added a layout based on Bootstrap-4.x with the help of webjars
* The templates refer to bootstrapcnd.com directly
* The production-version uses webjars, to embed the CSS in the app
Kai Moritz [Sun, 20 Sep 2020 13:05:12 +0000 (15:05 +0200)]
Added a customized error-page
Kai Moritz [Sat, 19 Sep 2020 12:08:38 +0000 (14:08 +0200)]
Added an integration-test that tests the exception-handling
* The integration-test uses WebTestClient to test the exception-handling
* Since this is a real integration-test, the exception-handling behave
exactly the same way
* The test-setup with the WebTestClient needs an additional dependency, to
work correctly - without it, the WebTestClient-Bean would not be
intanciated
* The added test ExceptionHandlingApplicationIT tests exaclty the same
stuff, as ExceptionHandlingApplicationTest - this is no good test-design,
but it serves the intention, to compare the two approaches
* Since Spring-Boot configures the surefire-maven-plugin to ignore all
tests, that end with IT, the failsafe-maven-plugin has to be added to
automatically fire the new test - remember: you have to call "mvn verify"
to fire IT
Kai Moritz [Sat, 19 Sep 2020 10:46:52 +0000 (12:46 +0200)]
Added a working @ExceptionHandler
* Both handlers resolve the handled exception as 503 Internal Server Error
and are using the template "error/503", which was extended to print a
message, that the reported exception was catched and handled.
* If one starts the app, it is clearly visible, that the mechanism only
works for exceptions, that are thrown in the context of the controller.
* Also added a test-case, that shows, that MockMvc shows the expected
behaviour for exceptions, that are thrown inside the container.
Kai Moritz [Fri, 2 Oct 2020 17:39:00 +0000 (19:39 +0200)]
Fixed non-working test-cases
Kai Moritz [Sun, 27 Sep 2020 17:54:53 +0000 (19:54 +0200)]
Added spring-boot-devtools
Kai Moritz [Fri, 2 Oct 2020 13:46:09 +0000 (15:46 +0200)]
Adding expectations for the rendered output reveals annother misconception
* Added Jsoup to check some expectations regarding the rendered pages.
* This revealed another misconception about the behaviour of MockMvc.
* The MockMvc-environment does not render a full version of the White Label
ErrorPage, that Spring-Boot shows for uncaught exceptions.
Kai Moritz [Wed, 30 Sep 2020 06:42:38 +0000 (08:42 +0200)]
Refined the test: @ParameterizedTest adds no additional insight here
* The parameterized tests only test the difference between an empty and an
non-empty Optional.
* The actual number is meaningless, because the business logic is mocked
away anyway!
* Hence, the parameterized version only tests the correctness of our mocking:
The test could only fail, if we make a mistake in the setup of the
expectations, not in the code under test!
* Also splitted up some test-cases more logically.
Kai Moritz [Sun, 27 Sep 2020 09:23:03 +0000 (11:23 +0200)]
Further refined the example: Simplified the setup
* Goal: Do not rely on knowledge about Thymeleaf
* Goal: Separate MVC (controller) from business logic (service)
* Introduced an ExampleService
* The service checks the answer for
The Ultimate Question Of Life, The Universe And Everything
* Requests without any answer are tolarated, so that the page with the
question can be rendered
* Only numbers (Integer) are allowed as answer.
* Negative numbers are not allowed as answers: the service answers with an
empty Optional.
* The view contains a bug, that results in a 503 for negative answers:
Optional.get() is called, regardless of the state of the Optional
* The view renders the question, if no answer is specified (initial request!)
* If a valid request is specified, the answer and the outcome is rendered
* If an invalid request (negative number!) is specified, the view generates
an exception, because it tries to resolve the Optional anyway
Kai Moritz [Sat, 19 Sep 2020 08:24:44 +0000 (10:24 +0200)]
Refined the example, to clearify the intent
* Removed unnecessary Annotation from test
* Renamed and pimped up the example templates
* Splitted up the test in separate units
* Remapped the controller to the root of the web-context
* Switched to @WebMvcTest, to load only the controller-layer
Kai Moritz [Sat, 19 Sep 2020 08:11:41 +0000 (10:11 +0200)]
Renamed and repackaged the example for the blog-article
Kai Moritz [Sat, 19 Sep 2020 07:50:41 +0000 (09:50 +0200)]
Initial Commit: Spring-Boot-Project, that pinns down a bug in a test-case
* I stumbled accros the unexpected behaviour of Springs MockMvc in a
test-case for one of my projects.
* This version pinned down the unexpected behaviour explicitly.