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

WebMvcTest: Migrating from WebSecurityConfigurerAdapter to SecurityFilterChain

As described here Spring Security deprecated WebSecurityConfigurerAdapter which I've been using for some time. I used the component based approach and introduced SecurityFilterChain and InMemoryUserDetailsManager beans (see: commit) but then one of…
pszemus
  • 375
  • 2
  • 10
2
votes
0 answers

How to test module when it needs Application.class and one is ine the other module?

I have multi-modules gradle project which has follows structure: Module-A main java com.example.project.main Application.class Module-B main java com.example.project.other …
Zhenyria
  • 376
  • 1
  • 16
2
votes
1 answer

Run Tests SpringBootTest from executable jar in command line

I need to run a jar with all tests in it. I could build all test classes inside jar but I don't know how to boot a main class to run junit tests in springboot. Is it possible I run a command line to run jar and start all test and ignore…
Dilermando Lima
  • 1,004
  • 8
  • 21
2
votes
2 answers

How to use spring security in integration tests?

I have a following WebSecurityConfigurerAdapter implementation: @Configuration @Order(0) @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private static final List permittedPaths = asList(); …
Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
2
votes
1 answer

Mock JWT AuthenticationPrincipal while testing REST end points

We are building REST API and adding AuthenticationPrincipal as method argument @Override public ResponseEntity listProduct( @Valid @RequestParam(value = "fields", required = false) final String fields, @Valid…
Dheeraj Joshi
  • 3,057
  • 8
  • 38
  • 55
2
votes
1 answer

@WebMvcTest Error creating bean with name 'securityConfiguration'

I have a spring boot rest application where I use JWT for authentication and it works fine when I just start the application. I just wanted to add some test cases but I could not solve this problem (I run the test cases with mvn test : Error states…
monstereo
  • 830
  • 11
  • 31
2
votes
1 answer

Mocking two Users at once for testing a 2-player Game?

Below is my test suite so far for my MVC app. I'm using Spring Security for authorization, and so far have been able to use the @WithMockUser annotation to take care of it in testing (user1 creates games in testCreateNewGame(), and user2 joins one…
2
votes
1 answer

How can I test a secured endpoint with Awaitility in Spring boot?

I'm using spring boot and I want to assert an asynchronous side effect by calling a secured endpoint with MockMvc. I have been using Awaitility, but apparently the mocked security context is lost when executing in a different thread. I couldn't find…
jcfandino
  • 320
  • 5
  • 12
2
votes
2 answers

WebMvcTest is too greedy

I want to write a WebMvcTest test for a single controller in my Spring Boot application. Among other things there are some custom Converters in my application. Although they are not needed for this particular controller that I want to test, Spring…
Nikem
  • 5,716
  • 3
  • 32
  • 59
2
votes
0 answers

spring @MockBean HttpSession - No qualifying bean of type 'javax.servlet.http.HttpSession' available

I inject the HttpSession into my controller with @Autowired: @RestController public class MyController { @Autowired private HttpSession httpSession; @GetMapping("hello") public String getHello() { return "hello " +…
nagy.zsolt.hun
  • 6,292
  • 12
  • 56
  • 95
2
votes
1 answer

Snapshot testing in Spring MVC test

Is there any existing solution for doing snapshot testing [1] in Spring MVC test (MockMvc)? Something like: this.mockMvc.perform(get("/users") .andExpect(status().isOk()) .andExpect(content().contentType("application/json")) …
2
votes
3 answers

MockMvc Integration Test with List of Object as Request Param

I am working on a REST service using Spring MVC which takes List of Object as request parameter. @RequestMapping(value="/test", method=RequestMethod.PUT) public String updateActiveStatus(ArrayList testList, BindingResult result)…
2
votes
1 answer

Environment getProperty("SomeValue") value is coming null with Spring test and Mockito

I am writing JUnits for controller classes. I am using @PropertySource("classpath:webmvc_test.properties") and Environment object to read the values from properties file. On calling getProperty() method getting null value. The property file…
user995656
  • 123
  • 1
  • 14
2
votes
1 answer

Spring, different behaviour when testing

I'm experimenting with Spring Web and testing a REST controller. The application is basically a game database accessible through a web service. When I launch it and test it with Postman to add a game, I get the behavior I'm looking for. However,…
gaucib
  • 465
  • 4
  • 8
2
votes
0 answers

Spring Boot Server and Client testing. Is it possible to combine them to achieve something like this?

Combining server testing MockMvc, and client testing @RestClientTest. Is this possible or will they always clash with each other? @AutoConfigureMockMvc @RestClientTest(BackendApiClient.class) public class ApiGatewayControllerTest extends ApiTest { …