use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class ChirpHandlerTest method testHandleAddChirp.
@Test
public void testHandleAddChirp() throws DataHandlingException {
MessageGeneral message = new MessageGeneral(SENDER_KEY, ADD_CHIRP, GSON);
messageHandler.handleMessage(laoRepository, messageSender, CHIRP_CHANNEL, message);
Optional<Chirp> chirpOpt = LAO.getChirp(message.getMessageId());
assertTrue(chirpOpt.isPresent());
Chirp chirp = chirpOpt.get();
assertEquals(message.getMessageId(), chirp.getId());
assertEquals(CHIRP_CHANNEL, chirp.getChannel());
assertEquals(SENDER, chirp.getSender());
assertEquals(TEXT, chirp.getText());
assertEquals(CREATION_TIME, chirp.getTimestamp());
assertEquals(PARENT_ID, chirp.getParentId());
Map<MessageID, Chirp> chirps = LAO.getAllChirps();
assertEquals(1, chirps.size());
assertEquals(chirp, chirps.get(chirp.getId()));
}
use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class ChirpHandlerTest method testHandleDeleteChirp.
@Test
public void testHandleDeleteChirp() throws DataHandlingException {
MessageGeneral message = new MessageGeneral(SENDER_KEY, ADD_CHIRP, GSON);
messageHandler.handleMessage(laoRepository, messageSender, CHIRP_CHANNEL, message);
final DeleteChirp DELETE_CHIRP = new DeleteChirp(message.getMessageId(), DELETION_TIME);
MessageGeneral message2 = new MessageGeneral(SENDER_KEY, DELETE_CHIRP, GSON);
messageHandler.handleMessage(laoRepository, messageSender, CHIRP_CHANNEL, message2);
Optional<Chirp> chirpOpt = LAO.getChirp(message.getMessageId());
assertTrue(chirpOpt.isPresent());
Chirp chirp = chirpOpt.get();
assertEquals(message.getMessageId(), chirp.getId());
assertEquals(CHIRP_CHANNEL, chirp.getChannel());
assertEquals(SENDER, chirp.getSender());
assertEquals(EMPTY_STRING, chirp.getText());
assertEquals(CREATION_TIME, chirp.getTimestamp());
assertEquals(PARENT_ID, chirp.getParentId());
Map<MessageID, Chirp> chirps = LAO.getAllChirps();
assertEquals(1, chirps.size());
assertEquals(chirp, chirps.get(chirp.getId()));
}
use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusElectTest.
// handle an elect from node2
// This should add an attempt from node2 to start a consensus (in this case for starting an
// election)
private void handleConsensusElectTest() throws DataHandlingException {
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electMsg);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
assertTrue(electInstanceOpt.isPresent());
ElectInstance electInstance = electInstanceOpt.get();
assertEquals(electMsg.getMessageId(), electInstance.getMessageId());
assertEquals(NODE_2, electInstance.getProposer());
assertEquals(CONSENSUS_CHANNEL, electInstance.getChannel());
assertEquals(CREATION_TIME, electInstance.getCreation());
assertEquals(VALUE, electInstance.getValue());
assertEquals(KEY, electInstance.getKey());
assertTrue(electInstance.getAcceptorsToMessageId().isEmpty());
assertEquals(Sets.newSet(ORGANIZER, NODE_2, NODE_3), electInstance.getNodes());
Map<MessageID, ElectInstance> messageIdToElectInstance = lao.getMessageIdToElectInstance();
assertEquals(1, messageIdToElectInstance.size());
assertEquals(electInstance, messageIdToElectInstance.get(electInstance.getMessageId()));
assertEquals(3, lao.getNodes().size());
ConsensusNode organizer = lao.getNode(ORGANIZER);
ConsensusNode node2 = lao.getNode(NODE_2);
ConsensusNode node3 = lao.getNode(NODE_3);
assertNotNull(organizer);
assertNotNull(node2);
assertNotNull(node3);
Optional<ElectInstance> organizerElectInstance = organizer.getLastElectInstance(INSTANCE_ID);
Optional<ElectInstance> node2ElectInstance = node2.getLastElectInstance(INSTANCE_ID);
Optional<ElectInstance> node3ElectInstance = node3.getLastElectInstance(INSTANCE_ID);
assertEquals(Optional.empty(), organizerElectInstance);
assertTrue(node2ElectInstance.isPresent());
assertEquals(electInstance, node2ElectInstance.get());
assertEquals(Optional.empty(), node3ElectInstance);
}
Aggregations