Search in sources :

Example 21 with MessageID

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()));
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Test(org.junit.Test)

Example 22 with MessageID

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()));
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Test(org.junit.Test)

Example 23 with MessageID

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);
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) ConsensusNode(com.github.dedis.popstellar.model.objects.ConsensusNode) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Aggregations

MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)23 Channel (com.github.dedis.popstellar.model.objects.Channel)10 Lao (com.github.dedis.popstellar.model.objects.Lao)10 LAORepository (com.github.dedis.popstellar.repository.LAORepository)10 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 Test (org.junit.Test)7 Base64DataUtils.generateMessageID (com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID)6 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)4 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)3 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)3 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)3 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)3 AddChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp)3 DeleteChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp)3 Chirp (com.github.dedis.popstellar.model.objects.Chirp)3 RollCall (com.github.dedis.popstellar.model.objects.RollCall)3 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)2 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)2 ConsensusNode (com.github.dedis.popstellar.model.objects.ConsensusNode)2