{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2766","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2766/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2766/comments","events_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2766/events","html_url":"https://github.com/spring-projects/spring-boot/issues/2766","id":65970271,"number":2766,"title":"@WebIntegrationTest doesn't call RequestContextHolder.setRequestAttributes()","user":{"login":"aheusingfeld","id":534272,"avatar_url":"https://avatars.githubusercontent.com/u/534272?v=3","gravatar_id":"","url":"https://api.github.com/users/aheusingfeld","html_url":"https://github.com/aheusingfeld","followers_url":"https://api.github.com/users/aheusingfeld/followers","following_url":"https://api.github.com/users/aheusingfeld/following{/other_user}","gists_url":"https://api.github.com/users/aheusingfeld/gists{/gist_id}","starred_url":"https://api.github.com/users/aheusingfeld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aheusingfeld/subscriptions","organizations_url":"https://api.github.com/users/aheusingfeld/orgs","repos_url":"https://api.github.com/users/aheusingfeld/repos","events_url":"https://api.github.com/users/aheusingfeld/events{/privacy}","received_events_url":"https://api.github.com/users/aheusingfeld/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/spring-projects/spring-boot/milestones/36","html_url":"https://github.com/spring-projects/spring-boot/milestones/1.2.4","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/milestones/36/labels","id":1046287,"number":36,"title":"1.2.4","description":"","creator":{"login":"philwebb","id":519772,"avatar_url":"https://avatars.githubusercontent.com/u/519772?v=3","gravatar_id":"","url":"https://api.github.com/users/philwebb","html_url":"https://github.com/philwebb","followers_url":"https://api.github.com/users/philwebb/followers","following_url":"https://api.github.com/users/philwebb/following{/other_user}","gists_url":"https://api.github.com/users/philwebb/gists{/gist_id}","starred_url":"https://api.github.com/users/philwebb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philwebb/subscriptions","organizations_url":"https://api.github.com/users/philwebb/orgs","repos_url":"https://api.github.com/users/philwebb/repos","events_url":"https://api.github.com/users/philwebb/events{/privacy}","received_events_url":"https://api.github.com/users/philwebb/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":0,"state":"open","created_at":"2015-03-31T04:59:32Z","updated_at":"2015-04-03T20:08:36Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2015-04-02T17:11:10Z","updated_at":"2015-04-03T20:08:55Z","closed_at":null,"body":"I currently have a scenario where I use Spring Boot 1.2.2 with Spring HATEOAS 0.17 and want to run integration tests. I annotated my test class with `@WebIntegrationTest` but unfortunately one of the tests fails when `ControllerLinkBuilder.getCurrentRequest()` calls `RequestContextHolder.getRequestAttributes()` because it returns `null`. The point is that this specific test does not call `MockMvc.perform()` - which would trigger a call to `RequestContextHolder.setRequestAttributes(RequestAttributes, boolean)` - but just tests a utility method on the controller that uses `ControllerLinkBuilder.linkTo()`.\r\n\r\nI tried some modifications i.e. I switched from `@WebIntegrationTest` to `@IntegrationTest` and `@WebAppConfiguration`. I noticed that when I use `@WebIntegrationTest` the `ServletTestExecutionListener.setUpRequestContextIfNecessary()` is not executed correctly as it checks whether the test class is annotated with `@WebAppConfiguration`. \r\n\r\nIn the end I found two options to get my test working\r\n1. I run `MockMvc.perform(get(\"/\"))` as the first thing in the test... #urgs\r\n2. I call `RequestContextHolder.setRequestAttributes(servletWebRequest)` in my tests `@Before` method \r\n\r\nI don't think that either is the right way to do it, so suggestions are very welcome.\r\n\r\nIMHO this is related to #2299. :)"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/comments/89408465","html_url":"https://github.com/spring-projects/spring-boot/issues/2766#issuecomment-89408465","issue_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2766","id":89408465,"user":{"login":"philwebb","id":519772,"avatar_url":"https://avatars.githubusercontent.com/u/519772?v=3","gravatar_id":"","url":"https://api.github.com/users/philwebb","html_url":"https://github.com/philwebb","followers_url":"https://api.github.com/users/philwebb/followers","following_url":"https://api.github.com/users/philwebb/following{/other_user}","gists_url":"https://api.github.com/users/philwebb/gists{/gist_id}","starred_url":"https://api.github.com/users/philwebb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philwebb/subscriptions","organizations_url":"https://api.github.com/users/philwebb/orgs","repos_url":"https://api.github.com/users/philwebb/repos","events_url":"https://api.github.com/users/philwebb/events{/privacy}","received_events_url":"https://api.github.com/users/philwebb/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T20:08:55Z","updated_at":"2015-04-03T20:08:55Z","body":"Are you able to share the test in question?"}}