Questions tagged [spring-mvc-test]

241 questions
3
votes
1 answer

Spring MVC testing conversion service when using ConverterFactory

Initially I had a converter for almost every entity classes in my project. I decided to drop all those converters and created a ConverterFactory that will do all the conversion. @Service("dataConverterFactory") public class DataConverterFactory…
chege
  • 323
  • 5
  • 16
3
votes
3 answers

Spring MVC test framework - JSON end point returns 406 only in test

I have built a working Spring MVC web app utilising Hibernate and JPA with a single end point that returns JSON only successfully when called through a web browser. I have also got passing unit tests against classes, in particular the main…
Jeremy
  • 3,418
  • 2
  • 32
  • 42
3
votes
1 answer

Spring boot test: Test passes, but should not (false positive)

I have Spring Boot project with test that does not fail (but should). Am I doing something wrong or it is a issue with Spring? For an small example I have created a small project with 2 entities (User and Category) and one Controller class that has…
3
votes
1 answer

Spock & Spock Reports: how "catch" and customize the error message for AssertionError?

I am working with: Spock Core Spock Reports Spock Spring Spring MVC Testing and I have the following code: @FailsWith(java.lang.AssertionError.class) def "findAll() Not Expected"(){ given: url = PersonaUrlHelper.FINDALL; when:…
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
3
votes
1 answer

is it possible to use Spring MVC Test directly in grails, and how?

We think the Spring Rest Doc is great for documenting rest api. But it is based on Spring MVC Test,and we can't figure out how to use Spring MVC Test in my grails apps(Grails 3.0.5). I tried to use a config class (with @Configuration…
3
votes
2 answers

Spring MVC Test failing

I am trying to run a Spring MVC Test but keep getting this exception. org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException The exception is occuring because the autowired…
kellzerIrl
  • 103
  • 1
  • 10
3
votes
1 answer

Spring security DefaultMethodSecurityExpressionHandler bean is not registered for Integration Test's default spring security config

I am attempting to write Spring MVC integration test with Spring Security and Thymeleaf for the view layer. I have setup my MockMvc object with Spring Security Integration just like all the examples from the documentation. Integration Test…
3
votes
0 answers

Spring MVC Test with RequestPostProcessor vs. Annotations

I have an application I've created with JHipster. I generated a Blog entity, then modified the BlogResource class so its getAll() method only returns the blog for the current user. /** * GET /blogs -> get all the blogs. */ @RequestMapping(value =…
3
votes
1 answer

How to reference jsp tags from Freemarker template in Spring/Junit test harness

I'm having trouble resolving JSP tags in the Freemarker template inside a Spring test harness. My questions is: Why are the JSP references not resolving inside the JUnit environment? And how do I get them to resolve? The code in the template…
Richard G
  • 5,243
  • 11
  • 53
  • 95
3
votes
0 answers

@WebAppConfiguration pre Spring 3.2.x

I'm writing a bunch of spring-mvc tests, but I'm using Spring 3.1, there are some issues right now with upgrading to post 3.1 so I'm not attempting that at this time. My question is, I have a spring controller test but I'm trying to inject a…
alessandro ferrucci
  • 1,261
  • 2
  • 24
  • 48
3
votes
1 answer

Spring integration tests issue: could not initialize proxy - no Session through reference chain:

I am trying to test a controller method and I have an issue that probably has to do with lazy loading and I am therefore trying to set up a open entity manager in view filter for my tests. Setup method: @Before public void setup() { mockMvc =…
balteo
  • 23,602
  • 63
  • 219
  • 412
3
votes
3 answers

MockHttpServletResponse : Checking xml content

I am testing a controller using MockMvc. This is what the response looks like: MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[text/xml]} Content type = text/xml …
Niel de Wet
  • 7,806
  • 9
  • 63
  • 100
3
votes
1 answer

Handling MethodArgumentNotValidException in Junit testcase?

I am using spring MVC testing: In my test case, I am passing an invalid Bar object(age with zero). The MethodArgumentNotValidException is being thrown, but it is nested inside a NestedServletException. Is there anyway to throw the…
jacquard
  • 1,307
  • 1
  • 11
  • 16
3
votes
1 answer

Is it possible to test Portlet Controllers using Springs MockMvc?

You can test your "normal" Spring MVC Controllers using the MockMvc class like so: mockMvc .perform(get("/my/fine/path")) .andExpect(status().isOk()); From the Spring Reference on Handler Mappings: Since there is really no such…
Jörgen Lundberg
  • 1,799
  • 3
  • 22
  • 31
2
votes
0 answers

MockMvc uses wrong ApplicationContext when it is used in a nested class

Apparently Spring creates another ApplicationContext when a @Nested class has custom configuration, e.g. @TestPropertySource. In that case two application contexts exist, one AnnotationConfigServletWebServerApplicationContext as usual and another…
Sirea
  • 53
  • 4