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());
}
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);
}
Aggregations