Questions tagged [spring-mvc-test]
241 questions
0
votes
0 answers
Spring boot: Failed to perform cleanup of multipart items
When I want to transfer a file to spring mvc from browser using http, there will be a error.If I remove the filters, there will be accept.I infer the error occured in filters.And so on, If I delete the temp file in operation system, It will show…

gold-three
- 19
- 1
0
votes
1 answer
Mock mvc test with repository dependency
I'm trying to write mock mvc controler test in Spring boot. I'm not able to boot test because my service: StrategyService which I'm going to inject in controller via @MockBean annotation has repository dependency StrategyRepository:
@Service
public…

Krzysztof Michalski
- 791
- 1
- 9
- 25
0
votes
0 answers
Spring MVC: MockHttpServletRequestBuilder - pass in sort parameters as a List
I can't figure out why there is a different conversion to the List sort when passing 1 or 2 sort options as follows from the test using MockMvc:
List sort = Arrays.asList("firstName,desc")
//some other test set…

belgoros
- 3,590
- 7
- 38
- 76
0
votes
0 answers
When trying to invoke a rest api to upload multipart file Getting error No serializer found for class java.io.ByteArrayInputStream?
I am trying to consume a rest api to upload a Multipart file. I have set MultipartFile in UploadFIleObject and I am sending the same to rest api. However when trying to invoke a rest API as below, I am getting error No serializer found for class…

Nishant
- 1
- 3
0
votes
1 answer
Mocked service class returns false instead of defined value
I'm currently trying to write Integration tests for a registration controller. When I run the test I get a different return value from the one I define using Mockito's when() method.
Test method:
@Test
public void whenValidInput_thenReturnsTrue()…

StruckCroissant
- 51
- 4
0
votes
0 answers
unit test for REST-API @PutMapping controller - problem with JSON path
I have problem with unit test for controller that has to update an employee in REST-API. For testing I use mockito, JUnit, hamcrest. I am only posting the most important parts of these classes.
controller method
@PutMapping("{id}")
public…

Dratewka
- 57
- 1
- 6
0
votes
1 answer
How can I test this springboot controller method with multipart and a object from a form submit?
I have the following controller method
@PostMapping("/create")
public ModelAndView createDocument(@ModelAttribute("user") @Valid User userToSave, BindingResult bindingResult,@RequestParam String adressId,@RequestParam MultipartFile file){
Now…
0
votes
1 answer
Custom Meta atribute in hibernate xml?
What is the purpose of custom meta tags? I have seen them at class level and at property level.
Example of Propery level level:
…

user124
- 423
- 2
- 7
- 26
0
votes
1 answer
Cannot load images in spring mvc
I cannot load static images. Did I miss anything here?
Here is my servlet xml file
servlet.xml
Project structure
And this is on my page

beginneronly
- 39
- 6
0
votes
1 answer
Spring MVC - Binding results missing after manually overriding model
I've got some code which looks like this
@Controller
public class FooController {
@RequestMapping(value = "/foos", method = POST)
public String createFoo(@ModelAttribute("FooDto")
@Valid FooDto fooDto, BindingResult bindingResult, Model model)…

Theiaz
- 568
- 6
- 24
0
votes
2 answers
Mockito.when method doesn't manage my service call
i'm trying to make Unit Test testing a simple GET controller method apply MockMvc.perform method but when the controller receive a request the method Mockito.when seems to doesn't manage the method call of MenuService and the test throw an…

gusmero
- 1
0
votes
2 answers
Integer overflow attack mitigation in Spring Rest API
We are currently undertaking security vulnerability assessment of our webapps. For this we have been using the ZAP tool from OWASP for automated penetration testing. One of the alerts we received from ZAP was for integer overflow error with the…

Desmond27
- 173
- 1
- 4
- 17
0
votes
1 answer
Spring boot v2 No qualifying bean of type TestRestTemplate
I am getting an error when trying to get the TestRestTemplate. Is there any way to get the TestRestTemplate or test the ErrorController?
error log: https://pastebin.com/XVPU9qrb
Main test class:
package io.kuark.ppalli
import…

dungsil
- 3
- 4
0
votes
1 answer
Why does @WebMvcTest not load Controller-Advices into the Application-Context?
Helloin my parameterized junit5-test i get a NestedServletException until i add the
@ContextConfiguration-Annotation above my test class in which i reference my custom exception handler that is annotated with @ControllerAdvice. In it i have methods…

Nico S.
- 77
- 1
- 1
- 9
0
votes
1 answer
Why does environment.getProperty("spring.profiles.active") return null on activating a Profile in Tests with @ActiveProfiles
If I activate a Profile in Tests with @ActiveProfiles, say @ActiveProfiles("test"), and declare @Mock private ConfigurableEnvironment environment in test, will I be able to retrieve environment.getProperty("spring.profiles.active"). I am getting…

sammy
- 31
- 3