use of com.github.dedis.popstellar.model.objects.WitnessMessage in project popstellar by dedis.
the class LaoHandlerTest method testHandleUpdateLao.
@Test
public void testHandleUpdateLao() throws DataHandlingException {
// Create the update LAO message
UpdateLao updateLao = new UpdateLao(SENDER, CREATE_LAO.getCreation(), "new name", Instant.now().getEpochSecond(), new HashSet<>());
MessageGeneral message = new MessageGeneral(SENDER_KEY, updateLao, GSON);
// Create the expected WitnessMessage
WitnessMessage expectedMessage = updateLaoNameWitnessMessage(message.getMessageId(), updateLao, lao);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
use of com.github.dedis.popstellar.model.objects.WitnessMessage 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.objects.WitnessMessage 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