use of com.github.dedis.popstellar.model.network.method.Publish in project popstellar by dedis.
the class LAONetworkManagerTest method publishSendsRightMessage.
@Test
public void publishSendsRightMessage() {
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
Publish publish = args.getArgument(0);
// Make sure the channel is correct
assertEquals(CHANNEL, publish.getChannel());
MessageGeneral messageGeneral = publish.getMessage();
assertEquals(DATA, messageGeneral.getData());
// Return a positive result
messages.onNext(new Result(publish.getRequestId()));
return null;
};
doAnswer(answer).when(connection).sendMessage(any(Publish.class));
// Actual test
Disposable disposable = networkManager.publish(KEY_PAIR, CHANNEL, DATA).subscribe();
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
disposable.dispose();
networkManager.dispose();
verify(connection).sendMessage(any(Publish.class));
verify(connection, atLeastOnce()).observeMessage();
verify(connection).observeConnectionEvents();
verify(connection).close();
verifyNoMoreInteractions(connection);
}
use of com.github.dedis.popstellar.model.network.method.Publish in project popstellar by dedis.
the class LAONetworkManager method publish.
@Override
public Completable publish(Channel channel, MessageGeneral msg) {
Log.d(TAG, "sending a publish " + msg.getData().getClass() + " to the channel " + channel);
Publish publish = new Publish(channel, requestCounter.incrementAndGet(), msg);
return request(publish).ignoreElement();
}
Aggregations