use of org.eclipse.hono.client.HonoConnection in project hono by eclipse.
the class ProtonBasedCommandSenderTest method setUp.
/**
* Sets up the fixture.
*/
@BeforeEach
void setUp() {
final var vertx = mock(Vertx.class);
when(vertx.eventBus()).thenReturn(mock(EventBus.class));
final HonoConnection connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx);
final ProtonReceiver receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), anyInt(), anyBoolean(), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
protonDelivery = mock(ProtonDelivery.class);
when(protonDelivery.remotelySettled()).thenReturn(true);
when(protonDelivery.getRemoteState()).thenReturn(new Accepted());
sender = AmqpClientUnitTestHelper.mockProtonSender();
when(sender.send(any(Message.class), VertxMockSupport.anyHandler())).thenReturn(protonDelivery);
when(connection.createSender(anyString(), any(), any())).thenReturn(Future.succeededFuture(sender));
commandSender = new ProtonBasedCommandSender(connection, SendMessageSampler.Factory.noop());
}
use of org.eclipse.hono.client.HonoConnection in project hono by eclipse.
the class ProtonBasedMappingAndDelegatingCommandHandlerTest method setUp.
/**
* Sets up fixture.
*/
@BeforeEach
public void setUp() {
final Vertx vertx = mock(Vertx.class);
final Context context = VertxMockSupport.mockContext(vertx);
when(vertx.getOrCreateContext()).thenReturn(context);
doAnswer(invocation -> {
final Handler<Void> handler = invocation.getArgument(1);
handler.handle(null);
return null;
}).when(vertx).setTimer(anyLong(), VertxMockSupport.anyHandler());
final EventBus eventBus = mock(EventBus.class);
when(vertx.eventBus()).thenReturn(eventBus);
final ClientConfigProperties props = new ClientConfigProperties();
props.setSendMessageTimeout(0);
final HonoConnection connection = mockHonoConnection(vertx, props);
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
sender = mockProtonSender();
when(connection.createSender(anyString(), any(), any())).thenReturn(Future.succeededFuture(sender));
tenantId = UUID.randomUUID().toString();
tenantClient = mock(TenantClient.class);
when(tenantClient.get(eq(tenantId), any())).thenReturn(Future.succeededFuture(TenantObject.from(tenantId)));
commandTargetMapper = mock(CommandTargetMapper.class);
final CommandRouterMetrics metrics = mock(CommandRouterMetrics.class);
when(metrics.startTimer()).thenReturn(Timer.start());
mappingAndDelegatingCommandHandler = new ProtonBasedMappingAndDelegatingCommandHandler(tenantClient, connection, commandTargetMapper, metrics);
}
use of org.eclipse.hono.client.HonoConnection in project hono by eclipse.
the class ProtonBasedMappingAndDelegatingCommandHandlerTest method mockHonoConnection.
private static <T> HonoConnection mockHonoConnection(final Vertx vertx, final ClientConfigProperties props) {
final Tracer tracer = NoopTracerFactory.create();
final HonoConnection connection = mock(HonoConnection.class);
when(connection.getVertx()).thenReturn(vertx);
when(connection.getConfig()).thenReturn(props);
when(connection.getTracer()).thenReturn(tracer);
when(connection.executeOnContext(VertxMockSupport.anyHandler())).then(invocation -> {
final Promise<T> result = Promise.promise();
final Handler<Future<T>> handler = invocation.getArgument(0);
handler.handle(result.future());
return result.future();
});
return connection;
}
use of org.eclipse.hono.client.HonoConnection in project hono by eclipse.
the class AmqpAdapterClientFactoryTest method setUp.
/**
* Sets up the fixture.
*/
@BeforeAll
public static void setUp() {
final HonoConnection connection = AmqpClientUnitTestHelper.mockHonoConnection(mock(Vertx.class));
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
final ProtonSender protonSender = AmqpClientUnitTestHelper.mockProtonSender();
when(connection.createSender(any(), any(), any())).thenReturn(Future.succeededFuture(protonSender));
final ProtonReceiver receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
when(connection.createReceiver(anyString(), any(), any(), any())).thenReturn(Future.succeededFuture(receiver));
factory = AmqpAdapterClientFactory.create(connection, "my-tenant");
}
use of org.eclipse.hono.client.HonoConnection in project hono by eclipse.
the class ProtonBasedInternalCommandConsumerTest method setUp.
/**
* Sets up fixture.
*/
@BeforeEach
public void setUp() {
final HonoConnection honoConnection = AmqpClientUnitTestHelper.mockHonoConnection(mock(Vertx.class));
final String adapterInstanceId = "adapterInstanceId";
commandHandlers = new CommandHandlers();
internalCommandConsumer = new ProtonBasedInternalCommandConsumer(honoConnection, adapterInstanceId, commandHandlers);
context = VertxMockSupport.mockContext(mock(Vertx.class));
}
Aggregations