use of com.github.dedis.popstellar.model.network.answer.Result in project popstellar by dedis.
the class LAONetworkManagerTest method subscribeSendsTheRightMessages.
@Test
public void subscribeSendsTheRightMessages() {
TestSchedulerProvider schedulerProvider = new TestSchedulerProvider();
TestScheduler testScheduler = schedulerProvider.getTestScheduler();
LAONetworkManager networkManager = new LAONetworkManager(laoRepository, handler, connection, JsonModule.provideGson(DataRegistryModule.provideDataRegistry()), schedulerProvider);
Answer<?> answer = args -> {
// Retrieve subscribe object
Subscribe subscribe = args.getArgument(0);
// Make sure the channel is correct
assertEquals(CHANNEL, subscribe.getChannel());
// Return a positive result
messages.onNext(new Result(subscribe.getRequestId()));
return null;
};
doAnswer(answer).when(connection).sendMessage(any(Subscribe.class));
// Actual test
Disposable disposable = networkManager.subscribe(CHANNEL).subscribe(() -> verify(connection, never()).sendMessage(any(Catchup.class)));
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
disposable.dispose();
networkManager.dispose();
verify(connection).sendMessage(any(Subscribe.class));
verify(connection).sendMessage(any(Catchup.class));
verify(connection, atLeastOnce()).observeMessage();
verify(connection).observeConnectionEvents();
verify(connection).close();
verifyNoMoreInteractions(connection);
}
use of com.github.dedis.popstellar.model.network.answer.Result in project popstellar by dedis.
the class JsonResultSerializer method deserialize.
@Override
public Result deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
int id = root.get("id").getAsInt();
JsonElement resultElement = root.get(RESULT);
if (resultElement.isJsonPrimitive()) {
return new Result(id);
} else {
Type listType = new TypeToken<ArrayList<MessageGeneral>>() {
}.getType();
List<MessageGeneral> messages = context.deserialize(resultElement.getAsJsonArray(), listType);
return new ResultMessages(id, messages);
}
}
Aggregations