package jp.agentec.sinaburocast.service; import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.Random; import javax.annotation.Resource; import jp.agentec.sinaburocast.action.admin.member.MemberSearchAction; import jp.agentec.sinaburocast.common.util.SinaburoUtil; import jp.agentec.sinaburocast.entity.AdminUser; 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.admin.enquete.EnqueteRegistForm; import jp.agentec.sinaburocast.form.admin.enquete.EnqueteSearchForm; import jp.agentec.sinaburocast.form.batch.EnqueteSumBatchForm; 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; import org.seasar.framework.beans.util.BeanMap; public class EnqueteServiceTest extends S2DaoTestCase { @Resource private EnqueteService enqueteService; public EnqueteServiceTest(String string) { super(string); } public static TestSuite suite() { TestSuite suite = new TestSuite("EnqueteServiceTest"); // suite.addTest(new EnqueteServiceTest("findById")); // suite.addTest(new EnqueteServiceTest("findEnqueteSummaryById")); // suite.addTest(new EnqueteServiceTest("findEnqueteSummaryByYmd")); // suite.addTest(new EnqueteServiceTest("findEnqueteByType")); // suite.addTest(new EnqueteServiceTest("insertEnqueteTx")); // suite.addTest(new EnqueteServiceTest("getEnqueteAnswerAgeBySql")); // suite.addTest(new EnqueteServiceTest("getEnqueteAnswerGenderBySql")); // suite.addTest(new EnqueteServiceTest("getEnqueteResultSumBySql")); // suite.addTest(new EnqueteServiceTest("getEnqueteByNameStartEnd")); // suite.addTest(new EnqueteServiceTest("enqueteDeleteTx")); // suite.addTest(new EnqueteServiceTest("getNextEnqueteNo")); // //suite.addTest(new EnqueteServiceTest("getEnqueteForRegistOrUpdateTx")); // suite.addTest(new EnqueteServiceTest("registEnqueteTx")); // suite.addTest(new EnqueteServiceTest("updateEnqueteTx")); // suite.addTest(new EnqueteServiceTest("getEnqueteResultBySql")); // suite.addTest(new EnqueteServiceTest("makeEnqueteResultForCsv")); // suite.addTest(new EnqueteServiceTest("enqueteCopyTx")); // suite.addTest(new EnqueteServiceTest("updateStatusToEnforcementTx")); // suite.addTest(new EnqueteServiceTest("updateStatusToCompleteTx")); suite.addTest(new EnqueteServiceTest("inserthukaTestData")); 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(enqueteService.findById(1)); } public void findEnqueteSummaryById(){ List<Enquete> list =enqueteService.findEnqueteSummaryById(); for (Enquete enquete : list) { System.out.println(enquete.enqueteSummary.enqueteId); System.out.println(enquete.enqueteName); System.out.println(enquete); } } public void findEnqueteSummaryByYmd(){ List<Enquete> list =enqueteService.findEnqueteSummaryByYmd("2012"); for (Enquete enquete : list) { System.out.println(enquete.enqueteSummary.enqueteId); System.out.println(enquete.enqueteName); System.out.println(enquete); } } public void findEnqueteByType(){ List<Enquete> list =enqueteService.findEnqueteByType("20120825",2); for (Enquete enquete : list) { //System.out.println(enquete.enqueteSummary.enqueteId); System.out.println(enquete.enqueteName); System.out.println(enquete); } } public void insertEnqueteTx() { Enquete enquete = new Enquete(); enquete.enqueteName = "TEST"; enquete.adminUserId = 1; enquete.enqueteNo = 1; enquete.status = 0; System.out.println(enqueteService.insertEnquete(enquete,"CLASSTEST")); } public void getEnqueteAnswerAgeBySql() { System.out.println(enqueteService.getEnqueteAnswerAgeBySql("1")); } public void getEnqueteAnswerGenderBySql() { System.out.println(enqueteService.getEnqueteAnswerGenderBySql("1")); } public void getEnqueteResultSumBySql() { System.out.println(enqueteService.getEnqueteResultSumBySql("1")); } public void getEnqueteByNameStartEnd() { EnqueteSearchForm enqueteSearchForm = new EnqueteSearchForm(); enqueteSearchForm.enqueteName = "KKKKK"; System.out.println(enqueteService.getEnqueteByNameStartEnd(enqueteSearchForm)); } public void enqueteDeleteTx() { AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; System.out.println(enqueteService.enqueteDelete("1",adminUserInfo)); } public void getNextEnqueteNo() { System.out.println(enqueteService.getNextEnqueteNo()); } public void registEnqueteTx() { EnqueteRegistForm enqueteRegistForm = new EnqueteRegistForm(); enqueteRegistForm.enquete = new Enquete(); enqueteRegistForm.enquete.enqueteName = "TEST12333"; enqueteRegistForm.enquete.adminUserId = 1; //enqueteRegistForm.enquete.enqueteNo = 1; enqueteRegistForm.enquete.status = 0; enqueteRegistForm.enquete.dispFlg = 0; enqueteRegistForm.enquete.endDate = "2012/11/12"; enqueteRegistForm.enquete.enqueteType = 0; enqueteRegistForm.enquete.pointNum = 0; enqueteRegistForm.enquete.version = 0; enqueteRegistForm.enquete.startDate ="2012/11/02"; AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; adminUserInfo.adminUserId =1; System.out.println(enqueteService.registEnquete(enqueteRegistForm,adminUserInfo)); } public void updateEnqueteTx() { EnqueteRegistForm enqueteRegistForm = new EnqueteRegistForm(); enqueteRegistForm.eid = "1"; enqueteRegistForm.enquete = new Enquete(); enqueteRegistForm.enquete.enqueteName = "TEST12333"; enqueteRegistForm.enquete.adminUserId = 1; //enqueteRegistForm.enquete.enqueteNo = 1; enqueteRegistForm.enquete.status = 0; enqueteRegistForm.enquete.dispFlg = 0; enqueteRegistForm.enquete.endDate = "2012/11/12"; enqueteRegistForm.enquete.enqueteType = 0; enqueteRegistForm.enquete.pointNum = 0; enqueteRegistForm.enquete.version = 0; enqueteRegistForm.enquete.startDate ="2012/11/02"; AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; adminUserInfo.adminUserId =1; System.out.println(enqueteService.updateEnquete(enqueteRegistForm,adminUserInfo)); } public void getEnqueteResultBySql() { System.out.println(enqueteService.getEnqueteResultBySql("1", 0, 1)); } public void makeEnqueteResultForCsv() throws UnsupportedEncodingException, Exception { EnqueteRegistForm enqueteRegistForm = new EnqueteRegistForm(); enqueteRegistForm.eid = "1"; enqueteRegistForm.enquete = new Enquete(); enqueteRegistForm.enquete.enqueteName = "TEST12333"; enqueteRegistForm.enquete.adminUserId = 1; //enqueteRegistForm.enquete.enqueteNo = 1; enqueteRegistForm.enquete.status = 0; enqueteRegistForm.enquete.dispFlg = 0; enqueteRegistForm.enquete.endDate = "2012/11/12"; enqueteRegistForm.enquete.enqueteType = 0; enqueteRegistForm.enquete.pointNum = 0; enqueteRegistForm.enquete.version = 0; enqueteRegistForm.enquete.startDate ="2012/11/02"; AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; adminUserInfo.adminUserId =1; EnqueteSumBatchForm enqueteSumBatchForm = new EnqueteSumBatchForm(); enqueteSumBatchForm.eid = "10"; enqueteSumBatchForm.enquete = new Enquete(); enqueteSumBatchForm.enquete.enqueteName = "TESTSTE"; enqueteSumBatchForm.enquete.endDate = "2012/11/12"; enqueteSumBatchForm.enquete.startDate ="2012/11/02"; System.out.println(enqueteService.makeEnqueteResultForCsv(enqueteSumBatchForm, "c:\\csv.csv")); } public void enqueteCopyTx() { AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; adminUserInfo.adminUserId =1; enqueteService.enqueteCopy(10,adminUserInfo.loginId); } public void updateStatusToEnforcementTx() { AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; adminUserInfo.adminUserId =1; enqueteService.updateStatusToEnforcement("TEST"); } public void updateStatusToCompleteTx() { AdminUser adminUserInfo = new AdminUser(); adminUserInfo.loginId = "CLASSTEST"; adminUserInfo.adminUserId =1; enqueteService.updateStatusToComplete("TEST"); } public QuestionService questionService; public ReplyService replyService; public void inserthukaTestData() throws ParseException{ // Random random =new Random(); // //List<Enquete> enqueteList = enqueteService.findEnqueteByTypeEnquete(3000); // List<Question> questionList = questionService.findAllOrderByEnqueteId("3000"); // BeanMap minMax =enqueteService.getMemberMinMax(); // Integer min = (Integer)minMax.get("min"); // Integer max = (Integer)minMax.get("max"); // min--; // //100名ずつ取り出してデータを登録する。 // long start = System.currentTimeMillis(); // int randomCnt=0; // ArrayList<Integer> answerIdList = new ArrayList<Integer>(); // while(min< max){ // List<Member> memberList = enqueteService.getMember((min+1), (min+=100)); // for(Member member : memberList){//会員数分 // // for (int i = 0; i < questionList.size(); i++) {//設問数分 // Question question = questionList.get(i); // randomCnt=random.nextInt(question.answerList.size())+1; // //answerIdList = new ArrayList<Integer>(); // //for(int cnt =0;cnt < randomCnt;cnt++){//回答数以下分 // Reply reply = new Reply(); // //reply.replyId = // reply.memberId = member.memberId; // reply.questionId =question.questionId ; // reply.answerId = question.answerList.get( random.nextInt(question.answerList.size())).answerId;//random //// while(answerIdList.contains(reply.answerId)){ //// reply.answerId =question.answerList.get( random.nextInt(question.answerList.size())).answerId;//random //// } // answerIdList.add(reply.answerId); // reply.answer=""; // reply.questionNo=question.questionNo; // reply.enqueteId=question.enqueteId; // reply.answerTimes=1; // reply.zipCode=member.zipCode; // reply.genderCd=member.genderCd; // reply.age=SinaburoUtil.getAge(member.birthday); // replyService.insertReply(reply,"huka"); // //} // } // } // } // System.out.println("所要時間:"+((System.currentTimeMillis()-start)/1000)); } // public static void main(String[] args) { // // for (int i = 0; i < 10; i++) { // System.out.println(new Random().nextInt(3)); // } // // } //Random }