Subversion Repositories eFlore/Applications.del

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
271 aurelien 1
package org.tela_botanica.del.test.services;
173 aurelien 2
 
3
import static org.junit.Assert.assertTrue;
4
 
5
import java.util.ArrayList;
6
import java.util.Date;
7
import java.util.List;
8
 
9
import org.junit.Test;
690 gduche 10
import org.tela_botanica.del.client.modeles.Contributeur;
173 aurelien 11
import org.tela_botanica.del.client.modeles.MoyenneVote;
838 aurelien 12
import org.tela_botanica.del.client.modeles.Observation;
173 aurelien 13
import org.tela_botanica.del.client.modeles.PropositionDetermination;
14
import org.tela_botanica.del.client.modeles.VoteDetermination;
15
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;
16
 
271 aurelien 17
public class CalculVoteDeterminationServiceTest {
173 aurelien 18
 
19
	@Test
271 aurelien 20
	public void testCalculerVoteDetermination() {
173 aurelien 21
 
22
		VoteDetermination voteDetermination = new VoteDetermination();
23
		voteDetermination.setVote(1);
24
		voteDetermination.setDate(new Date());
25
		voteDetermination.setContributeur("benjamin");
26
 
838 aurelien 27
		PropositionDetermination propositionDetermination = new PropositionDetermination(new Observation());
173 aurelien 28
		propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
882 aurelien 29
		propositionDetermination.setContributeur(new Contributeur("1", "contrib", "test", "contrib@test.com"));
173 aurelien 30
		propositionDetermination.setId("1");
31
		propositionDetermination.ajouterVoteDetermination(voteDetermination);
32
 
33
		MoyenneVote moyenneVote = CalculVoteDeterminationService
34
				.calculerVoteDetermination(propositionDetermination);
35
 
36
		assertTrue(moyenneVote.getScore() == 100);
37
 
38
	}
39
 
40
	@Test
271 aurelien 41
	public void testCalculerVoteDeterminationPlusPopulaire() {
173 aurelien 42
 
1098 aurelien 43
		Contributeur cIdent1 = new Contributeur("1", "Peronnet", "Aurélien", "aurelien@tela-botanica.org");
44
		Contributeur cIdent2 = new Contributeur("2", "Liens", "Benjamin", "benjamin@tela-botanica.org");
45
 
46
		Contributeur cAnon1 = new Contributeur("a1a5f7b8s8c4v2b3g4g5t7t8t94", "", "", "");
47
 
173 aurelien 48
		VoteDetermination voteDetermination1 = new VoteDetermination();
49
		voteDetermination1.setVote(1);
50
		voteDetermination1.setDate(new Date());
1098 aurelien 51
		voteDetermination1.setContributeur(cIdent1.getId());
52
		voteDetermination1.setAuteur(cIdent1);
173 aurelien 53
 
54
		VoteDetermination voteDetermination2 = new VoteDetermination();
55
		voteDetermination2.setVote(1);
56
		voteDetermination2.setDate(new Date());
1098 aurelien 57
		voteDetermination2.setContributeur(cIdent2.getId());
58
		voteDetermination2.setAuteur(cIdent2);
173 aurelien 59
 
60
		VoteDetermination voteDetermination3 = new VoteDetermination();
61
		voteDetermination3.setVote(0);
62
		voteDetermination3.setDate(new Date());
1098 aurelien 63
		voteDetermination3.setContributeur(cAnon1.getId());
64
		voteDetermination3.setAuteur(cAnon1);
173 aurelien 65
 
838 aurelien 66
		PropositionDetermination propositionDetermination = new PropositionDetermination(new Observation());
173 aurelien 67
		propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
882 aurelien 68
		propositionDetermination.setContributeur(new Contributeur("1", "contrib", "test", "contrib@test.com"));
173 aurelien 69
		propositionDetermination.setId("1");
70
		propositionDetermination.ajouterVoteDetermination(voteDetermination2);
71
		propositionDetermination.ajouterVoteDetermination(voteDetermination3);
72
 
838 aurelien 73
		PropositionDetermination propositionDetermination2 = new PropositionDetermination(new Observation());
173 aurelien 74
		propositionDetermination2.setEspece("Iris urticans");
882 aurelien 75
		propositionDetermination2.setContributeur(new Contributeur("1", "contrib", "test", "contrib@test.com"));
173 aurelien 76
		propositionDetermination2.setId("2");
77
		propositionDetermination2.ajouterVoteDetermination(voteDetermination1);
78
		propositionDetermination2.ajouterVoteDetermination(voteDetermination2);
79
		propositionDetermination2.ajouterVoteDetermination(voteDetermination3);
80
 
81
		List<PropositionDetermination> listePropositions = new ArrayList<PropositionDetermination>();
82
		listePropositions.add(propositionDetermination2);
83
		listePropositions.add(propositionDetermination);
84
 
85
		List<MoyenneVote> listeMoyenneVote = CalculVoteDeterminationService
86
				.calculerVoteDeterminationPlusPopulaire(listePropositions);
87
 
88
		// le premier vote est sensé être celui qui possède le plus gros score
1098 aurelien 89
		assertTrue(listeMoyenneVote.get(0).getIntituleAssocie().equals("Iris urticans"));
173 aurelien 90
	}
91
 
92
}