use of com.github.dedis.popstellar.model.network.answer.ErrorCode in project popstellar by dedis.
the class LAONetworkManagerTest method errorsAreDispatchedCorrectly.
@Test
public void errorsAreDispatchedCorrectly() {
TestSchedulerProvider schedulerProvider = new TestSchedulerProvider();
TestScheduler testScheduler = schedulerProvider.getTestScheduler();
LAONetworkManager networkManager = new LAONetworkManager(laoRepository, handler, connection, JsonModule.provideGson(DataRegistryModule.provideDataRegistry()), schedulerProvider);
ErrorCode error = new ErrorCode(3, "error");
// Setup mock answer
Answer<?> answer = args -> {
// Retrieve subscribe object
Query query = args.getArgument(0);
// Return a negative result
messages.onNext(new Error(query.getRequestId(), error));
return null;
};
doAnswer(answer).when(connection).sendMessage(any());
Disposable disposable = networkManager.subscribe(CHANNEL).subscribe(() -> {
throw new IllegalAccessException("The subscription should have failed.");
}, err -> assertTrue(err instanceof JsonRPCErrorException));
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
disposable.dispose();
networkManager.dispose();
verify(connection).sendMessage(any(Subscribe.class));
verify(connection, atLeastOnce()).observeMessage();
verify(connection).observeConnectionEvents();
verify(connection).close();
verifyNoMoreInteractions(connection);
}
Aggregations