Subversion Repositories eFlore/Applications.del

Rev

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