package jp.agentec.sinaburocast.service;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;

import javax.annotation.Resource;
import javax.mail.MessagingException;

import jp.agentec.sinaburocast.entity.Answer;
import jp.agentec.sinaburocast.entity.Enquete;
import jp.agentec.sinaburocast.entity.Member;
import jp.agentec.sinaburocast.entity.Question;
import jp.agentec.sinaburocast.entity.Reply;
import jp.agentec.sinaburocast.form.user.EnqueteForm;
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 ReplyServiceTest extends S2DaoTestCase {

	@Resource
	private ReplyService replyService;





	@Resource
	private MemberService memberService;

	@Resource
	private EnqueteService enqueteService;

	@Resource
	private QuestionService questionService;

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

	public static TestSuite suite() {
		TestSuite suite = new TestSuite("ReplyServiceTest");
		suite.addTest(new ReplyServiceTest("insertReplyTx"));
		suite.addTest(new ReplyServiceTest("findById"));
		suite.addTest(new ReplyServiceTest("findAllOrderById"));
		suite.addTest(new ReplyServiceTest("getAnswerTimes"));
		suite.addTest(new ReplyServiceTest("getReplyList"));
		suite.addTest(new ReplyServiceTest("setReplyLogic"));
		suite.addTest(new ReplyServiceTest("replyRegistAndMailSendLogicTx"));
		suite.addTest(new ReplyServiceTest("findBymemberId"));
		suite.addTest(new ReplyServiceTest("findBymemberIdList"));
		suite.addTest(new ReplyServiceTest("findByQuestionIdList"));
		suite.addTest(new ReplyServiceTest("findAllByEnqueteId"));
		suite.addTest(new ReplyServiceTest("deleteByEnqueteIdTx"));
		suite.addTest(new ReplyServiceTest("deleteByquestionIdTx"));
		suite.addTest(new ReplyServiceTest("getCountByEnqueteIdTx"));
		return suite;
	}

	public void findById(){
	    replyService.findById((long)1);
	}

	public void insertReplyTx(){
		Reply reply = new Reply();
		//reply.replyId = null;
		reply.memberId = 1;
		reply.questionId = 1;
		reply.answerId = 1;
		reply.answer = "1";
		reply.questionNo = 1;
		reply.enqueteId = 1;
		reply.answerTimes = 1;
		//reply.member = 1;
		//reply.answerReply = null;
		//reply.question = null;
		//reply.enquete = null;


	    System.out.println(replyService.insertReply(reply, "TESTCLASS01"));
	}


	public void findAllOrderById(){
	    System.out.println(replyService.findAllOrderById());
	}
	public void getAnswerTimes(){
	    System.out.println(replyService.getAnswerTimes(1, 1));
	}
	public void getReplyList(){
	    System.out.println(replyService.getReplyList(1, "1", "1"));

	}
	public void setReplyLogic(){

		EnqueteForm enqueteForm =new EnqueteForm();
		enqueteForm.eid = "1";
		enqueteForm.qid = "1";
		enqueteForm.timeid = "1";


	    replyService.setReplyLogic(enqueteForm);
	    System.out.println(enqueteForm);
	}
	public void replyRegistAndMailSendLogicTx()throws Exception{

		Member member  = memberService.findById(1);
		Enquete enquete = enqueteService.findById(1);
		ArrayList<Question> questionList = questionService.findAllOrderByEnqueteId("1");

		Question question = questionList.get(0);

		Answer answer = question.answerList.get(0);
		answer.answerIdValue="1";


		System.out.println(replyService.replyRegistAndMailSendLogic(member, questionList, enquete, false));

	}

	public void findBymemberId(){
	    System.out.println(replyService.findBymemberId(2));

	}
	public void findBymemberIdList(){
	    System.out.println(replyService.findBymemberIdList(2));

	}
	public void findByQuestionIdList(){
	    System.out.println(replyService.findByQuestionIdList(2));

	}
	public void findAllByEnqueteId(){
	    System.out.println(replyService.findAllByEnqueteId("2"));

	}
	public void deleteByEnqueteIdTx(){
	    System.out.println(replyService.deleteByEnqueteId("2"));

	}
	public void deleteByquestionIdTx(){
	    System.out.println(replyService.deleteByquestionId(1,"2"));

	}
	public void getCountByEnqueteId(){
	    System.out.println(replyService.getCountByEnqueteId(1));

	}
	/**
	 * @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 {
	}


}