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
3
votes
2 answers

How to print only the requests of the failed test with @AutoConfigureMockMvc?

In our project we are using @AutoConfigureMockMvc with printOnlyOnFailure left as default, true. This works fine and prints none of the requests… except if any test fails. At that point, it prints all requests from ALL tests that have been executed…
Didier L
  • 18,905
  • 10
  • 61
  • 103
3
votes
1 answer

How to run controller test classes in order with spring integration test

Running controller test classes in order. I have this test classes below. @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc(addFilters = false) public class UserControllerTest { @Autowired private MockMvc mockMvc; …
Mehmet Bektaş
  • 173
  • 1
  • 2
  • 15
3
votes
1 answer

Test static content with MockMVC in Spring Boot with Slice

I'm trying to figure out a way to test with MockMVC the serving of content using a WebSlice that only autoconfigs org.springframework.web.servlet.resource.ResourceHttpRequestHandler (and not controllers) I've tried something like…
Chris DaMour
  • 3,650
  • 28
  • 37
3
votes
1 answer

Spring MVC 4.2 : How to Unit Test Controller with @RequestPart Params

I have a requestMapping of the form: @RequestMapping( value = "/submitCase", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.POST ) public Object submitCase( …
user3762085
  • 31
  • 1
  • 3
3
votes
2 answers

Mockmvc for a DELETE method that accepts a Multipart file

I'm trying to write a unit test for a controller that has a DELETE method that should accept a File and a text param. I know I can do a simple delete like that: MvcResult result = mockMvc.perform(MockMvcRequestBuilders.delete( …
riorio
  • 6,500
  • 7
  • 47
  • 100
3
votes
2 answers

Difference with unit testing controller and service method

I wanted to test same method from controller and service layer. The question is: Why do I have to use @MockBean annotation in controller, why not @Mock annotation for BookFindOperationsService bookService. Same question for service, why do I need to…
pipilam
  • 587
  • 3
  • 9
  • 22
3
votes
1 answer

MockMvc + Hamcrest: inconsistent collections for floating point numbers

I would like to implement a test that checks that my filter for a floating point variable works well. I send the filter and expect the collection to have values only below the defined value. final Double orderPrice = 0.0; …
user1921819
  • 3,290
  • 2
  • 22
  • 28
3
votes
3 answers

JSONObject Expected to find an object with property ['XXX'] in path $

I have made a program to consume a third part API: I have a service Called:NewsService @Service public class NewsService { @Autowired private NewsRepository newsRepository; public List getTopStories() throws Exception{ …
3
votes
1 answer

How to resolve MethodArgumentConversionNotSupportedException with MockMvc?

I'm writing a unit test for a controller method that accepts a MultipartFile and a custom object MessageAttachment. So far I can see that the MultipartFile is the correct format for the request but the MessageAttachment is not. The parsing of the…
Brian Var
  • 6,029
  • 25
  • 114
  • 212
3
votes
0 answers

Spring Integration test - request Timeout MockMvc

I am trying to write some integrations tests, and I want to introduce a timeout exception in one case. So, my question is, how can I introduce a delay in the mockMvc.perfrom method? I found this example but it's not suitable to MockMvc. Any…
pik4
  • 1,283
  • 3
  • 21
  • 56
3
votes
1 answer

Adding model attribute to spring MockMvc call

I'm writing a test for a simple controller. The controller checks if the modelattribute "ADDED_OBJECT" exists and returns a success page and an error page when the modelattribute is missing. Testing the error path is no problem but I don't know how…
Patrick Adler
  • 196
  • 2
  • 9
3
votes
1 answer

How to test if a controller method forwards the requests to a specific URL?

In my Spring Boot application I have the following controller with a single method that redirects all HTML5 routes to the root URL**: @Controller public class RedirectController { @RequestMapping(value = "/**/{path:[^\\.]*}") public String…
Boyan Kushlev
  • 1,043
  • 1
  • 18
  • 35
3
votes
1 answer

How test CORS in Spring Boot? When I try in MockMvcBuilders, it always returns 200 despite Origin being wrong

The below tests (I included two classes to see if either one would work) both have no issues calling the controller. I want it to reject with a CORS issue as I have not added any CORS config. (I then want to test with a CORS config and have that…
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
3
votes
1 answer

Spring boot's actuator unavailable when set management port

I use Spring boot + Spring Security + Spring Actuator My JUnit test class: @RunWith(SpringRunner.class) @SpringBootTest() @AutoConfigureMockMvc public class ActuatorTests { @Autowired private MockMvc mockMvc; @Test …
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
3
votes
2 answers

Spring 5.0.0 MockMvc: Unsupported media type, even with correct MediaType set

I am using JUnit4 with Spring Web MVC Test and I have test class for a Controller. The Controller handles a POST request to "/test" with JSON body content. I've tested this method manually using Postman and I get a 400 Bad Request response, as…
the duck wizard
  • 105
  • 2
  • 8