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
1
vote
2 answers

How to add query parameters to mockup in Spring Boot 2.0 with MockMvcRequestBuilders

I'm trying to do a simple test class using MockMvc. But I'm stuck in a really simple thing (but the docs doesn't help). My basic code is @SpringBootTest @AutoConfigureMockMvc class RecommendationServiceApplicationTests { private static…
Sourcerer
  • 1,891
  • 1
  • 19
  • 32
1
vote
1 answer

Spring Integration Tests for Resource Server (based on spring-cloud-starter-oauth2)

I am using Spring Boot and Spring Cloud for a oAuth2 resource server. This is the configuration: pom.xml org.springframework.boot spring-boot-starter-web
1
vote
0 answers

Spring Boot does not throw HttpMessageNotReadableException

There is a simple loginController with loginRequest annotated with @RequestBody @RestController public class LoginController{ @PostMapping("/login") public ResponseEntity doLogin(@Valid @RequestBody LoginRequest loginRequest,…
monstereo
  • 830
  • 11
  • 31
1
vote
2 answers

MockMVC adds additional quotes with string in request param with post request

MockMvc adds quotes at the ends of string when passed in param() in request builder like following // initialization of mockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); ObjectNode tweets = ((ObjectNode)…
It's K
  • 177
  • 3
  • 15
1
vote
1 answer

How to check values in response body with mockMvc - AssertionError: Status expected:<201> but was:<400>

im new to test writing and i am trying to write junit tests for my controller class using mockMvc. Here are my classes: public class StudentDTO { private final String firstName; private final String lastName; private final String JMBAG; private…
Sinor Bodl
  • 73
  • 2
  • 11
1
vote
2 answers

Kotlin + SpringBootTest + Junit 5 + AutoConfigureMockMvc: test passing when it was supposed to fail (seems @BeforeEach not taking effect)

I coded a very simple and common CRUD in Kotlin. I want to do basic tests as testing post, delete, get and put. Probably I understood something wrong: I used Beforeeach aimed to insert a register so I could check during get test. I don't get…
Jim C
  • 3,957
  • 25
  • 85
  • 162
1
vote
1 answer

How to save a value from an XML-MvcResult into a variable with xpath

I have an integration test, to test two rest services with content-type application/xml. The first endpoint is called by an post request to create a person, and return a revision id. This ID is generated via a sql sequence in a H2 SQL database, so…
1
vote
1 answer

Why do I get null `Authentication` as @Controller method parameter in `@WebMvcTest`?

The context: I created a test annotation @WithMockAuthentication to populate test security context with an Authentication instance, much like @WithMockUser does. The main difference being, in my case, the instance is a Mockito mock. What I…
ch4mp
  • 6,622
  • 6
  • 29
  • 49
1
vote
1 answer

How can i check if each object in an array has a specific property exists using spring junit integration test?

I am writing a spring integration test for a method in my resource class . accessing the resource method returns a json response . I would like do an assertion . the following is my test method. @Test public void…
1
vote
0 answers

MockMVC not working with Spring Data Rest

I'm using Spring Data Rest with a custom controller. The custom controller overrides only the PATCH/PUT and POST verbs. @ExtendWith(SpringExtension.class) @WebMvcTest(UserController.class) public class UserControllerTests { @Autowired …
erotsppa
  • 14,248
  • 33
  • 123
  • 181
1
vote
1 answer

Running integration tests with springboot

I have several heavy Spring integration tests (yeah, it's not the best approach and I'm running out of time to mock all external deps properly) Here is typical annotation of a…
Capacytron
  • 3,425
  • 6
  • 47
  • 80
1
vote
1 answer

MockMvc empty response/return

I just created a simple integration test with MockMvc for a controller. All works well, but there is no response provided even the controller method returns something. Here is the Controller: import depmgmt.service.deposit.HouseService; import…
DanutClapa
  • 592
  • 2
  • 7
  • 23
1
vote
0 answers

Spring Boot - Different Testing approaches

I've been working with Spring and Hibernate for about two years. Recently I have also been working on testing. Now I'm not quite sure if I understood everything correctly. Do I understand correctly that the following methods exist? **If I make wrong…
Sven M.
  • 587
  • 7
  • 23
1
vote
1 answer

Spring WebMvcTest stucks in instantiating tests step

I have controller on groovy @RestController @RequestMapping('/v1') @CompileStatic class DatasourceResource { private final DatasourceService datasourceService @Autowired DatasourceResource(final DatasourceService datasourceService) { …
newakkoff
  • 270
  • 2
  • 13
1
vote
0 answers

Spring controller test failing with 404 error

I am using spring rest docs to create the documentation, my problem is that the test is working when I have both the test and the controller in the same folder: But when I try to change the controller from this package and move it to the…
rasilvap
  • 1,771
  • 3
  • 31
  • 70