Subversion Repositories eFlore/Applications.del

Rev

Rev 1503 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.del.test.services;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.junit.Test;
import org.tela_botanica.del.client.modeles.Contributeur;
import org.tela_botanica.del.client.modeles.MoyenneVote;
import org.tela_botanica.del.client.modeles.Observation;
import org.tela_botanica.del.client.modeles.PropositionDetermination;
import org.tela_botanica.del.client.modeles.VoteDetermination;
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;

public class CalculVoteDeterminationServiceTest {

        @Test
        public void testCalculerVoteDetermination() {

                Observation obs = new Observation();
                
                VoteDetermination voteDetermination = new VoteDetermination();
                voteDetermination.setVote(1);
                voteDetermination.setDate(new Date());
                voteDetermination.setContributeur("benjamin");

                PropositionDetermination propositionDetermination = new PropositionDetermination(obs);
                propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
                propositionDetermination.setContributeur(new Contributeur("1", "contrib", "test", "contrib@test.com"));
                propositionDetermination.setId("1");
                propositionDetermination.ajouterVoteDetermination(voteDetermination);
                obs.ajouterPropositionDetermination(propositionDetermination);

                MoyenneVote moyenneVote = CalculVoteDeterminationService
                                .calculerVoteDetermination(propositionDetermination);

                assertTrue(moyenneVote.getScore() == 100);

        }
        
        @Test
        public void testCalculerVoteDeterminationPlusPopulaire() {
                
                Observation obs = new Observation();

                Contributeur cIdent1 = new Contributeur("1", "Peronnet", "Aurélien", "aurelien@tela-botanica.org");
                Contributeur cIdent2 = new Contributeur("2", "Liens", "Benjamin", "benjamin@tela-botanica.org");
                
                Contributeur cAnon1 = new Contributeur("a1a5f7b8s8c4v2b3g4g5t7t8t94", "", "", "");
                
                VoteDetermination voteDetermination1 = new VoteDetermination();
                voteDetermination1.setVote(1);
                voteDetermination1.setDate(new Date());
                voteDetermination1.setContributeur(cIdent1.getId());
                voteDetermination1.setAuteur(cIdent1);
                
                VoteDetermination voteDetermination2 = new VoteDetermination();
                voteDetermination2.setVote(1);
                voteDetermination2.setDate(new Date());
                voteDetermination2.setContributeur(cIdent2.getId());
                voteDetermination2.setAuteur(cIdent2);
                
                VoteDetermination voteDetermination3 = new VoteDetermination();
                voteDetermination3.setVote(0);
                voteDetermination3.setDate(new Date());
                voteDetermination3.setContributeur(cAnon1.getId());
                voteDetermination3.setAuteur(cAnon1);

                PropositionDetermination propositionDetermination = new PropositionDetermination(obs);
                propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
                propositionDetermination.setContributeur(new Contributeur("1", "contrib", "test", "contrib@test.com"));
                propositionDetermination.setId("1");
                propositionDetermination.ajouterVoteDetermination(voteDetermination2);
                propositionDetermination.ajouterVoteDetermination(voteDetermination3);
                
                obs.ajouterPropositionDetermination(propositionDetermination);
                
                PropositionDetermination propositionDetermination2 = new PropositionDetermination(obs);
                propositionDetermination2.setEspece("Iris urticans");
                propositionDetermination2.setContributeur(new Contributeur("1", "contrib", "test", "contrib@test.com"));
                propositionDetermination2.setId("2");
                propositionDetermination2.ajouterVoteDetermination(voteDetermination1);
                propositionDetermination2.ajouterVoteDetermination(voteDetermination2);
                propositionDetermination2.ajouterVoteDetermination(voteDetermination3);
                
                obs.ajouterPropositionDetermination(propositionDetermination2);
                
                List<PropositionDetermination> listePropositions = new ArrayList<PropositionDetermination>();
                listePropositions.add(propositionDetermination2);
                listePropositions.add(propositionDetermination);

                List<MoyenneVote> listeMoyenneVote = CalculVoteDeterminationService
                                .calculerVoteDeterminationPlusPopulaire(listePropositions);
                
                for (Iterator iterator = listeMoyenneVote.iterator(); iterator
                                .hasNext();) {
                        MoyenneVote moyenneVote = (MoyenneVote) iterator.next();
                        System.out.println(moyenneVote.getScore());
                }

                // le premier vote est sensé être celui qui possède le plus gros score
                assertTrue(listeMoyenneVote.get(0).getIntituleAssocie().equals("Iris urticans"));
        }

}