Questions tagged [spring-mvc-test]
241 questions
1
vote
2 answers
Spring override bean of another module
In my multimodule project I have integration tests as seperate module. That tests have application jar added as dependency. Is it possible to override application bean definition from integration tests?
In application I have following Bean (standard…

patryks
- 650
- 2
- 15
- 32
1
vote
2 answers
@NotNull is not validating and not Producing correct Result in Spring Framework
I have created a simple Application that checks whether the given first name and lastname is null or not . i have used @NotNull annotation to check
The code for the Student.java is
@NotNull(message = "Name must not be null")
private String…

Arul Suju
- 706
- 1
- 9
- 21
1
vote
1 answer
Spring MVC Test - multipart POST json originalFilename is required
I use spring-boot 2.0.3.RELEASE with junit5. I have just tried to test multipart request with mockMvc.
MockMultipartFile file = new MockMultipartFile("file", "contract.pdf", MediaType.APPLICATION_PDF_VALUE, "<

Bully
- 139
- 1
- 14
1
vote
2 answers
405 Request method 'POST' not supported when testing spring application
I prepared and extended this existing spring example which is running fine. You can simply login with "user" and "password" and afterwards you get forwarded to user/index.
Using this controller
@Controller
public class LoginController {
…

Ben1980
- 186
- 1
- 3
- 15
1
vote
1 answer
How to test if a REST endpoint returns a number in Spring Boot?
I have a simple controller that requests a number from some random REST service and wraps it in a JSON object. These numbers can either be integers or floating point numbers. Thus the consumers of my REST endpoint should expect a floating point…

stevecross
- 5,588
- 7
- 47
- 85
1
vote
1 answer
This exception may occur if matchers are combined with raw values
My Mock call is like below :
BDDMockito.given(restTemplate.exchange(url,
HttpMethod.POST,
BDDMockito.any(),
Response.class)
).willReturn(responseEntity);
but i am getting below errors . please help me out on this???????
4 matchers…

Nag-Raj
- 169
- 1
- 4
- 13
1
vote
1 answer
SpringWebMvcTest - Test Requestbody using @Valid and custom validation
I am trying to test my controller endpoint and my requestbody annotated with @Valid annotation. My Testclass looks like the follow:
@RunWith(SpringRunner.class)
@WebMvcTest(value = BalanceInquiryController.class, secure = false)
public class…

Patrick
- 12,336
- 15
- 73
- 115
1
vote
0 answers
Mocked authentication not applied when using mockMvc together with direct bean access
I have an UserRepository annotated with @PreAuthorize("hasRole('ROLE_ADMIN')"). When I perform a mockMvc request, the mocked authentication works as expected. But the repository access afterwards fails with:
An Authentication object was not found…

Jannik Weichert
- 1,623
- 16
- 28
1
vote
1 answer
Spring boot Integration unit testing NoSuchBeanDefinitionException exception
I created a sample IntegrationFlow as shown below:
@Configuration
@EnableIntegration
@IntegrationComponentScan
@ComponentScan
public class RegisterHostFlow {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
…

nkare
- 397
- 6
- 17
1
vote
0 answers
RestTemplate reads String data with "\" content (Even with StringHttpMessageConverter)
I am working with Spring Framework 4.3.6.RELEASE
For testing purposes through RestTemplate how a consumer, if the HTTP DELETE method fails because the entity does not exist, I need return an error message in raw format or String. It because…

Manuel Jordan
- 15,253
- 21
- 95
- 158
1
vote
0 answers
Spring MVC Test with Validation JSR-303/349: Locale or accept-language does not work in testing
I am working with Spring Framework 4.3.3
I have the following situation for a @Controller either for POST or PUT
For example for POST I have the following:
@PostMapping(value="/save",
…

Manuel Jordan
- 15,253
- 21
- 95
- 158
1
vote
0 answers
Using sping's default beans in mvc-test framework
I have the following controller definition:
public ResponseEntity switch(@PathVariable UUID userId, OAuth2Authentication authentication) { .. }
authentication object injected automatically, everything is fine. But once I want to test is with…

nKognito
- 6,297
- 17
- 77
- 138
1
vote
1 answer
Strange character in MockHttpServletRequest Swagger2 DeferredResult  response
Running a validation test and get these nasty characters embedded in the Swagger 2.0 validation output
{"$ref":"#/definitions/DeferredResult«ResponseEntity«SummCollection»»"
Controller method returns:…

ken
- 666
- 2
- 6
- 19
1
vote
1 answer
JPA foreign key is null in the child table
I have below classes i am trying to get onetomany relationship using JPA. When the xml message sent to restcontroller, the message is stored both parent and child table but foreign key is always null. Please let me know if any issue.
Rest Service…

mike
- 377
- 1
- 9
- 22
1
vote
0 answers
No InputStream specified when use spring-mvc-test andDo() method
recently when i do my work using spring-mvc-test-framework,code like…

MrJ
- 33
- 1
- 7