title: How to login a user with spring 3.2 new mvc testing
body: <p>This works fine until I have to test a service that needs a logged in user, how do I add user to context :</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration("classpath:applicationContext-test.xml")
  @WebAppConfiguration
  public class FooTest {
  @Autowired
  private WebApplicationContext webApplicationContext;
  
  private MockMvc mockMvc;
  
  @Resource(name = "aService")
  private AService aService; //uses logged in user
  
  @Before
  public void setup() {
      this.mockMvc = webAppContextSetup(this.webApplicationContext).build();
  }
  </code></pre>