Search in sources :

Example 1 with ElectionEnd

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

the class ElectionHandlerTest method testHandleElectionEnd.

@Test
public void testHandleElectionEnd() throws DataHandlingException {
    // Create the end Election message
    ElectionEnd electionEnd = new ElectionEnd(election.getId(), lao.getId(), "");
    MessageGeneral message = new MessageGeneral(SENDER_KEY, electionEnd, GSON);
    // Call the message handler
    messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL.subChannel(election.getId()), message);
    // Check the Election is present with state CLOSED and the results
    Optional<Election> electionOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getElection(election.getId());
    assertTrue(electionOpt.isPresent());
    assertEquals(EventState.CLOSED, electionOpt.get().getState());
}
Also used : ElectionEnd(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionEnd) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Election(com.github.dedis.popstellar.model.objects.Election) Test(org.junit.Test)

Example 2 with ElectionEnd

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

the class LaoDetailViewModel method endElection.

public void endElection(Election election) {
    Log.d(TAG, "ending election with name : " + election.getName());
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    Channel channel = election.getChannel();
    String laoId = lao.getId();
    ElectionEnd electionEnd = new ElectionEnd(election.getId(), laoId, election.computerRegisteredVotes());
    Log.d(TAG, PUBLISH_MESSAGE);
    Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, electionEnd).subscribe(() -> {
        Log.d(TAG, "ended election successfully");
        endElectionEvent();
    }, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_end_election));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ElectionEnd(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionEnd) Channel(com.github.dedis.popstellar.model.objects.Channel) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)

Aggregations

ElectionEnd (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionEnd)2 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)1 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)1 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 Election (com.github.dedis.popstellar.model.objects.Election)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Test (org.junit.Test)1