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

Spring Boot: MockMvc returning strange responses

I have the following controller: RestApiController.java package com.spring.ocr.rest.restconsume.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import…
jbailie1991
  • 1,305
  • 2
  • 21
  • 42
0
votes
1 answer

JsonPath assertions type JSONArray

I'm trying to make a test validating one json using JsonPath, I could create the test, but when I validate what I got is probably a type error Expected: <[4]> but: was <[4]> my test is this: mockmvc.perform(get("/client/rating")) …
Luiz Rossi
  • 772
  • 5
  • 19
0
votes
0 answers

APPLICATION FAILED TO START (Spring MockMvc @WebMvcTest)

everyone. I am new to WebMvcTest, and am learning to write a PostControllerTest. While the project runs well, the test does not work. 2017-05-31 10:08:09.490 INFO 5768 --- [ main] nz.p2.controller.PostControllerTest : Starting…
Leo.W
  • 539
  • 1
  • 7
  • 18
0
votes
1 answer

Mock rest endpoint without instantianting controller class

I am mostly a Spring Boot user when it comes to making rest apis, so I am not always comfortable with classic Spring projects using xml configuration. However, I need to mock a rest endpoint for testing on that particular of project. There is also…
matthieusb
  • 505
  • 1
  • 10
  • 34
0
votes
1 answer

handling exception for RestAPI unit test

I have a method public class ActivityManager { private ActivityManager activityManager_; @Autowired public ActivityManager(ActivityManager activityManage) { activityManager_= activityManage; } @RequestMapping(value ="activityManager/",…
RLe
  • 456
  • 12
  • 28
0
votes
1 answer

java.lang.AssertionError when executing unit test

I got a java.lang.AssertionError when I was attempting to verify the href. The response body looks fine, MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[application/json;charset=UTF-8]} …
Frank
  • 5
  • 1
  • 4
0
votes
0 answers

Switch-off Spring REST Docs Snippets generation when executing unit-tests

Is there any mechanism to switch off snippets generation for Spring REST Docs (say any flag which can be configured) when executing unit-test cases ? I don't want to make changes at at each unit-test code level here.
Anurag
  • 51
  • 3
0
votes
2 answers

Spring security, test MVC and mock services

I want to test my controller, which has @PreAuthorize and also it has service which i want to mock PlayerController.java @RestController @RequestMapping(value = "/player") public class PlayerController { @Autowired private PlayerService…
Komdosh
  • 340
  • 3
  • 20
0
votes
1 answer

Integration and unit tests with MockMvc

According to the documentation there are two ways to do this: First: @RunWith(SpringRunner.class) @WebAppConfiguration @ContextConfiguration("my-servlet-context.xml") public class MyWebTests { @Autowired private WebApplicationContext wac; …
oscar
  • 1,636
  • 6
  • 31
  • 59
0
votes
1 answer

Spring-data-rest POST using Jackson Deserialization with same property name in nested objects

I am using spring-boot-starter-parent 1.3.3 and jackson-core-asl:jar:1.9.2. I am unable to create the object (Group) with person associated in it, because the group is created with the person name. The response likes the…
SST
  • 2,054
  • 5
  • 35
  • 65
0
votes
2 answers

SpringMVC Mockito Mocking values of class within class

I am trying to use mockito to mock the return value of method3() in class3 when i run the method try() in class1 from the testclass. I have restriction as to not being able to make any edition to the codes that i have. So, i cannot add in…
cleve yeo
  • 103
  • 2
  • 10
0
votes
2 answers

Unit testing spring rest controller error handling

I have a spring rest controller as detailed below @RestController @RequestMapping(value = "/data") public class DataController { private final IDataService service; private static final Logger LOG = Logger.getLogger(DataController.class); /** *…
Craig
  • 341
  • 2
  • 9
  • 18
0
votes
0 answers

In Spring Boot WebMvcTest @MockBean fails by not getting dependency

Test Class: @RunWith(SpringRunner.class) @WebMvcTest(MyController.class) public class MyControllerTest { @Autowired private MockMvc mvc; @MockBean private MyService myService; @Test public void testCreateEntit() throws Exception { ... …
Shafiul
  • 1,452
  • 14
  • 21
0
votes
0 answers

Can't upload multipart file with mockMvc

I can't figure out how to upload jpg file using mockMvc with spock. When i perform request manually with postman everything works fine and image uploads. I am using spring boot Here is the controller : @PostMapping(value =…
Filip P.
  • 1,194
  • 1
  • 7
  • 18
0
votes
1 answer

Spring HATEOAS and mockMVC, ignores consumes = MediaType.APPLICATION_JSON_UTF8_VALUE

After creating a service using Spring HATEOAS and testing it with mockmvc (also to generate documentation using Spring restdocs) we found the following. Our RestController looks something…
Wilfred Dittmer
  • 151
  • 2
  • 5