• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Why does'nt my mockMvc submit any content?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!