Questions tagged [spring-test-mvc]

spring-test-mvc based on spring-test provides a unit testing framework for spring-mvc services.

spring-test-mvc
Filter by
Sorted by
Tagged with
0 votes
1 answer
2k views

Spring test MVC @annotation pointcut expression is only supported at Java 5 compliance level

I am writin Spring Integration Testcase using Spring test MVC framewok. My application works properly in J2EE Runtime but if I run though JUnit Plugin my test case is using @RunWith(...
jazz's user avatar
  • 19
1 vote
0 answers
111 views

How get the amount of elements/fields of a node

I am working with Spring MVC Spring MVC Testing In Spring MVC, assuming that a @Controller working with @ResponseBody returns a domain object represented in XML format and through print() method I ...
Manuel Jordan's user avatar
0 votes
0 answers
498 views

jsonPath: how confirm the data returned is just one element? and when it is not an array

I am working with: Spring MVC Spring MVC Testing Assuming that a @Controller working with @ResponseBody returns a set of domain objects represented in JSON format and through print() method I can ...
Manuel Jordan's user avatar
2 votes
1 answer
2k views

How to test a Controller, which retrieves data with Post method, using a MockMvc object?

Hello everyone I'm using Spring MVC framework and I want to test my Controllers. One of them uses the Post method in order to retrieve data from the View and I don't know how to to test it. This ...
nick's user avatar
  • 1,621
1 vote
0 answers
407 views

Spock & Spock Reports how retrieve the MockHttpServletResponse (from Spring MVC Testing) for the where block?

I am working with Gradle Spring MVC Testing Spock Core Spock Spring Spock Reports In some Specification I have the following: I was able to do the following: def ResultActions resultActions // ...
Manuel Jordan's user avatar
1 vote
1 answer
2k views

Spring MockMvc does seems not support "produces" in @RequestMapping when using WebApplicationInitializer

I have the following method: @RequestMapping(value = "/report.txt", produces = "text/plain;charset=UTF-8", method = RequestMethod.GET) @ResponseBody public String showReport( ... ) which I test ...
Kaj Hejer's user avatar
  • 998
0 votes
1 answer
1k views

Spock does not work for an expected "matched invocations" working through @WebAppConfiguration

I am working with STS Gradle Spock Core Spock Reports Spock Spring Spring MVC Testing I have the following test code: @WebAppConfiguration @ContextConfiguration(classes=[...
Manuel Jordan's user avatar
1 vote
1 answer
2k views

Getting null for form parameter in Spring Test Framework Controller test

I am testing Sign Up form submit using Spring Test Framework. And I am passing parameters using param but parameter assertion is failing because value is coming out to be null. Below is the code ...
Meena Chaudhary's user avatar
1 vote
0 answers
1k views

Testing Spring MVC: Null view when using standaloneSetup()

I cannot get spring mvc test framework to run correctly in standaloneSetup configuration, it always result in a null View. i am using thymeleaf as the view technology in a spring boot v1.2.7 ...
Joseph's user avatar
  • 3,145
13 votes
3 answers
9k views

Test maximum upload file size with MockMultipartFile

I create a file upload service with Spring Boot and test it with Spring Mock Mvc and MockMultipartFile. I want to test if an error is thrown when the maximum file size is exceeded. The following test ...
fabwu's user avatar
  • 652
2 votes
2 answers
3k views

Spring Security Test and MockMvc supply null custom UserDetails parameter to REST Controller

I'm trying to write an integration test that hits a REST endpoint and gets data for a specific authenticated user (the one I'm setting up in the test). I initially tried my setup with mockMvc = ...
akokskis's user avatar
  • 1,518
3 votes
0 answers
337 views

Apache Camel Integration test results in OutOfMemory

I have a simple Camel route that sends data to an external REST interface, integrated with Spring MVC. @RestController public class MyController { @Autowired private camelService ...
Leo's user avatar
  • 1,036
11 votes
1 answer
9k views

How to print request body using spring-test-mvc

I'm using spring-test-mvc to test my controller, but I can't find a way to print request body which is very inconvenient. with MockMvcResultHandlers.print() mvc.perform(put("/payment/1234") ....
Yugang Zhou's user avatar
  • 7,173
4 votes
1 answer
6k views

Spring load testing

I've implemented a testing unit using spring (mock mvc), and I'm looking for a tool to run this unit in many threads/processes (so it will act as load testing for my server). I've seen applications ...
user_s's user avatar
  • 1,078
3 votes
2 answers
3k views

Why aren't my Spring Controller's request mappings working inside of a mock WebApplicationContext?

I'm working from the Spring documentation here. My goal is to use the "webAppContextSetup" option to test my spring configuration along with my controller, but I'm having trouble getting the ...
user avatar
5 votes
3 answers
7k views

JMockit wasn't properly initialized

I am using junit 4.12, jmockit 1.19 & spring-test 4.1.1.RELEASE for testing my Spring MVC Java project. Order of these dependencies in my pom.xml: jmockit junit spring-test Test cases for ...
Dev's user avatar
  • 13.6k
0 votes
1 answer
134 views

How can i test existence specific data in session?

I want to test that session has proper TTL value on defferent request times. How can i do it? @ThreadSafe @RestController @SessionAttributes("TTL") @RequestMapping("/rest/") public class ...
kraken's user avatar
  • 484
1 vote
1 answer
1k views

How imports of static libraries work in Java / Spring?

I am experimenting MockMvc of Spring framework. To call perform method of MockMvc I would need to have an import as following import static org.springframework.test.web.servlet.request....
Jack's user avatar
  • 6,530
12 votes
2 answers
15k views

How to mock Eureka when doing Integration Tests in Spring?

I am running a simple Junit Testing a Controller in Spring Boot. The test code looks like this: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {...
Keyhan's user avatar
  • 121
19 votes
2 answers
18k views

Are Spring's MockMvc used for unit testing or integration testing?

Spring has 2 setups for the MockMvc: Standalone setup WebApplicationContext setup In general what kind of testing is MockMvc used for? Unit or Integration? or Both? Am i right in saying that using ...
SoftwareDeveloper's user avatar
1 vote
2 answers
2k views

Spring MVC Testing: Controller Method Parameters

I am trying to write tests for my Spring MVC web application. I have successfully configured a MockMvc object and can execute preform() operations, and can verify that my controller methods are ...
Mac's user avatar
  • 1,173
0 votes
1 answer
591 views

Issue with Bean Validation while testing a Spring Controller method [duplicate]

I have a Spring RestController that looks something like this: ... import javax.validation.Valid; ... @RestController @RequestMapping( value = "/users", consumes = { MediaType.APPLICATION_JSON }, ...
TJ-'s user avatar
  • 14.2k
4 votes
2 answers
8k views

unit test Spring MissingServletRequestParameterException JSON response

I have POST method in a Spring boot rest controller as follows @RequestMapping(value="/post/action/bookmark", method=RequestMethod.POST) public @ResponseBody Map<String, String> bookmarkPost( ...
Youssef Al Muhaidib's user avatar
1 vote
1 answer
4k views

Difference between @ContextConfiguration with "locations" or same config with "classes" and @ImportResource

I have a Java Spring MVC application that contains a unit test set up like this: // A configuration class. @Configuration @ImportResource({ "classpath:configuration/applicationContext.xml", "...
Ricardo van den Broek's user avatar
0 votes
1 answer
84 views

static import compile time error in spring-test-mvc

I am writing one test case for testing Spring MVC controllers. I have defined below entry in pom.xml: <properties> <project.build.sourceEncoding>UTF-8</project.build....
Nav's user avatar
  • 23
3 votes
1 answer
833 views

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 ...
Selwyn's user avatar
  • 3,168
2 votes
2 answers
4k views

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 @...
Selwyn's user avatar
  • 3,168
1 vote
1 answer
2k views

Spring MVC Junit tests are not being executed

I am trying to build tests for my MVC controllers. I followed the example on the docs and when doing mvn test the tests are not being executed. Any idea what I am missing? One weird log is that ...
special0ne's user avatar
  • 6,173
84 votes
5 answers
174k views

How to check JSON in response body with mockMvc

This is my method inside my controller which is annotated by @Controller @RequestMapping(value = "/getServerAlertFilters/{serverName}/", produces = "application/json; charset=utf-8") @...
Zeeshan's user avatar
  • 12.2k
2 votes
1 answer
2k views

Using RestTemplate in Spring Boot Spock specification with customized Jackson

I have a Spring Boot app that's using a customized Jackson ObjectMapper, and I would like to use the same customized mapper during testing. I used spring boot's method of automatically registering ...
nerdherd's user avatar
  • 2,538
6 votes
3 answers
2k views

How can I debug processing of hibernate.hbm2ddl.import_files value combined with hsqldb?

In a Java project I'm working on I've got the following setup for our unit tests: I'm using Spring Test MVC, @RunWith(SpringJUnit4ClassRunner.class) and @WebAppConfiguration to run the unit tests, ...
Ricardo van den Broek's user avatar
83 votes
5 answers
134k views

How to write a unit test for a Spring Boot Controller endpoint

I have a sample Spring Boot app with the following Boot main class @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(...
user6123723's user avatar
  • 10.8k
6 votes
1 answer
14k views

spring messagesource while testing

i have message source defined in my java config as : @Bean(name = "messageSource") public MessageSource messageSource() { ResourceBundleMessageSource messageSource = new ...
alizelzele's user avatar
0 votes
0 answers
85 views

Why mvn does not run test case class? [duplicate]

I have 5 test classes in the package: X.Y.Z Test Classes are those following: A,B,C,D,. They are identical. Everything is same in the classes. Only difference is that there is another fields in the ...
grep's user avatar
  • 5,575
2 votes
0 answers
71 views

How to test non-Spring controllers using Spring test framework

Can anybody please provide me some guidance or code sample on how to do this? HomePageController.java public class HomePageController extends HttpServlet { private static final Logger log = ...
Nital's user avatar
  • 5,954
3 votes
0 answers
726 views

Spring Rest locale test not working

I am trying to test localization. My configuration is as given below @Bean public MessageSource messageSource() { ReloadableResourceBundleMessageSource messageSource = new ...
Rohit's user avatar
  • 363
12 votes
3 answers
26k views

@ModelAttribute controller spring-mvc mocking

I want to test a controller which is using @ModelAttribute for one of its method arguments. public String processSaveAction(@ModelAttribute("exampleEntity") ExampleEntity exampleEntity) @...
Remik's user avatar
  • 45
15 votes
2 answers
16k views

Integration Testing Spring Boot With MockMVC

I'm having some trouble testing a Spring Boot application with MockMvc. I have the following test class: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {...
David's user avatar
  • 8,036
1 vote
1 answer
2k views

Spring Boot Java Config - split web (controllers, etc), and services

In my old XML config projects, I could do the following in my configurations mvc-context.xml <context:component-scan base-package="com.foo" use-default-filters="false"> <context:include-...
kabal's user avatar
  • 2,115
1 vote
2 answers
3k views

How to send json instead of params in spring test

I call Spring controller using org.springframework.test.web.servlet.MockMvc. It looks like this: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations = {"file:...
grep's user avatar
  • 5,575
6 votes
2 answers
5k views

Testing Spring Security and MvcMock using a custom UserDetails implementation

I'm trying to follow this article [1] to mock security in my Spring MvcMock test. The REST service I want to test looks like this: @RequestMapping(value = "/something/{id}", method = RequestMethod....
domi's user avatar
  • 2,217
0 votes
2 answers
930 views

Mocking expected result from service using spring testing framework

I want to write a test case for Restful web service using Spring testing framework. I mocked the service and able to run the testcase successfully. But, as service is mocked, it is returning the ...
NamingException's user avatar
4 votes
2 answers
5k views

MockMvc WebAppConfiguration: Load servlet mappings in web.xml

I'm writing integration tests using MockMvc, and I'm wondering if there's a way to load servlet mappings from web.xml (which normally shouldn't matter). I have a custom HandlerInteceptor that matches ...
nebulabrot's user avatar
4 votes
0 answers
1k views

Spring MVC Test with Tiles 3 in IntelliJ doesn't work

I have the following very simple Test: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @Transactional @ContextConfiguration(SpringTestContext.WEB_APPLICATION) public class ...
DerLucan's user avatar
0 votes
2 answers
2k views

Overriding ContextHierarchy and ContextConfiguration from a meta-annotation

We have test classes using a meta-annotation: @WebAppConfiguration @ContextHierarchy({ @ContextConfiguration(locations = {"/web/WEB-INF/spring.xml" }, name = "parent"), @ContextConfiguration("...
David E's user avatar
  • 888
7 votes
2 answers
13k views

How to unit test a secured controller which uses thymeleaf (without getting TemplateProcessingException)?

I am trying to run a unit test in spring-boot using spring security and a simple home (root) controller which uses thymeleaf for the template processing. I am trying to write some unit tests to verify ...
Aaron Zeckoski's user avatar
4 votes
1 answer
2k views

Is it possible to use MockMvc without SpringJUnit4ClassRunner?

I want to use MockMvc without SpringJUnit4ClassRunner. public static void main(String[] args) { WebApplicationContext wac = ...; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac)....
jack's user avatar
  • 1,911
0 votes
1 answer
2k views

Spring: NotWritablePropertyException

applicationContext <bean id="contentRegisteringBean" parent="abstractRegisteringBean" lazy-init="false"> <property name="processor"> <bean class="com.somepackage....
VB_'s user avatar
  • 45.3k
1 vote
2 answers
2k views

returning null in controller breaks MockMvc

I am using MockMvc with Mockito, drawing heavily on Spring greenhouse sample. I have a simple controller which returns a String viewname, or null if there is some sort of error. It works well in ...
f.khantsis's user avatar
  • 3,412
4 votes
3 answers
13k views

Spring MVC Test Framework - Unsupported Media Type

I am writing a test for controller using spring test mvc framework. I am trying to test a post request and it produces JSON. The actual code is running but test is failing. I an getting the error ...
vineet's user avatar
  • 269

1
4 5
6
7 8