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

Getting NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped

I want to conduct a JUnit 5 integration test for my small application. The problem occurs in the test which is sending a GET request with @PathVariable with MockMvc usage. My controller looks…
Martin
  • 1,139
  • 4
  • 23
  • 49
0
votes
1 answer

MockMvc is throwing an assertion on a simple Spring Boot / Thymeleaf integration test

I've created a basic integration test using the standard MockMvc setup for my Spring Boot / Thymeleaf application. My simple test is just to verify that the About page of the website loads. When I run the test and verify status, I get a…
LeeRosenberg
  • 83
  • 1
  • 2
  • 9
0
votes
0 answers

Preperate data with MockMVC for GET method

I'am trying to test my get all events method. So i'm trying to first fill one event into database and then perform get method by MockMVC. But it is returning empty content. I have tried to change specific annotations such like MockBean/Autowired on…
A. Blicharski
  • 36
  • 1
  • 6
0
votes
1 answer

Why do I keep getting 404's when using @AutoConfigureMockMvc in SpringBoot test?

I'm trying to write an integration test using springrunner. I'm running it as a springboottest and using autoconfiguremockmvc. However, i keep getting 404s. It seems my controllers/endpoints aren't being loaded by the autoconfiguremockmvc. Does…
0
votes
1 answer

jdbcTemplate is null, when using method with JUnit

I currently work on a Spring Project and I am now writing JUnit tests. My problem is, that the jdbcTemplate is null (tested with Debugger) in the method getQuestions, so it doesn't receive any data from the database. Everything else works just…
Manuel K.
  • 23
  • 8
0
votes
1 answer

How do I post an String Array with MockMvc?

I am currently working on a Spring project and I want to write some tests. Unfortunately I don't know how to pass the requiered Array. The Get Request works just fine... Here is my Code: MainControllerTest.java private MockMvc…
Manuel K.
  • 23
  • 8
0
votes
1 answer

HttpMediaTypeNotAcceptableException when calling REST API using mockMVC

I am trying to test my API,for which I am calling my API using mockMVC as below: ResultActions resultAction = mockMvc.perform(MockMvcRequestBuilders.get("/users/v1/{userId}",userId) …
javaguy
  • 927
  • 2
  • 16
  • 37
0
votes
1 answer

how to get bottom error message from a nested exception using mockmvc

I am getting a nested exception like below for my Junit tests: Caused by: com.exception.Test1RestException: operation failed for test1 at com.testController.tests(Test1Controller.java:123) ............................ Caused by:…
Anand
  • 621
  • 3
  • 9
  • 31
0
votes
0 answers

Spring Boot 2 MockMVC unit testing with RequestPart and MultipartFile

I have the below email controller for sending email with RequestPart DTO object (userDTO) and Multipart file (3 files upload max). where userDTO is a JSON object I tried using postman and it works perfectly for sending email with attachments,…
0
votes
1 answer

Unable to Mock RestTemplate.exchange

As part of TDD i want to be able to test every portion of my SpringBoot rest application. However i am unable to mock external calls. Application structure 1. Few rest endpoints which internally call external rest endpoints. 2. All calls to…
Veeraraghavan N
  • 839
  • 1
  • 10
  • 19
0
votes
2 answers

MockMvc fails because of method invocation inside the controller method

I try to mock a controller which contains a util method inside even though I mock the util method, the mvcMock ignore the result from the when(...) and call the method again with empty parameters which lead to nullpointerexception How I can ship…
Noa
  • 315
  • 1
  • 7
  • 31
0
votes
1 answer

How to convert java object correctly for jsonPath matcher?

I'm writing mockMvc tests for my controller, and need to validate jsonPath return value. Have tried differently with .is() and .value(), mapping, in any way i can imagine with no success Loan loan = new Loan( "0000-0000", …
nilino
  • 1
0
votes
1 answer

Mock a method within another method in mockmvc

I'm new to MockMVC and junit stuffs so need a help ,so the situation is I need to mock a method while mocking the outer method which contains the method. For example method calculator(int a , int b) , i mock this method with two mock values, and…
Akhil KC
  • 76
  • 1
  • 8
0
votes
0 answers

how tests are getting executed in spring boot while doing integration with in memory server?

I am running integration tests for my API which deals with in-memory LDAP server. Sometimes tests gets executed properly and sometimes not. Why is this happening ? I have tried optimizing test-cases and reducing count of test-cases. Individually…
0
votes
1 answer

How do I check whether a mockMvc response header is the MD5 representation of a part of my response?

I need to compare the MD5 hash of a specific value in my mockMvc response body to a header of the same request. I'm not sure how to do this given that there doesn't seem to be an easy way to get the content of a jsonPath or xPath matcher. I think…
Nzall
  • 3,439
  • 5
  • 29
  • 59