package jp.agentec.sinaburocast.service;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.annotation.Resource;

import jp.agentec.sinaburocast.common.util.SinaburoUtil;
import jp.agentec.sinaburocast.entity.GiftExchange;
import jp.agentec.sinaburocast.form.admin.enquete.GiftExchangeSearchForm;
import junit.framework.TestSuite;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.seasar.dao.unit.S2DaoTestCase;

public class GiftExchangeServiceTest extends S2DaoTestCase {

	@Resource
	private GiftExchangeService giftExchangeService;

	public GiftExchangeServiceTest(String string) {
		super(string);
	}

	public static TestSuite suite() {
		TestSuite suite = new TestSuite("GiftExchangeServiceTest");
		suite.addTest(new GiftExchangeServiceTest("insertGiftExchangeTx"));
		suite.addTest(new GiftExchangeServiceTest("findById"));
		suite.addTest(new GiftExchangeServiceTest("findAllOrderById"));
		suite.addTest(new GiftExchangeServiceTest("findBymemberIdList"));
		suite.addTest(new GiftExchangeServiceTest("findAllByPaging"));
		suite.addTest(new GiftExchangeServiceTest("getGiftExchangeForCsv"));
		return suite;
	}


	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
        include("app.dicon");
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	public void findById() {
		System.out.println(giftExchangeService.findById(1));
	}

	public void insertGiftExchangeTx(){
		GiftExchange giftExchange = new GiftExchange();

		giftExchange.memberId = 1;
		giftExchange.giftId = 1;
		giftExchange.cnt = 101;
		giftExchange.applyDate = SinaburoUtil.getTimestamp();
		System.out.println(giftExchangeService.insertGiftExchange(giftExchange,"test"));

	}

	public void findAllOrderById(){

		List<GiftExchange> list =giftExchangeService.findAllOrderById();
		for (GiftExchange giftExchange : list) {
			//System.out.println(enquete.enqueteSummary.enqueteId);
			System.out.println(giftExchange.memberId);
			System.out.println(giftExchange.giftId);
			System.out.println(giftExchange);
		}
	}

	public void findBymemberIdList() {
		System.out.println(giftExchangeService.findBymemberIdList(1));
	}

	public void findAllByPaging() {
		GiftExchangeSearchForm giftExchangeSearchForm = new GiftExchangeSearchForm();
		System.out.println(giftExchangeService.findAllByPaging(giftExchangeSearchForm));
	}

	public void getGiftExchangeForCsv() throws UnsupportedEncodingException, Exception {
		GiftExchangeSearchForm giftExchangeSearchForm = new GiftExchangeSearchForm();
		System.out.println(giftExchangeService.getGiftExchangeForCsv(giftExchangeSearchForm));
	}

}