package com.sds.emp.users.service.impl;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.jmock.Expectations;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import anyframe.common.Page;
import anyframe.common.util.SearchVO;
import anyframe.core.basis.service.impl.BaseManagerMockTestCase;

import com.sds.emp.domain.Users;
import com.sds.emp.users.dao.UsersDao;
import com.sds.emp.users.services.impl.UsersServiceImpl;

public class UsersServiceImplTest extends BaseManagerMockTestCase {
    private UsersServiceImpl service = null;
    private UsersDao dao = null;

    @Before
    public void setUp() {
        dao = context.mock(UsersDao.class);
        service = new UsersServiceImpl(dao);
    }

    @After
    public void tearDown() {
        service = null;
    }

    @Test
    public void testGetUsers() throws Exception {
        log.debug("testing get...");
		
		final String userId = new String("CpVpDcTwTcBwToFzAzGs");
        final Users users = new Users();

        // set expected behavior on dao 
        context.checking(new Expectations() {{
            one(dao).get(with(equal(userId)));
            will(returnValue(users));
        }});

        Users result = service.get(userId);
        assertSame(users, result);
    }

    @Test
    public void testGetUserss() throws Exception {
        log.debug("testing getAll...");

		final Page usersPage = new Page();
		usersPage.setList(new ArrayList<Users>());
		final SearchVO search = new SearchVO();
		
        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).getList(search);
            will(returnValue(usersPage));
        }});

        Page result = service.getList(search);
        assertSame(usersPage, result);
    }

    @Test
    public void testSaveUsers() throws Exception {
        log.debug("testing save...");

		final String userId = new String("GdHdMoLbBrByKdEsAyFr");
        final Users users = new Users();
        // enter all required fields
        users.setAuthority("WgUoDkPlNaMgVoMdUxXoJdOzEdIfFeLqKyOlThIpEiWkHtFrNk");
        users.setPassword("GdIgWxSnLi");
        users.setUserName("AwWoBcVqQlIxCnTrMnSjKoMnJtDmPmTaSwKoWpKaFzZzThIdQz");
        
        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).save(with(same(users)));
        }});

        service.save(users);
    }

    @Test
    public void testRemoveUsers() throws Exception {
        log.debug("testing remove...");

		final String userId = new String("ZbTkWtMvHeOyTsVqRyYn");

        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).remove(with(equal(userId)));
        }});

        service.remove(userId);
    }
}
