Author: echatellier Date: 2010-03-10 12:43:56 +0100 (Wed, 10 Mar 2010) New Revision: 2925 Log: Ajout d'une methode pour ajouter un nombre de fix de vote sur un sondage sans liste de votants Modified: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java Modified: branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-10 09:48:04 UTC (rev 2924) +++ branches/pollen-1.2.3-1.2.x/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-10 11:43:56 UTC (rev 2925) @@ -27,6 +27,7 @@ import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.PollAccountDAO; import org.chorem.pollen.business.persistence.PollDAO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.persistence.Vote; @@ -74,7 +75,7 @@ config.remove("hibernate.hbm2ddl.auto"); try { - new ScalingVote().doInsert(); + new ScalingVote().doInsertFixedNumber(); } catch(Exception e) { if (log.isErrorEnabled()) { @@ -91,7 +92,7 @@ * * @throws TopiaException */ - public void doInsert() throws TopiaException { + public void doInsertWithVotingList() throws TopiaException { TopiaContext rootContext = TopiaContextFactory.getContext(config); TopiaContext context = rootContext.beginTransaction(); @@ -152,4 +153,71 @@ rootContext.closeContext(); } + + /** + * Insert a lot of vote into poll. + * + * This version find a poll with his name and add a vote + * for each votant in voting list. + * + * @throws TopiaException + */ + public void doInsertFixedNumber() throws TopiaException { + TopiaContext rootContext = TopiaContextFactory.getContext(config); + TopiaContext context = rootContext.beginTransaction(); + + PollDAO pollDAO = PollenModelDAOHelper.getPollDAO(context); + VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(context); + PollAccountDAO pollAccountDAO = PollenModelDAOHelper.getPollAccountDAO(context); + VoteToChoiceDAO voteToChoiceDAO = PollenModelDAOHelper.getVoteToChoiceDAO(context); + + // find a poll with his name + Poll poll = pollDAO.findByTitle("test pagination 3000"); + + for (int i = 1 ; i <= 4200 ; ++i) { + + PollAccount pollAccount = pollAccountDAO.create(); + pollAccount.setVotingId("Test " + i); + + if (log.isInfoEnabled()) { + log.info("Create vote for " + pollAccount.getVotingId()); + } + + Vote myNewVote = voteDAO.create(); + myNewVote.setPollAccount(pollAccount); + myNewVote.setPoll(poll); + myNewVote.setWeight(new Double(1)); + myNewVote.setAnonymous(Boolean.FALSE); + + List<Choice> choices = new ArrayList<Choice>(); + choices.add(poll.getChoice().get(0)); + + List<VoteToChoice> voteToChoices = new ArrayList<VoteToChoice>(); + + if (i % 2 == 0) { + VoteToChoice voteToChoice = voteToChoiceDAO.create(); + voteToChoice.setChoice(poll.getChoice().get(0)); + voteToChoice.setVoteValue(1); + voteToChoice.setVote(myNewVote); + voteToChoices.add(voteToChoice); + } + else { + VoteToChoice voteToChoice2 = voteToChoiceDAO.create(); + voteToChoice2.setChoice(poll.getChoice().get(1)); + voteToChoice2.setVoteValue(2); + voteToChoice2.setVote(myNewVote); + voteToChoices.add(voteToChoice2); + } + + myNewVote.setChoiceVoteToChoice(voteToChoices); + myNewVote.update(); + poll.getVote().add(myNewVote); + + } + poll.update(); + context.commitTransaction(); + context.closeContext(); + + rootContext.closeContext(); + } }