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
9
votes
1 answer

Does the new Spring MVC Test Framework released in Spring 3.2 test the web.xml configuration?

I've read the docs ( http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/testing.html#spring-mvc-test-framework ) several times and I can't confirm if the WebApplicationContext context that gets injected when you use the…
Ryan Walls
  • 6,962
  • 1
  • 39
  • 42
8
votes
4 answers

How to retrieve data directly from Spring test MvcResult json response?

I want to retrieve a value from json response in order to use in the rest of my test case, here's what I'm doing now: MvcResult mvcResult = super.mockMvc.perform(get("url").accept(MediaType.APPLICATION_JSON).headers(basicAuthHeaders())) …
Mohamed Ibrahim Elsayed
  • 2,734
  • 3
  • 23
  • 43
8
votes
2 answers

How to mock multiple responses for same request using spring's MockRestServiceServer?

Im using MockRestServiceServer for mocking http responses. In a specific scenario i call an endpoint two times and want a different response the second time. But when i write a second expectation it's like it overwrites my first expectation. How…
8
votes
1 answer

Spring Test Service Autowiring resulting in null

I am able to run a Rest Controller PUT method that uses a Autowired @Service as expected via the Spring Boot Application. The same Autowiring is failing while trying to perform a Spring JUnit Test. I have tried reading through multiple threads with…
Satya
  • 1,037
  • 3
  • 15
  • 34
8
votes
1 answer

Testing security in Spring Boot 1.4

I'm trying to test @WebMvcTest with custom security settings defined in SecurityConfig class: @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void…
dmunozfer
  • 550
  • 1
  • 5
  • 16
8
votes
3 answers

Autowiring not working in Spring 3.1.2, JUnit 4.10.0

Using Spring 3.1.2, JUnit 4.10.0, and pretty new to both versions. I'm having the problem that I can't get the annotation-based autowiring to work. Below are two samples, the one not using annotations, which is working fine. And the second one using…
Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192
7
votes
2 answers

How to use random port for JUNIT Testcases using Spring Boot 1.4.0 +

I am using spring boot 1.3.6 and my JUNIT Test cases are running fine, after upgrading to spring boot 1.4.0 and attempting to remove deprecated classes is throwing me error My JUNITCLASS with…
rajadilipkolli
  • 3,475
  • 2
  • 26
  • 49
7
votes
1 answer

Setting session attributes for JUnits on Spring 3.2

I'm having trouble setting session attributes for a test. I am using MockMvc to test calls to a controller. The session model has a member attribute on it (representing the person who has logged in). The SessionModel object is added as a session…
Ash McConnell
  • 1,340
  • 1
  • 17
  • 28
6
votes
2 answers

Spring Boot @WebMvcTest vs @SpringBootTest

I have a simple health controller defined as follows: @RestController @RequestMapping("/admin") public class AdminController { @Value("${spring.application.name}") String serviceName; @GetMapping("/health") String getHealth() { …
belgoros
  • 3,590
  • 7
  • 38
  • 76
6
votes
1 answer

Is there a way to use @MockBean annotation while working with Spock framework

I was trying out Spock and encountered an interesting problem when writing controller-tests. WebMvcTest(value = SomeController.class) @AutoConfigureMockMvc @ActiveProfiles(value = "restapi") @Import(value = SecurityConfiguration) class…
pannu
  • 518
  • 7
  • 20
6
votes
0 answers

InstanceAlreadyExistsException for EnvironmentManager when trying to start Spring Boot application in plain Spring test

I have simple web application: @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } @RestController public class SimpleController { …
6
votes
1 answer

How to enable controller parameter validation for standalone MockMvc

Controller @RestController @Validated class MyController { @GetMapping("/foo") public String unwrapped(@Min(1) @RequestParam("param") int param) { return Integer.toString(param); } @GetMapping("/bar") public String…
Bax
  • 4,260
  • 5
  • 43
  • 65
6
votes
1 answer

Use MockMVC outside SpringBoot application

I have an application that uses Spring MVC for running a REST service (without Spring Boot). Context is mainly loaded from the parent's one. I have a controller and I would like to test it via MockMvc. I have tried to set up local test context…
ryzhman
  • 674
  • 10
  • 22
6
votes
2 answers

Spring Boot - Test - Validator: Invalid target for Validator

I'm getting the following error when I'm trying to run a test: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Invalid target for Validator [userCreateFormValidator…
AleGallagher
  • 1,745
  • 7
  • 30
  • 40
6
votes
3 answers

How can I debug processing of hibernate.hbm2ddl.import_files value combined with hsqldb?

In a Java project I'm working on I've got the following setup for our unit tests: I'm using Spring Test MVC, @RunWith(SpringJUnit4ClassRunner.class) and @WebAppConfiguration to run the unit tests, and I create a MockMvc instance using…
1 2
3
23 24