package org.bench4q.master.unitTest.service;

import static org.junit.Assert.*;
import org.bench4q.master.domain.repository.UserRepository;
import org.bench4q.master.domain.service.UserService;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class Test_UserService {
	private UserService userService;
	private UserRepository usreRepository;

	private UserService getUserService() {
		return userService;
	}

	@Autowired
	private void setUserService(UserService userService) {
		this.userService = userService;
	}

	private UserRepository getUsreRepository() {
		return usreRepository;
	}

	@Autowired
	private void setUsreRepository(UserRepository usreRepository) {
		this.usreRepository = usreRepository;
	}

	@Test
	public void test() {
		assertNotNull(this.getUserService());
	}

	@Test
	public void testRegister() {
		assertTrue(this.getUserService().register("test1", "test1",(byte)1));
	}

	@Test
	public void testValidate() {
		this.getUserService().register("test1", "test1",(byte)1);
		assertTrue(this.getUserService().validateUser("test1", "test1",
				(byte) 0));
	}

	@Test
	public void testGetUserByName() {
		this.getUserService().register("test1", "test1",(byte)1);
		assertNotNull(this.getUsreRepository().getUser("test1"));
	}

	@After
	public void cleanUp() {
		this.getUsreRepository().detach("test1");
	}
}
