I'm trying to optimize step by step an example that I've got from the internet . So I started with the
Unit tests.
What I want is to write a Unit test with SpringBoot and
Mockito like the last example as here
https://spring.io/guides/gs/testing-web/.
In my code I have a controller, a DAO and a service. I would like to Unit test 2 methods of my controller e.g. the one with POST and the one with PUT.
But somehow the content is'nt submitted. The Database in the Background is MySQL5.7.25
following the controller's methods I want to Unit-Test:
I did'nt submit all the methods in the controller but these are the ones that I don't succeed to Unit-Test
then my service:
I did'nt submit the code of the Service Interface
my DAO (no code of the DAO Interface:
My Repo:
my Entity:
And finally my Tests with some out commented code due to some of my trials
Now my Problem:
the Tests are failing because somehow no content-body is submitted. On the console I have the following Testresults:
MockHttpServletRequest:
HTTP Method = POST
Request URI = /articles
Parameters = {}
Headers = []
Body = <no character encoding set>
Session Attrs = {}
MockHttpServletRequest:
HTTP Method = PUT
Request URI = /article/2
Parameters = {}
Headers = [Accept:"application/json;charset=UTF-8"]
Body = <no character encoding set>
Session Attrs = {}
My question: What I'm doing wrong?I know that I'm mocking wrong but what?
Many Thanks for helping!
PS:the application is working fine. I can add and update the articles in the database. Only the tests don't work.
Many thanks in advance.