use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class RollCallHandlerTest method testHandleCreateRollCall.
@Test
public void testHandleCreateRollCall() throws DataHandlingException {
// Create the create Roll Call message
CreateRollCall createRollCall = new CreateRollCall("roll call 2", rollCall.getCreation(), rollCall.getStart(), rollCall.getEnd(), rollCall.getLocation(), rollCall.getDescription(), CREATE_LAO.getId());
MessageGeneral message = new MessageGeneral(SENDER_KEY, createRollCall, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the new Roll Call is present with state CREATED and the correct ID
Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(createRollCall.getId());
assertTrue(rollCallOpt.isPresent());
assertEquals(EventState.CREATED, rollCallOpt.get().getState());
assertEquals(createRollCall.getId(), rollCallOpt.get().getId());
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
// Check the Witness message contains the expected title and description
WitnessMessage expectedMessage = createRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class RollCallHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException, KeyException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
lenient().when(keyManager.getValidPoPToken(any(), any())).thenReturn(POP_TOKEN);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO
Lao lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
lao.setLastModified(lao.getCreation());
// Create one Roll Call and add it to the LAO
rollCall = new RollCall(lao.getId(), Instant.now().getEpochSecond(), "roll call 1");
rollCall.setLocation("EPFL");
lao.setRollCalls(new HashMap<String, RollCall>() {
{
put(rollCall.getId(), rollCall);
}
});
// Add the LAO to the LAORepository
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
// Add the CreateLao message to the LAORepository
MessageGeneral createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.
the class RollCallHandlerTest method testHandleCloseRollCall.
@Test
public void testHandleCloseRollCall() throws DataHandlingException {
// Create the close Roll Call message
CloseRollCall closeRollCall = new CloseRollCall(CREATE_LAO.getId(), rollCall.getId(), rollCall.getEnd(), new ArrayList<>());
MessageGeneral message = new MessageGeneral(SENDER_KEY, closeRollCall, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the Roll Call is present with state CLOSED and the correct ID
Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(closeRollCall.getUpdateId());
assertTrue(rollCallOpt.isPresent());
assertEquals(EventState.CLOSED, rollCallOpt.get().getState());
assertEquals(closeRollCall.getUpdateId(), rollCallOpt.get().getId());
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
// Check the Witness message contains the expected title and description
WitnessMessage expectedMessage = closeRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
Aggregations