I am getting status expected but was getting error. I have updated the content-type in the header to : application/json. Please suggest if I am missing something. My exact code is : String payload =""; //some json payload MvcResult result = mockMvc.perform(post("/abc/xyz").header("Content-Type","application/json") .contentType(MediaType.APPLICATION_JSON).content(payload) .accept(MediaType.APPLICATION_JSON)) .isExpect(status().isOk()).andReturn();
Is this post API you are trying , u believe 415 means bad request something going wrong in your request Do one thing In payload , try to pass your actual object after converting it to string Use new ObjectMapper().writeValueAsString(payload);
@@Javatechie Yes, This is a post API I am trying. Since the payload is a string in itself so using new ObjectMapper().writeValueAsString(payload); i.e converting it into again into a string does not suffice
Nice but can you explain in more detail What is Mokito, MockMVC, @before, MockMVC Builders etc...and when to use and how Boot will invoke this ...some at very beginner level? Also, why do we need to use MockMVC and can we do it normal jUnit and what are the advantages of using MockMvc? (Sorry I am new in testing and yeah so boring topic for any developers).
Hi Bimal, Normally we are writing test case for both controller and service layer . For controller we need to use mockMVC where for service or Dao we need to use Mockito Already I have uploaded video for both layer please have a look
@@Javatechie most of the videos on TH-cam is not showing how to work on fail queues .. your example can have list of objects like 100 records from CSV file that are sent to the queue and store them in database while reading back from queue and due to network issue or any other issue the messages should go to the failed queues and later read back from it. . Your examples are always unique .
@@seetaramaraotaduri90 thanks for giving me wonderful scenario . Definitely I will do this .but before that I would like to introduce small content on retry mechanism else it confuse user to understand queue with retry . Make sense ?
How to pass Boolean value in setter ???? Like if we writter in setter as Boolean success .....then in junit case ....how to pass Boolean value in ...setter ????
Hi sir if you have an application that is based on real time project and if you used the junit test case for that project then please add the link , because i don't know how to check the list of data that is coming form the Database , i want to test of that data , so please add the link sir or even you can upload in the face book group . Please sir , i have need of this .
@@Javatechie for statements like squery=squery.replace("", pid); System.out.println(squery); return jdbcTemplate.query(squery, (rs, rowNum) -> new StudyUID( rs.getInt("PERSON_ID"), how to write test case for this scenario?
@@Javatechie i am getting error :com.fasterxml.jackson.databind.exc.MismatchedInputException Cannot deserialize my response class. what could be the possible solution?
Please I request to do Mockito testing for Repository layer i am not getting any good article I am stuck 1 question i,e when we are testing controller layer we should mock repository layer also na sir but u have not mocked Thank You.
Could you please mention your exact issue? R u talking about which method ? If you are getting 415 then it's media type issue . please cross verify once Did you specified media type as application/json in headers and in controller URL mapping .?
Well this is not unit testing You are creating an client for rest apis If your are writing test cases for controller layer then service layer should be mocked
I completely understand your concern buddy what I am trying to convince that beginners do watch my videos who started learning from basics so if anyone already advanced then he/she have option to skip and watch the videos from where they really need . Hope this makes sense
Java Techie, while running test cases i get fallowing exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
dude this tutorial worked like a charm....keep the good work going....saved my day at work......thanks.....!!!!!!!
13:27 setup mockmvc
16:57 result = mockMvc.perform(post("/url")) method
20:10 result.getResponse().getContentAsString();
20:41 Response.class
Could you please elaborate what you want to convince ?
Java Techie This is for my reference. If I need to see this video again, i can only see important points of video.
@@avijitsharma5050 got it , cool
Excellent, All your video are relevant to the industry usage. Really helpful. Thank you.
Been watching a few of your videos. Really good content.Thanks for the effort.
Very nice explanation. Thanks for the knowledge sharing.
Life saver. Best out there.
Thank you for the inspiration at the beginning of the video :)
nice work bro keep it up
Bhai you are God ❤️
hi ur explaination is real good
Your knowledge is top, but please give clean description about what your doing and what is the each work it will reach bigners also thank you.
Cool going forward i will take care of that
You are a best tutor Basant. Awesome. Could you please make a video on ReactJS?
I will start this series soon 🙂
Good Tutorial
@Java Techie , I had given the return type as string in controller class for post method
What i should i do for that
Thank you very much for this video
Thank you. This video more help to me
good tutorials, try to improve the microphone quality maybe, it'd be great
I Really appreciate your support and interest definitely going forward I will improve it
I am getting status expected but was getting error. I have updated the content-type in the header to : application/json. Please suggest if I am missing something.
My exact code is :
String payload =""; //some json payload
MvcResult result = mockMvc.perform(post("/abc/xyz").header("Content-Type","application/json")
.contentType(MediaType.APPLICATION_JSON).content(payload)
.accept(MediaType.APPLICATION_JSON))
.isExpect(status().isOk()).andReturn();
Is this post API you are trying , u believe 415 means bad request something going wrong in your request
Do one thing
In payload , try to pass your actual object after converting it to string
Use new ObjectMapper().writeValueAsString(payload);
@@Javatechie Yes, This is a post API I am trying.
Since the payload is a string in itself so using new ObjectMapper().writeValueAsString(payload); i.e converting it into again into a string does not suffice
Can you show me your controller class
@@Javatechie How to since we work on remote desktops.can share via image but unable to upload in here
very good video
I like YOUR COMMENTS ON YOUR DESKTOP SCREEN... :)
Nice but can you explain in more detail What is Mokito, MockMVC, @before, MockMVC Builders etc...and when to use and how Boot will invoke this ...some at very beginner level? Also, why do we need to use MockMVC and can we do it normal jUnit and what are the advantages of using MockMvc? (Sorry I am new in testing and yeah so boring topic for any developers).
Ok I will create one Integration test video there I will explain all required annotation.
nice explanation ...bro
JUnit is excluded in latest spring web starter package. Need to use JUnit Jupiter so can you create a video with that.
Spring boot 2.x onwords it used Jupiter
You no need to add it manually
hi sir I have a doubt on Junit Test cases writing on Only For a controller or service Layer ?
Hi Bimal,
Normally we are writing test case for both controller and service layer .
For controller we need to use mockMVC where for service or Dao we need to use Mockito
Already I have uploaded video for both layer please have a look
Will junit testing hit database?or we should mock that..
If you won't mock it will hit the db
Thanks for this wonderful video
Can you make video on sending objects into rabbitmq and if it fails placed them on failed queues using spring boot retry
Yup i can , as I noticed maximum viewers suggested for active Mq let me give a try
@@Javatechie most of the videos on TH-cam is not showing how to work on fail queues .. your example can have list of objects like 100 records from CSV file that are sent to the queue and store them in database while reading back from queue and due to network issue or any other issue the messages should go to the failed queues and later read back from it. . Your examples are always unique .
@@seetaramaraotaduri90 thanks for giving me wonderful scenario .
Definitely I will do this .but before that I would like to introduce small content on retry mechanism else it confuse user to understand queue with retry .
Make sense ?
@@Javatechie thank for your reply .. yes I agree start with a small example and later can elaborate on this .
want to know how to use Mockito.when() , thenReturn() and Mockito.verify() in this example.i dont want to affect the db while executing Database
Already I created another mockito tutorial please check that
@@Javatechie ok I'll look into it
Thank you
Thanks bro
I am getting 400 in my project.writevalueasString not generating proper JSON .I am coping same JSON and hitting a APi through postman but not working.
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
Try including this
How to write test case for controller method having return type ResponseEntity . Plz help..
which short cut you are using for indendation...I mean after select+All which key you are using for auto-idendation
@javatechonline. i want to mock service layer also so that it doesn't hit actual db layer
Can we mock the DAO in the flow above?
Please make video on test service and repository class
Can you see the data in the database that was created by junit test first case
Does it hit database in every call???
No it won't that's why we mock the Dao
@@Javatechiewould the junit work if we create controlTest.java and execute there insteam of mainTest.class??
If we do not have response class, what should we use instead of it?
You need to design this based on your return type
@@Javatechie have you used JUnit4?
Yes I used
How to pass Boolean value in setter ???? Like if we writter in setter as Boolean success .....then in junit case ....how to pass Boolean value in ...setter ????
Hi sir if you have an application that is based on real time project and if you used the junit test case for that project then please add the link , because i don't know how to check the list of data that is coming form the Database , i want to test of that data , so please add the link sir or even you can upload in the face book group .
Please sir , i have need of this .
You need to mock your dependencies like database with Mockito library
under @autowired, what is "WebApplicationContext Context"? is that a class and its object that you have created? or it has to be mandatorily written?
Yes you must need to autowire this class to kick start test web context
@@Javatechie for statements like squery=squery.replace("", pid);
System.out.println(squery);
return jdbcTemplate.query(squery, (rs, rowNum) -> new StudyUID(
rs.getInt("PERSON_ID"),
how to write test case for this scenario?
Please checkout below tutorial and mock your dao class
th-cam.com/video/kXhYu939_5s/w-d-xo.html
@@Javatechie i am getting error :com.fasterxml.jackson.databind.exc.MismatchedInputException
Cannot deserialize my response class. what could be the possible solution?
Thankyou !
Use @Data - lot easier than adding @Getter and and and
Testing starts at 11:25
Basanta bhai your video is so nice but the problem is visibility,plz go through it.
Hi Rabindra, Thanks for your update it depends on your internet connectivity so please try to connect with good internet it will run on HD mode
Can u please upload the exact code in git ...the link u posted for this is quite different
Hi..m getting error like content type is missing...please suggest
Did you mentioned media type as application/json in header
@@Javatechie I mentioned that one
Please follow same what I did .still if u r facing same issue then please share ur code in javatechie4u@gmail.com
com.fasterxml.jackson.databind.exc.MismatchedInputException
Cannot deserialize my response class
@@Javatechie i have sent the code...Please check once
what you dont have a service laye in your project ?
Hi Basma , it's good practice to write service layer in your application .
But in my max video am not writing service layer to avoid time duration
@@Javatechie u dont have plz an example for unit test for controller layer where u used (u moked ) the service layer in it ?
Please I request to do Mockito testing for Repository layer i am not getting any good article
I am stuck
1 question i,e when we are testing controller layer we should mock repository layer also na sir but u have not mocked
Thank You.
No we shouldn't mock repository if you are writing test case for controller
@@Javatechie
Y ?
Please make mockito testing for repository layer
Okay i will do that using test container
can you tell me when to mock repository or when to mock service , in this video you are mocking service ?
Hi Basant. Will you please use microphones, your voice is too low in all your videos.
I agreed Shruti , these are old videos but in recent videos voice and video clarity both are good .
thanks
you tell wrong input statement for recovery this error status code 415 but i cant understand. ..please help me
Could you please mention your exact issue?
R u talking about which method ?
If you are getting 415 then it's media type issue . please cross verify once
Did you specified media type as application/json in headers and in controller URL mapping .?
@@Javatechie i get this...changes content to contentType fix this issue
Please share the spring annotations document.
can you pls share the complete src
In video description I mentioned my GitHub link so you download my code
Well this is not unit testing
You are creating an client for rest apis
If your are writing test cases for controller layer then service layer should be mocked
This is integration test Manish
@@Javatechie headline to Junit laga rakha hai...
Its giving me the NullPointerException
Please checkout my source code
setup or creating new object was not supposed to be part of this tutorials. that could have been created already
Yes agree but it's demo need to cover from scratch
@@Javatechie someone who wants to learn mockito, would already know those basics
I completely understand your concern buddy what I am trying to convince that beginners do watch my videos who started learning from basics so if anyone already advanced then he/she have option to skip and watch the videos from where they really need . Hope this makes sense
@@Javatechie fair enough. thank you
This is not unit test
This is integration test
You need to mock all your dependencies in this case respository
very low voice pls fix
Buddy these are my old videos please coperate
Inject context into your code is a very bad practice
Sorry didn't get you , you mean injecting WebApplicationContext in junit
Light Mode? How dare you...
boring
Thanks 😊
Java Techie, while running test cases i get fallowing exception
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
Please reimport your pom and error says dependency is not available at runtime