Questions tagged [spring-test-mvc]

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

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

spring-test-mvc might be included in the Spring Framework version 3.2.x

Spring One DC 2012 slides

356 questions
1
vote
2 answers

test chained REST API's in spring boot

What is the proper way of mocking external API call inside my RestController. Meaning my RestController actually does these steps: transformation on date call external API with the data respond with the external API response Can't copy/paste…
1
vote
1 answer

Spring boot test controllers when no app class present

So i have a multi maven module project, with a module for controllers and a module that contains the spring boot start up application class. myApp - deployment (module) - controllers (module) In the controllers module i want to be able to…
user1555190
  • 2,803
  • 8
  • 47
  • 80
1
vote
2 answers

Configure two ports for springboot integration testing

Im pretty new to spring framework and my JAVA application(Say Project_A) running at http://localhost:8080, does processing and forwards the processed content to http://localhost:9090 where another application(Say Project_B) is running. Project_B…
1
vote
1 answer

spring mock mvc tests with api being invoked from external system

I have an api(API 1) which is being stubbed through MockMvc.When I post on this API through this mock object, a request goes out to external system which in turn invokes api (API 2) of my system. Since this API 2 is invoked through http channel…
user2599052
  • 1,056
  • 3
  • 12
  • 27
1
vote
1 answer

Testing a secure REST endpoint with Spring MVC Test Framework

I am trying to test a secure REST method, using Spring MVC Test Framework. val result = this.mockMvc!! .perform(get("/ping").with(SecurityMockMvcRequestPostProcessors.user("user"))) .andDo(MockMvcResultHandlers.print()) …
1
vote
2 answers

How to disable securty on controller Unit Test?

I try to disable the security on controller Unit test but I allways have error 403. My Unit Test : @RunWith(SpringRunner.class) @WebMvcTest(value = MeasureController.class, secure = false) @AutoConfigureMockMvc(secure = false) public class…
BokC
  • 333
  • 5
  • 19
1
vote
1 answer

Spring MVC unit test for DeferredResult doesn't call timeout callback

I'm using Spring 4.3.18 and Spring Boot 1.5.14 on Java 7. I'm implementing a RestController endpoint which returns a DeferredResult with a timeout callback. I'm trying to write a unit test for the timeout callback, but I can't get a MockMvc unit…
Kenster
  • 23,465
  • 21
  • 80
  • 106
1
vote
0 answers

springmvc and jmockit error

I am running into an issue while mocking the autowired component of a mvc controller. Here is my code, I am on Jmockit 1.28 @RunWith(SpringJUnit4ClassRunner.class) @WebMvcTest(value = SomeController.class, secure = false) public class…
user3221430
  • 71
  • 1
  • 6
1
vote
0 answers

best way to convert MockHttpServletResponse to ResponseEntity

just wondering what is the simpler/best way to convert MockHttpServletResponse to ResponseEntity the background is I have my tests currently using TestRestTemplate and plan to migrate them to use MockMvc the situation is that …
Miguel Costa
  • 627
  • 1
  • 12
  • 30
1
vote
0 answers

How can I use ActiveProfiles with Spring Boot tests with WebMvcTest?

I have a unit test that is testing a RestController using @WebMvcTest. The the controller class autowires a service class that I would like to mock. I found that I can use @Profile and @Configuration to create a config class for specifying primary…
srowley
  • 837
  • 1
  • 12
  • 24
1
vote
1 answer

Failed to load ApplicationContext (Spring Boot)

I'm trying to test my application following samples on the Spring website. These are my dependencies: dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') …
Lithicas
  • 3,793
  • 7
  • 23
  • 32
1
vote
0 answers

Spring Boot Controller IT test not finding class path resources

I have a spring boot web app with both unit tests and IT tests. The application also has a DAL, and I have unit tests in the DAL layer that use an in memory H2 database for tests. The h2 database is created using the same liquibase changelog as my…
SME
  • 489
  • 1
  • 10
  • 21
1
vote
1 answer

Spring's MockMvc picks up wrong handler method

I have a controller that contains 2+ methods: @RequestMapping(method = RequestMethod.GET, value = "/{uuid}", produces = "application/json") public MyObject findByUuid( @PathVariable("uuid") String uuid) { ... } @RequestMapping(method =…
Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71
1
vote
1 answer

What is sense of @Mock annotation?

I have a question about bean creation in testing of controllers. For example, there is a such test @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {MainApplicationConfiguration.class,…
Alex
  • 3,923
  • 3
  • 25
  • 43
1
vote
1 answer

No x-auth-token header is found after logging in using Spring's MockMVC test API

Please consider the following configuration Spring Boot application: @SpringBootApplication @EnableRedissonHttpSession @ComponentScan(basePackages = { "com.ja.pi" }) public class PiApp { @Bean public HttpSessionStrategy…