Questions tagged [spring-mvc-test]

241 questions
2
votes
1 answer

@Mock of an @Autowired dependency causes random junit test failures

My spring-mvc app works. Yay! Proof: This is my good setup: The important bits of my Buggy-servlet.xml The important bits…
mikerott
  • 423
  • 2
  • 10
2
votes
1 answer

Spring @SqlGroup MetaAnnotation not working

I'm trying to set up a meta-annotation for some integration tests. This test works fine. @Test @SqlGroup( { @Sql(scripts = {"classpath:test/sql/customers/customers.sql", "classpath:test/sql/orders/order_addresses.sql", …
Richard G
  • 5,243
  • 11
  • 53
  • 95
2
votes
3 answers

Invalid controller configuration at Spring MVC 4

I am new to Spring framework. I would to develop a simple web-app that displays a hello.jsp content based on url "/greeting.html". But now, it gives me 404 error. What am I doing wrong? Here is the github repo for my project (this project was…
mr.M
  • 851
  • 6
  • 23
  • 41
2
votes
2 answers

Spring MVC Mixing xml and java @ContextConfiguration in integration test

I am trying to configure a Spring MVC Integration test using a combination of XML config and @Configuration annotated classes. @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @TestPropertySource({"/spring-security.properties", …
2
votes
0 answers

Spring Controller @ResponseBody is Empty

In my spring webapp, I'm trying to test my controller: @Controller @RequestMapping(value="/Position") public class PositionController { @Autowired PositionRepository positionRepository; @RequestMapping(method=RequestMethod.GET,…
Alex2330
  • 347
  • 1
  • 7
  • 21
2
votes
1 answer

Mockito:: Null pointer exception for MockMVC

I am having project in spring-mvc. I wrote a test case in mockito, Below is the code: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:applicationContext.xml"}) @Configurable public class ABCControllerTest { …
user3363969
  • 233
  • 1
  • 4
  • 15
2
votes
1 answer

Spring MVC form with Multiple rows of same type of fields, each row with a submit button, not able to edit a single row

I have a form with multiple rows, each row having some editable fields which are mapped to the property of the model class through form input path and a submit(edit) button. Now, the problem is while submission, I am not able to dynamically append…
user2971387
  • 109
  • 1
  • 3
  • 11
2
votes
1 answer

Spring Junit Controller Mock Not Working

I have the following controller and I want to make a Junit Test on it, @RequestMapping(value = "/path", method = RequestMethod.Get) public String getMyPath(HttpServletRequest request, Model model) { Principal principal =…
Jones
  • 1,036
  • 5
  • 20
  • 37
2
votes
2 answers

Test a Spring multipart/form-data controller with uploading of some files

I am trying to test this controller: @RequestMapping(value="/u",consumes="multipart/form-data", method = RequestMethod.POST) public @ResponseBody String register( @RequestParam String u, @RequestParam CommonsMultipartFile filea, …
Jonás
  • 1,459
  • 4
  • 27
  • 43
2
votes
1 answer

stubbing two methods in a mock is throwing Exception using Mockito and Spring MockMVC

I am trying to set up some simple MVC Unit Testing. What I am trying to accomplish is this: Use Spring MockMVC to test HTTP status and HTTP data returned from my controllers. My controllers have an Autowired reference to a facade which performs the…
2
votes
1 answer

Unit testing spring mvc controller with mockito

i'm using mockito and junit and run unit test against spring mvc my flow of code is: Service Layer -> Model Layer -> Controller Layer i was successfully testing the Controller against the model layer with the…
oak
  • 2,898
  • 2
  • 32
  • 65
2
votes
1 answer

MockMvc: forwardedUrl is null

I am having problems to make this test work. Assertion always fails because it can't verify forwardedUrl which is always null. If I remove this assumption, it can't verify return model. I suppose it is due to missing forwarded Url. My test class…
Rade Milovic
  • 965
  • 4
  • 13
  • 29
2
votes
1 answer

Spring setDisallowedFields is not working

The registration controller disallowes sending account id field by the following: @InitBinder public void initBinder(WebDataBinder binder) { binder.setDisallowedFields("id"); binder.setRequiredFields("username","password","emailAddress"); }…
Alexandr
  • 9,213
  • 12
  • 62
  • 102
2
votes
1 answer

Spring mock mvc keep file extension

The only relevant question I could I find here is this one. Unfortunately unlike the above mentioned question I am not using file names as a path variable. What I am sending in a string which may or may not have '.'. As a result I do not want to use…
bagi
  • 627
  • 1
  • 8
  • 20
2
votes
1 answer

Spring MVC test 3.2.2 fails "flash().attributeExists" assertion for some strange reason

I am testing the following Spring MVC controller method: @RequestMapping(value = "/passwordReset", method = RequestMethod.POST, produces = "text/html") public String resetPassword(@Validated({ ValidationGroups.PasswordReset.class })…
balteo
  • 23,602
  • 63
  • 219
  • 412