Questions tagged [mockmvc]
MockMVC is the key part of the Spring MVC Test framework is. It simulates the internals of Spring MVC.
mockmvc
774
questions
0
votes
0
answers
10
views
Junit expecting a 400 response but getting a 200
I am trying to test my springboot controller /save endpoint. I want to test that if you send a json request with a null agency name you should get back a 400 status and the response "Agency Name ...
-1
votes
1
answer
12
views
Spring / MockMvc: A multipart post request of file&non-file parts causing issues matching the correct object type
If I want a post request definition like so:
@PostMapping(path = "/metadata/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResponseEntity<Void> test(HttpServletResponse ...
0
votes
1
answer
53
views
Encoding problem in Spring Boot MockMvc tests
I'm implementing integration tests for my Spring Boot application using MockMvc. The problem is that I need to use russian characters in my request/response bodies and they keep changing to unreadable ...
0
votes
1
answer
29
views
how to get Image in database for orderClass integration test springboot
The images for the invoice are first uploaded by user via POST-image request, so that later in a POST-order request the invoiceService that auto-generates the invoice has the images within reach.(...
0
votes
0
answers
31
views
MockMvc pefrorm method doesnt actually perform my http request
So I am busy with small project for my school and I am writing the test class for my movie controller class (using Spring Data JPA). All endpoints from my controller class are working fine, but when I ...
0
votes
1
answer
30
views
how can i toggle unleash feature flag in integration tests in kotlin?
Unleash give this documentation - https://github.com/silvercar/unleash-client-kotlin?tab=readme-ov-file#unit-testing for writing unit tests but there is nothing on how to toggle in integration test ...
1
vote
0
answers
50
views
How to properly send array of objects with MockMvc POST api request which controller using @ModelAttribute?
I try to write post API endpoint test with MockMvc that send multiple parameters including array of objects and I got this error.
java.lang.AssertionError: Status expected:<201> but was:<400&...
0
votes
1
answer
41
views
MockMvc test always returns 200 regardless of JWT authorities
@Test
public void testGetOrders() throws Exception {
mockMvc.perform(get("/admin/api/orders/")
.with(jwt().authorities(new SimpleGrantedAuthority("...
0
votes
0
answers
38
views
Spring Boot test: Why is my response body empty when testing a POST request?
I'm trying to test a POST endpoint in my Spring Boot application that creates a ChallengeReport. However, the response body is always empty, even though the status code is correct. I need help ...
0
votes
0
answers
37
views
MockMvc expected 200 actual 400 - @Valid annotation not respected
We recently upgraded our application to Spring 6, java JDK21 and are now using the jakarta.validation-api. Furthermore, we have a custom class which extends ResponseEntityExceptionHandler. When we ...
0
votes
0
answers
23
views
How to wait async tasks in java mockmvc tests?
We have a system that we send notification asynchronously to users under certain conditions. We also keep the notifications in a DB repository.
We want to write a test to ensure that if the ...
-2
votes
1
answer
61
views
Java Spring Softwaretest json response is empty. Why?
I'm working on a fun project with some random person data (from java-faker) to learn more aboud java, spring, api, thymeleaf, softwaretests...
-> my-project-from-gitlab
Besides many small problems ...
-2
votes
3
answers
76
views
Error with MockMVC and Spring boot integration test
I am trying to create an integration Test for my Spring boot App. For this, I followed the following tutorial: https://programandoenjava.com/pruebas-de-integracion-en-spring-boot/
This is my code:
@...
0
votes
0
answers
40
views
Getting 415 Unsupported Media Type error when running tests in Spring, when it works when I manually test it
So I have this test set up
@Test
@WithMockUser
public void testXml() throws Exception {
String testXml = "<test><key1>value1</key1><key2>value2</...
0
votes
0
answers
37
views
Writing integration tests for a Spring Boot application using SAML with Single Sign-On (SSO)
I'm working on a Spring Boot application that utilizes SAML for authentication with Single Sign-On (SSO) using Microsoft Entra ID. I'm looking to write integration tests for this application to ensure ...