Questions tagged [spring-mvc-test]
241 questions
0
votes
1 answer
spring mvc servlet 3 async response no database result in test
I'm testing the new servlet 3 asynchronous requests in my new project and get stuck while testing the controller.
I have a controller method like this:
@RequestMapping(value = "/thumbnails", method = RequestMethod.GET)
public…

conscience
- 463
- 6
- 21
0
votes
1 answer
Spring MVC Test with security and session
I am using spring security form based login mechanism,after sucessful login I am storing one object in session.
Using that object stored in session to decide the fate on next requests.But now when I am testing that using
spring mvc test with…

MasterCode
- 975
- 5
- 21
- 44
0
votes
1 answer
I would like to test the resolved view name for a spring controller
Simplist case my controller returns
new ModelAndView("hello").
"hello" maps/resolves to (in an xml file) to a jsp,
e.g. "hello" may map to WEB-INF/myapp/goodbye.jsp.
I would like to write a test for my controller to verify the view name being…

Warren Goldman
- 85
- 1
- 3
- 7
0
votes
1 answer
Spring Junit4TestRunner Autowired null
public interface Animal {
public String getName();
public int getAge();
}
@Component
public class Dog implements Animal{
@Override public String getName() {
return "Puppy";
}
@Override public int getAge() {
…

arulprakash
- 22
- 1
- 6
0
votes
0 answers
Use @Primary to precede an @Component/@Service annotated class
In my project I have a service with the @Service annotation.
@Service
public class ExampleService { ... }
I would like to override this service with a Mockito-mock, using a configuration file for my test in the following way:
public class…

raichu
- 688
- 2
- 8
- 15
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
spring-mvc-test auto rollback transactions configured with AOP xml on Service layer
I have the following Spring MVC app stack:
Controller -> Service -> DAO (Repository) -> Entity -> MySql InnoDB
Transactions are configured to start from the Service layer using AOP xml config, and the app works perfectly:
…

Amir Jamak
- 351
- 1
- 2
- 15
0
votes
1 answer
Spring MockMvc - Custom Validators are not registered/called in Spring Container
@Configuration
@EnableWebMvc
@ComponentScan("com.xyz.web")
class BaseTestConfig extends WebMvcConfigurerAdapter {
@Bean
AccountService accountService() {
return Mockito.mock(AccountService)
}
}
class Test {
@Autowired…

led
- 611
- 4
- 11
- 18
0
votes
1 answer
Spring MVC Java-based configuration can't see class-path properties file
I'm trying to migrate my web-app from XML-based configuration to Java-based one. I have properties files under "\src\main\resources\" directory. In XML configuration I had such bean:

Dmytro Titov
- 2,802
- 6
- 38
- 60
0
votes
1 answer
MockMvc does not loads named query
When I run my web application on tomcat server my named query is loaded properly:
But when I use MockMvc hibernate cannot find any named queries. As a result I have en error when executing tests
MockHttpServletResponse:
Status = 401
…

Andrew
- 106
- 5
0
votes
0 answers
How do you make spring-mvc-test framework stop trapping exceptions?
I am using the Spring MVC Test framework in Spring 3.2.4, and one problem I have with it is that it continuously traps exceptions. For example, if you perform a POST with JSON data (or anything really), and a NullPointerException or Jackson…

egervari
- 22,372
- 32
- 121
- 175
0
votes
1 answer
How to efficiently create a base test class for spring mvc integration tests
I have a series of integration-tests that I want to test my spring-mvc/spring-data-jpa stack with. Unfortunately the build time is ridiculous and only getting worse with each new integration tests. It looks as if each separate test is going thru…

sonoerin
- 5,015
- 23
- 75
- 132
-1
votes
1 answer
getting error in spock test case while performing test for rest controller
I am writing a test case for my controller in spring boot below is my controller
@RestController
public class HelloController {
@RequestMapping("/hello")
public String helloWorld(){
return "hello world";
}
}
Now I writing the…

hgjioohjh aderwsdt
- 21
- 2
-1
votes
1 answer
Rest controller test with @WebMvcTest, Could not instantiate JAXBContext for PagedResources
I have some tests that were failing with Error creating bean with name 'entityManagerFactory' this answer solved it for me https://stackoverflow.com/a/47504698/6945345 but broke my Controller test with Could not instantiate JAXBContext for class…

wdr
- 37
- 7
-1
votes
1 answer
Spring MVC - testing services
i have a question regarding service layer testing in Spring framework.
I have a class ProductService which has method:
public List getProducts() {
return productDAO.getProducts();
}
Is there any way to test it properly? This method…

thosenumbers
- 55
- 1
- 10