Questions tagged [mockmvc]

MockMVC is the key part of the Spring MVC Test framework is. It simulates the internals of Spring MVC.

MockMVC is the key part of the Spring MVC Test framework is. It simulates the internals of Spring MVC.

742 questions
0
votes
1 answer

Spring boot test for Restful POST API DTO with MultiPartFile attribute

I have a Spring Boot app which has a RestController with the following POST method: @PostMapping(path = "/add", headers = {"content-type=multipart/form-data; charset=utf-8"}) public ResponseEntity addUser(@RequestHeader HttpHeaders…
Riham Nour
  • 387
  • 4
  • 10
0
votes
1 answer

The return entity of mocked repository call is returning null

The code snippet retrieves the entity based on parameters. public void updateNotification(String status, Entity entity ) { Entity entity1 = null; try { switch (status) { case "AX": entity1 =…
Karthik Suresh
  • 367
  • 7
  • 23
0
votes
1 answer

MockMvc the Model is Null

I'm testing a controller using JUnit and MocMvc as bellow : the test fails because the model is null, but when I debug, I'm sure that the model attributes contain the right value Controller : @RequestMapping("/login/role") public String…
BSL
  • 93
  • 1
  • 10
0
votes
0 answers

ExceptionHandler is not entered

I have a REST-Backend created with JHipster. There are different exception-classes in the service layer and the web-rest layer. This service-exceptions are translated by an ExceptionTranslator which implements the ProblemHandling interface from…
Steve2Fish
  • 187
  • 4
  • 15
0
votes
2 answers

MockMvc post test fails

I want to test a rest controller method of request type post that includes a request body. All other Get Methods are working expect post. I'm expecting 200 OK but it returns 417. My intention is to make it pass I run the test and it fails. I'm new…
K.Nehe
  • 424
  • 10
  • 22
0
votes
1 answer

Spring Security MockMVC with @WithMockUser() always returns Successful status

I am trying to test some endpoints (I am quite new to testing) and having an issue where the Mocked Authentication seems to always be accepted and returns a 200. The test without Auth seems to have a user with just a ROLE_USER but the endpoint still…
Jcov
  • 2,122
  • 2
  • 21
  • 32
0
votes
1 answer

Spring REST Docs - No content to map due to end-of-input

I have a springBoot 2.1.9.RELEASE application that uses Spring REST Docs. I have this method in my TestController @Test public void createOK() throws Exception { String content = ResourceUtils.getResourceFileAsString…
Sandro Rey
  • 2,429
  • 13
  • 36
  • 80
0
votes
1 answer

Service layer mocked in controller class is executing actual method implementation

When writing the unit test case for the controller class, I mocked the service layer call to return the desired value, but instead, it returns null. Test class @RunWith(SpringJUnit4ClassRunner.class) public class ControllerTest { @Mock …
Karthik Suresh
  • 367
  • 7
  • 23
0
votes
1 answer

java cannot resolve symbol 'param' while using mockMvc to test spring boot application

I am trying to test my spring boot application by using junit5 and mockMvc, however i cannot even compile it because java cannot resolve the symbol param. Can anyone please tell me what i can do to find the missing package? I am using IDEA to do the…
zifan yan
  • 125
  • 2
  • 11
0
votes
0 answers

How to generate request body regex match with spring restdocs and spring contract?

Using mockMvc, Spring restDocs and Spring cloud contract with the following @Test code: var adminDTO = HandlerTestObjectGenerator.createRandomAdminDTO(); mockMvc.perform( RestDocumentationRequestBuilders …
milkamar
  • 443
  • 6
  • 16
0
votes
1 answer

@ModelAttribute Overwritten by URL Values

I have a controller the following method signature @PostMapping public String doUpdate( @PathVariable("fooId") Long ID, @ModelAttribute Item form, Model model) The @RequestMapping for the controller…
pmaurais
  • 734
  • 2
  • 9
  • 30
0
votes
1 answer

mockMvc doesn't understand securityConfig with multiple Matchers

my security config: http.authorizeRequests().antMatchers("/ticket/create") .access("hasAnyAuthority('MANAGER','EMPLOYEE')") .and().authorizeRequests().antMatchers("/api/**","/ticket/*") …
Ars
  • 591
  • 1
  • 4
  • 19
0
votes
1 answer

How to Unit test Spring-Boot REST endpoints with MockMVC where the path mappings are environment variables?

I'm trying to write Unit tests for a service that relies heavily on environment variables for its configuration. Unit tests work fine for the service layer but I'm running into problems trying to set up MockMVC tests for the endpoints that read…
Péter Veres
  • 955
  • 1
  • 10
  • 25
0
votes
1 answer

Testing a POST Api using Junit and Mockito-Nested Exception problem

I am trying to test an API using JUNIT and mockito, being a beginner i didn't find any solution regarding the problem i am stating I am trying to test an api which invovles the inclusion of employee and department in the form of { "name":…
Vandit Shah
  • 105
  • 7
0
votes
1 answer

Getting a bad status error response with MockMvc junuit test

I wrote a test in spring mockMVC this method, but I am getting a wrong error message: My method testing is: @Test public void registerAll_NoSalons_SalonNoExist() throws Exception { KidDTO kidDTO = MockDTO.buildKidDTO(); …
rasilvap
  • 1,771
  • 3
  • 31
  • 70