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
0 answers

mockMvc expect exception

I would like to know how can I test to see if my controller is throwing an exception? Of course, the exception will cause the controller to redirect to another page or will return 500 status code. In my case, it returns 500 Internal Server Error…
tzortzik
  • 4,993
  • 9
  • 57
  • 88
0
votes
1 answer

NoInitialContextException - MockMvc accessing Rest Web Service with datasource connection got from InitialContext.lookup

There is a rest web service working perfectly when I evoke from other application but it fails when I evoke from Junit tester. I read a lot in the last hours and, if I understood correctly, the error in the subject is happening for two possible…
Jim C
  • 3,957
  • 25
  • 85
  • 162
0
votes
1 answer

movckmvc test that correct error message returned

The following test (testing that validation fails as the terms and conditions accepted by the user is not latest version) works fine but I would like to test the error message that's returned. The reason for this is a subsequent test (check that…
Simon Tilbury
  • 37
  • 1
  • 1
  • 5
0
votes
1 answer

RestAssuredMockMvc - Autowire repositories are null

I'm testing a rest controller using RestAssuredMockMvc. This is my code /*Repository*/ package com.rest.api.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import…
gvatreya
  • 444
  • 1
  • 6
  • 12
0
votes
1 answer

MockMvc on spring mvc controller

I have the following code in my controller: @Controller @RequestMapping(value="/my") public class MyController { @RequestMapping(value="/zone/{id}", method=RequestMethod.POST) public ModelAndView zone(@PathVariable Long id, @Valid…
Dax Durax
  • 1,607
  • 5
  • 23
  • 31
0
votes
0 answers

spring integration test for the controller with post method

I've got a controller with some parameters. It's RequestMethod is POST. But I send POST request with some parameters in URI and some in the body. But when I write such test mockMvc.perform( post("/") …
lapots
  • 12,553
  • 32
  • 121
  • 242
0
votes
0 answers

Spring MockMvc : setting MultiPartFile as part of form

My controller is like below @RequestMapping(method = RequestMethod.POST) protected String processSubmit(HttpServletRequest request, @Valid @ModelAttribute("binaryUploadForm") BinaryUploadForm form, BindingResult result, ModelMap model)…
Sammy Pawar
  • 1,201
  • 3
  • 19
  • 38
0
votes
1 answer

Unit Test of Controller Spring 4 MockMvc Absent Code Attribute

I've tried to build some basic web application using Spring 4 with Thymeleaf and I have problem with testing. First my build.gradle dependencies: dependencies { compile("org.springframework:spring-webmvc:4.0.5.RELEASE") …
Passarinho
  • 109
  • 1
  • 2
  • 15
0
votes
1 answer

setting up MockMVC for Spring Restful Web Service

So I don't think there is a lot of questions on here on Mockmvc from spring for testing springmvc controllers but I read through the spring tutorial https://spring.io/guides/tutorials/rest/2/ where there is a lot there but I was just trying to do a…
Michael Sampson
  • 369
  • 1
  • 6
  • 19
0
votes
2 answers

how test returned object from a mocked dependency that accepts two arguments inside the mocked object?

I couldn't find any post related to my problem. I'm using Mockito and I want to test the behavior inside a controller. I think the core of the problem is that I'm not using Mockito correctly when I send in two arguments to the mocked interface. It…
Magnus Lassi
  • 921
  • 2
  • 9
  • 21
0
votes
1 answer

Spring MVC testing with MockMvc - webapplicationcontext is null

I am trying to create JUnit test cases for Spring MVC controllers using junit & spring-test api. Since I have lot of beandefinitions in my app, I used LazyInitDefaultBeanDefinitionDocumentReader and have written a CustomContextLoader. My sample test…
0
votes
1 answer

noHandlerFound when unit testing login powered by Spring security

I'm getting this error when submitting login form with unit test: org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/app/login/authenticate] in DispatcherServlet with name '' I'm using…
perak
  • 1,310
  • 5
  • 20
  • 31
-1
votes
1 answer

What is the cause of java.lang.NullPointerException in my spring boot mockMVC test case?

MyCode @AutoConfigureMockMvc public class NewsletterTest { @Autowired private MockMvc mockMvc; @MockBean private NewsletterService service; @Test public void deleteNewsletterShouldDelete() throws…
-1
votes
1 answer

Mockmcv query param with localdate MethodArgumentTypeMismatchException exception

I'm trying to write an integration test with mockmvc, but I'm getting an error. While startDate and endDate, which I receive as request param, normally work without any problems, I get the following error in the test;…
Mert Özler
  • 113
  • 5
-1
votes
1 answer

Does Juint reset global variables for each test?

I have an integration test class like this (but more complex) @ExtendWith(SpringExtension::class) @WebMvcTest(Controller::class) class ScheduleControllerTest(@Autowired val mockMvc: MockMvc) { val obj = object { var b = 2 } @Test …
user15941734
1 2 3
49
50