fr.mael.microrss.BaseTest.java Source code

Java tutorial

Introduction

Here is the source code for fr.mael.microrss.BaseTest.java

Source

/*
   Copyright  2013 Mael Le Guvel
   This work is free. You can redistribute it and/or modify it under the
   terms of the Do What The Fuck You Want To Public License, Version 2,
   as published by Sam Hocevar. See the COPYING file for more details.
*/
package fr.mael.microrss;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;

import fr.mael.microrss.domain.User;
import fr.mael.microrss.service.UserService;

public abstract class BaseTest {

    @Autowired
    protected UserService userService;

    protected void login(Integer id) {
        User user = userService.get(id);
        SecurityContextHolder.getContext()
                .setAuthentication(new UsernamePasswordAuthenticationToken(user, "admin"));
    }

}