use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class LaoDetailViewModel method dispatchLaoUpdate.
/**
* Helper method for updateLaoWitnesses and updateLaoName to send a stateLao message
*/
private void dispatchLaoUpdate(String desc, UpdateLao updateLao, Lao lao, Channel channel, MessageGeneral msg) {
StateLao stateLao = new StateLao(updateLao.getId(), updateLao.getName(), lao.getCreation(), updateLao.getLastModified(), lao.getOrganizer(), msg.getMessageId(), updateLao.getWitnesses(), new ArrayList<>());
disposables.add(networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, stateLao).subscribe(() -> Log.d(TAG, "updated " + desc), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_state_lao)));
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral 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.network.method.message.MessageGeneral 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.network.method.message.MessageGeneral in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusLearnTest.
// handle a learn from node3 for the elect of node2
// This test need be run after the elect message was handled, else the messageId would be invalid
private void handleConsensusLearnTest() throws DataHandlingException {
ConsensusLearn learn = new ConsensusLearn(INSTANCE_ID, messageId, CREATION_TIME, true, Collections.emptyList());
MessageGeneral learnMsg = getMsg(NODE_3_KEY, learn);
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, learnMsg);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
assertTrue(electInstanceOpt.isPresent());
ElectInstance electInstance = electInstanceOpt.get();
assertEquals(ACCEPTED, electInstance.getState());
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class ConsensusHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, DataHandlingException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(ORGANIZER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(ORGANIZER);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
lao = new Lao(LAO_ID);
laoRepository.getLaoById().put(LAO_ID, new LAOState(lao));
MessageGeneral createLaoMessage = getMsg(ORGANIZER_KEY, CREATE_LAO);
messageHandler.handleMessage(laoRepository, messageSender, lao.getChannel(), createLaoMessage);
electMsg = getMsg(NODE_2_KEY, elect);
messageId = electMsg.getMessageId();
}
Aggregations