Search in sources :

Example 6 with ElectionResultQuestion

use of com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion in project popstellar by dedis.

the class ElectionHandlerTest method testHandleElectionResult.

@Test
public void testHandleElectionResult() throws DataHandlingException {
    // Create the result Election message
    QuestionResult questionResult = new QuestionResult(electionQuestion.getBallotOptions().get(0), 2);
    ElectionResultQuestion electionResultQuestion = new ElectionResultQuestion("id", Collections.singletonList(questionResult));
    ElectionResult electionResult = new ElectionResult(Collections.singletonList(electionResultQuestion));
    MessageGeneral message = new MessageGeneral(SENDER_KEY, electionResult, GSON);
    // Call the message handler
    messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL.subChannel(election.getId()), message);
    // Check the Election is present with state RESULTS_READY and the results
    Optional<Election> electionOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getElection(election.getId());
    assertTrue(electionOpt.isPresent());
    assertEquals(EventState.RESULTS_READY, electionOpt.get().getState());
    assertEquals(Collections.singletonList(questionResult), electionOpt.get().getResultsForQuestionId("id"));
}
Also used : MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ElectionResult(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResult) ElectionResultQuestion(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion) Election(com.github.dedis.popstellar.model.objects.Election) QuestionResult(com.github.dedis.popstellar.model.network.method.message.data.election.QuestionResult) Test(org.junit.Test)

Aggregations

ElectionResultQuestion (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion)6 QuestionResult (com.github.dedis.popstellar.model.network.method.message.data.election.QuestionResult)4 Test (org.junit.Test)4 Election (com.github.dedis.popstellar.model.objects.Election)2 ArrayList (java.util.ArrayList)2 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)1 ElectionResult (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResult)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 LAORepository (com.github.dedis.popstellar.repository.LAORepository)1 DataHandlingException (com.github.dedis.popstellar.utility.error.DataHandlingException)1