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

Need to mock a service method in a POST endpoint skiping @RequestBody annotation

I'm trying to write a unit test for a POST REST endpoint. I need to mock a service method which is using in above endpoint using mockito. Using mock mvc to trigger the endpoint. I'm mocking the userService.saveUser(user) using in the endpoint and…
wannix
  • 120
  • 1
  • 2
  • 12
0
votes
1 answer

How to do error handling testing with mockmvc?

I have a method and method includes one exception if some param does not write in url. Let's show below if (url != null) { File = getService().getByUrl(url); } else { throw new IllegalStateException("you must send id); } this is my method pair and…
selo
  • 61
  • 2
  • 7
0
votes
0 answers

Kotlin testing authentication to /actuator api

I have a ActuatorSecurity class which I use for authentication for /actuator actions. package com.netapp.qronicle.config import org.springframework.beans.factory.annotation.Value import…
JonB
  • 804
  • 3
  • 12
  • 40
0
votes
1 answer

Load ApplicationContext inside a Junit Integration test

Config class with below configuration will load all the required classes in the application as beans by component scan during startup of application as below: @Configuration @EnableWebMvc @ComponentScan(basePackages = {"package1","package2"} public…
0
votes
1 answer

Controller Unit test not able to autowire required beans

I am trying to write a unit test for spring controller, the myService class is autowired in myController,I have mocked myService class but when I debug the code it is coming null myService = null I am not able to inject this service for my…
Ravat Tailor
  • 1,193
  • 3
  • 20
  • 44
0
votes
1 answer

Spring MockMVC redirectUrlPattern throws "No Ant-style path pattern"

I've seen this question and this question. I want to match URL pattern so I write my test according to answers in these questions. @Autowired private MockMvc mockMvc; // Ant pattern, example URL: /courses/1/edit private static final String…
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
0
votes
2 answers

Spring REST Docs setup MockMvc with static configuration class

Spring REST Docs reference guides to setting up MockMvc using autowired ApplicationContext: @Before public void setUp() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) …
user1622058
  • 453
  • 3
  • 7
  • 16
0
votes
1 answer

Mock Mvc unit test throws Http 406

My controller has this code @RequestMapping(value = "/getUserByEmailId/{emailId}", method = GET, produces = "application/json") public ResponseEntity getUserByEmailId(@PathVariable String emailId) throws ServiceException { …
Pavanraotk
  • 1,097
  • 4
  • 15
  • 33
0
votes
1 answer

CompletableFuture and MockMVC

I am using SpringBoot 2.0.6-RELEASE When I configure my api to use a CompletableFuture with no executor service provided - my tests run successfully. For example this tests passes ok public Future> getAlerts(@PathVariable(value =…
Damien
  • 4,081
  • 12
  • 75
  • 126
0
votes
0 answers

MockMvc PostRequest Exception

I have following post mapping. @PostMapping(value = BULK_UPDATE) @ApiOperation(value = "Bulk Update of Markets by pairs of Market Key and Tier Quantity Id", tags = "Bulk", code = 200) @ApiImplicitParams({ @ApiImplicitParam(name =…
Nilamber Singh
  • 804
  • 1
  • 14
  • 33
0
votes
1 answer

Test Request body of restTemplate.postforEntity(url, request,ResponseObj.class)

How can I test the request json passed in restTemplate.postForEntity. Lets say for the below method: void doAsyncCall(Int id){ MyObject obj= mydao.getObject(id); ///do something MyRequstObject myrequet =…
Stin
  • 141
  • 1
  • 2
  • 12
0
votes
1 answer

How to test stateless with MockMvc and Mockito

I recently inherited some java code, that needs to switch to stateless in HttpSecurity configuration: http.csrf().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); After that, some tests using MockMvc…
Annie C
  • 764
  • 2
  • 12
  • 31
0
votes
1 answer

Mocking @Resource when using MockMvcBuilders.standaloneSetup

My team is currently building a SpringBoot API. Below is a snippet of how my team is mocking for our controller tests. This works when we have plain classes as dependencies. @RunWith(SpringRunner.class) @SpringBootTest public class TestController…
David Stewart
  • 335
  • 1
  • 4
  • 10
0
votes
1 answer

How to use Mockito to skip invoking a void method

I have a REST controller exposing an endpoint. When this endpoint is hit, a void method gets invoked and this method then goes off and pushes a file to a remote GitHub repo. The code is working beautifully. My problem occurs when writing unit…
prometheusnoob
  • 147
  • 1
  • 3
  • 13
0
votes
1 answer

Spring Test mockMvc is ignoring validation

please help me to solve the following issue: I have a class, where several fields are marked as @NotNull: public class SearchCommentRequest { @NotNull private Date fromDate; @NotNull private Date toDate; //... } Object if this class is passed to…
Viacheslav
  • 143
  • 4
  • 19