Search in sources :

Example 6 with HonoConnection

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());
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonQoS(io.vertx.proton.ProtonQoS) HonoConnection(org.eclipse.hono.client.HonoConnection) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) ProtonDelivery(io.vertx.proton.ProtonDelivery) Message(org.apache.qpid.proton.message.Message) EventBus(io.vertx.core.eventbus.EventBus) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with HonoConnection

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);
}
Also used : Context(io.vertx.core.Context) CommandRouterMetrics(org.eclipse.hono.commandrouter.CommandRouterMetrics) CommandTargetMapper(org.eclipse.hono.commandrouter.CommandTargetMapper) HonoConnection(org.eclipse.hono.client.HonoConnection) TenantClient(org.eclipse.hono.client.registry.TenantClient) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with HonoConnection

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;
}
Also used : HonoConnection(org.eclipse.hono.client.HonoConnection) Tracer(io.opentracing.Tracer) Future(io.vertx.core.Future)

Example 9 with HonoConnection

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");
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonSender(io.vertx.proton.ProtonSender) HonoConnection(org.eclipse.hono.client.HonoConnection) Vertx(io.vertx.core.Vertx) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with HonoConnection

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));
}
Also used : HonoConnection(org.eclipse.hono.client.HonoConnection) CommandHandlers(org.eclipse.hono.client.command.CommandHandlers) Vertx(io.vertx.core.Vertx) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HonoConnection (org.eclipse.hono.client.HonoConnection)19 Vertx (io.vertx.core.Vertx)14 ProtonReceiver (io.vertx.proton.ProtonReceiver)13 Context (io.vertx.core.Context)12 Future (io.vertx.core.Future)12 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)12 ProtonQoS (io.vertx.proton.ProtonQoS)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 AsyncResult (io.vertx.core.AsyncResult)11 Handler (io.vertx.core.Handler)11 Promise (io.vertx.core.Promise)11 ProtonSender (io.vertx.proton.ProtonSender)11 HttpURLConnection (java.net.HttpURLConnection)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 ServerErrorException (org.eclipse.hono.client.ServerErrorException)11 ClientConfigProperties (org.eclipse.hono.config.ClientConfigProperties)11 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)10 ProtonConnection (io.vertx.proton.ProtonConnection)10 ProtonSession (io.vertx.proton.ProtonSession)10 SaslSystemException (io.vertx.proton.sasl.SaslSystemException)10