Questions tagged [mockmvc]

MockMVC is the key part of the Spring MVC Test framework is. It simulates the internals of Spring MVC.

MockMVC is the key part of the Spring MVC Test framework is. It simulates the internals of Spring MVC.

742 questions
0
votes
1 answer

Using Try Catch inside JUnit Test Case

Initially, I'm using MockMvc in Java Spring Boot Junit testcase. I'm sending a JSON with a message as Success {"message": "Success"}, if the message is not Success, without throwing an AssertionError Exception. It should check the message Failure…
Lakshan G
  • 366
  • 3
  • 9
0
votes
0 answers

Spring Boot mock MVC assertion error:Content type not set

I am getting the following error trace, when I run a JUNIT method for HTTP PUT request in Spring boot. The input JSON value is successfully passed to the service method. However, I am not getting any response in HTTP servlet response. When I hit the…
Vidhya
  • 1
  • 2
0
votes
2 answers

How to mock public API (Third Party API) to generate spring restdocs

I am able to generate restdocs for rest services which is created by me, but unable to generate docs for services which i am consuming. Is there any way to test and generate docs for third party API. Sample code which i am using to generate to docs…
Vikash
  • 643
  • 7
  • 13
0
votes
1 answer

java.lang.AssertionError: JSON path expect different result

I have a Junit test which works with mockMvc, and it happens something weird. My test case looks like that... @Test public void getSignatureData() throws Exception { String dataXValues = "[0,5,10,15,20]"; String dataYValues1 =…
Lady Hams
  • 1
  • 3
0
votes
1 answer

Spring MockMvc not taking roles into account

I have API endpoints which require a user to hold a specific role. Therefore, in some of my tests I attempt to reach these endpoints and expect a 401 error, however I get 200. I am using MockMvc to perform the calls. The following are some snippets…
D. Gal
  • 329
  • 2
  • 14
0
votes
1 answer

How can I pass a object using MockMvc as a RequestBody?

So here is the scenario and problem I am facing explained in code // the call that I am making in my test, please note that myService is a Mocked object Foo foo = new Foo(); when(myService.postFoo(foo)).thenReturn(true);…
katiex7
  • 863
  • 12
  • 23
0
votes
1 answer

MockMVC- Form Submit Spring controller from dropdown

Can anyone asssist how to write mockMVC for the controller? I have come up with mockMVC however i am stuck and not sure how to test further From UI User selectes from the drop down and does the form submit with select ID as name (which is…
kulu makani
  • 1
  • 1
  • 2
0
votes
1 answer

Spring Boot Unit Test of RestController POST method Expected :201 Actual :400

I'm trying to set up a unit test for my RestController, but for the post method I always retrieve status 400 instead of 201. I don't see what is wrong. The rest service is working fine using curl. Also the passed JSON is the same as i pass to my…
Francesco Iannazzo
  • 596
  • 2
  • 11
  • 31
0
votes
1 answer

java.lang.AssertionError: No value at JSON path "$.version" mockMVC

I written test mockMVC method get i have this following bug what is bad in my code? what i can fixed it?
martine
  • 79
  • 2
  • 3
  • 10
0
votes
1 answer

When/thenReturn not mapped

I can't understand why my when/thenReturn is not mapped to the mocked bean. During the debug I can see that the "userDto" after the line "UserDTO userDto = userService.update(id, entity);" in the tested controller is equal to null. Any idea what…
0
votes
1 answer

Springboot test not return expected result

all developers, my team is creating a microservice to get the property information using springboot. We have a test suite to mock up the process of making a Http request and verify the response which returns a property information in a stub class.…
edison ouyang
  • 109
  • 1
  • 8
0
votes
1 answer

Is it possible to use MockMvc and mock only the RestTemplate used by my service?

I'm trying to build one integration test using MockMvc and I want to mock only the RestTemplate used by MyService.java. If I uncomment the code on MyIT.java, this test will fail because the RestTemplate used by MockMvc will be mocked as…
0
votes
1 answer

How To Handle Exception in Test Case

@RunWith(SpringRunner.class) @WebMvcTest(MyController.class) @ContextConfiguration(classes = Application.class) public class MyControllerTest { @Autowired MockMvc mockMvc; @MockBean EmployeeService employeeService; @MockBean EmployeeRepo…
0
votes
1 answer

Spring security custom UserDetails not authenticating

while experimenting around with spring boot, security, and data. i just came across this scenario: i use H2 in memory DB and poblate it with one user with liquibase on startup with username and password. now i want spring security to authenticate…
0
votes
1 answer

Why is authentication not being propagated in spring mockmvc unit test?

I'm trying to test some oauth endpoints following this guide, http://engineering.pivotal.io/post/faking_oauth_sso/. I created a method getOauthUserAuthentication() which returns an oauth2 authentication object with principal 'vince' and authority…