Questions tagged [spring-test-mvc]

spring-test-mvc based on spring-test provides a unit testing framework for spring-mvc services.

spring-test-mvc based on provides a unit testing framework for services.

spring-test-mvc might be included in the Spring Framework version 3.2.x

Spring One DC 2012 slides

356 questions
3
votes
3 answers

MockMvc test POST request

I have the following post route in my REST controller: @RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json") public ResponseEntity saveMovie(@RequestBody Movie movie){ …
user2693135
  • 1,206
  • 5
  • 21
  • 44
3
votes
2 answers

Junit test hangs up on my async thread

I am fork a new thread on my service's @Postconstruct method, and in the new thread, a infinite loop is running. My test is just invoke the service using spring mvc test: ResultActions result = this.mockMvc.perform(post("/test").with(httpBasic(user,…
Cherry Zhang
  • 101
  • 1
  • 11
3
votes
1 answer

Spring MVC Test with Hamcrest: how count and test the properties number/size of an object inside a Model

For Spring MVC Test (working together with Java Hamcrest): Testing the scenario where is necessary render a jsp file with a Model object which only contains an instance of the Person class I have the following (works fine):…
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
3
votes
1 answer

How to do integration tests on Spring Controller Advice

The title explains my question 100%. Let assume there is @ControllerAdvice annotated class in Spring Boot/MVC. In my case it contains @ExceptionHandler annotations. Ok, I can do unit-test of this class (it returns formatted JSON with information…
3
votes
1 answer

Error while creating spring MockHttpServletResponse, MissingResourceException even after adding javax.servet-api dependency

I am writing test for a servlet filter using spring MockHttpServletResponse and request. I am getting the following error while creating MockHttpServletResponse object. Caused by: java.util.MissingResourceException: Can't find bundle for base name…
user3565529
  • 1,317
  • 2
  • 14
  • 24
3
votes
2 answers

Simulate Anonymous Authentication in Spring MVC Unit Test

I am trying to write a unit test for a guest user account. The code under test checks guest by calling this method, which in Unit Test returns null for the guest account. /** * Determines if the user is a guest account. * * @return True if the…
Richard G
  • 5,243
  • 11
  • 53
  • 95
3
votes
0 answers

Apache Camel Integration test results in OutOfMemory

I have a simple Camel route that sends data to an external REST interface, integrated with Spring MVC. @RestController public class MyController { @Autowired private camelService camelService; @RequestMapping(method =…
Leo
  • 1,016
  • 1
  • 13
  • 32
3
votes
2 answers

Why aren't my Spring Controller's request mappings working inside of a mock WebApplicationContext?

I'm working from the Spring documentation here. My goal is to use the "webAppContextSetup" option to test my spring configuration along with my controller, but I'm having trouble getting the controller's methods mapped inside of the…
user3596946
3
votes
1 answer

Spring security DefaultMethodSecurityExpressionHandler bean is not registered for Integration Test's default spring security config

I am attempting to write Spring MVC integration test with Spring Security and Thymeleaf for the view layer. I have setup my MockMvc object with Spring Security Integration just like all the examples from the documentation. Integration Test…
3
votes
0 answers

Spring Rest locale test not working

I am trying to test localization. My configuration is as given below @Bean public MessageSource messageSource() { ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); String[]…
Rohit
  • 353
  • 2
  • 8
  • 24
3
votes
1 answer

Is it possible to use MockMvc without SpringJUnit4ClassRunner?

I want to use MockMvc without SpringJUnit4ClassRunner. public static void main(String[] args) { WebApplicationContext wac = ...; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } Since main is not invoked by a…
jack
  • 1,861
  • 4
  • 31
  • 52
3
votes
2 answers

Spring MockMVC - How to mock custom validators running outside of controllers

@UsernameAlreadyExists private String username; I have a custom validator that I created to ensure that duplicate usernames are caught by the application when account creation form submits. When I unit test the account creation controller using…
led
  • 611
  • 4
  • 11
  • 18
3
votes
2 answers

Testing with spring-test-mvc jsonpath returns null

I am using Spring's "spring-test-mvc" library to test web controllers. I have a very simple controller that returns a JSON array. Then in my test I have: @Test public void shouldGetAllUsersAsJson() throws Exception { …
jsf
  • 2,851
  • 9
  • 30
  • 33
3
votes
2 answers

How to test POST spring mvc

My problem is to how to call this. I could do MyObject o = new MyObject(); myController.save(o, "value"); but this is not what I would like to do. I would like the MyObject to be in the request post body? How can this be…
pethel
  • 5,397
  • 12
  • 55
  • 86
2
votes
1 answer

How to specify date format for MockMvc standalone setup

I have an endpoint like this: @GetMapping("/path") public ResponseDTO> getProgramsByUserId(@PathVariable String userId, Pageable pageable, …
eternal
  • 339
  • 2
  • 15