Search in sources :

Example 6 with ClientConfigProperties

use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.

the class HonoClientImplTest method setUp.

/**
 * Sets up fixture.
 */
@Before
public void setUp() {
    con = mock(ProtonConnection.class);
    when(con.getRemoteContainer()).thenReturn("server");
    connectionFactory = new DisconnectHandlerProvidingConnectionFactory(con);
    props = new ClientConfigProperties();
    client = new HonoClientImpl(vertx, connectionFactory, props);
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) Before(org.junit.Before)

Example 7 with ClientConfigProperties

use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.

the class TelemetrySenderImplTest method setUp.

/**
 * Sets up the fixture.
 */
@Before
public void setUp() {
    vertx = mock(Vertx.class);
    context = HonoClientUnitTestHelper.mockContext(vertx);
    sender = HonoClientUnitTestHelper.mockProtonSender();
    config = new ClientConfigProperties();
}
Also used : ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) Vertx(io.vertx.core.Vertx) Before(org.junit.Before)

Example 8 with ClientConfigProperties

use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.

the class ConnectionFactoryImplTest method testConnectEnablesSslIfExplicitlyConfigured.

/**
 * Verifies that the factory uses TLS when connecting to the peer if no trust store
 * is configured but TLS has been enabled explicitly.
 */
@SuppressWarnings("unchecked")
@Test
public void testConnectEnablesSslIfExplicitlyConfigured() {
    // GIVEN a factory configured to connect to a server using TLS
    final ClientConfigProperties config = new ClientConfigProperties();
    config.setHost("remote.host");
    config.setTlsEnabled(true);
    final ProtonClient client = mock(ProtonClient.class);
    final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, config);
    factory.setProtonClient(client);
    // WHEN connecting to the server
    factory.connect(null, null, null, c -> {
    });
    // THEN the factory uses TLS when establishing the connection
    final ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
    verify(client).connect(optionsCaptor.capture(), eq("remote.host"), anyInt(), any(), any(), any(Handler.class));
    assertTrue(optionsCaptor.getValue().isSsl());
}
Also used : Handler(io.vertx.core.Handler) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) ProtonClient(io.vertx.proton.ProtonClient) Test(org.junit.Test)

Example 9 with ClientConfigProperties

use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.

the class ConnectionFactoryImplTest method setup.

/**
 * Sets up fixture.
 */
@Before
public void setup() {
    props = new ClientConfigProperties();
    props.setHost("127.0.0.1");
    // no server running on port
    props.setPort(25673);
    props.setAmqpHostname("hono");
    props.setName("client");
}
Also used : ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) Before(org.junit.Before)

Example 10 with ClientConfigProperties

use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.

the class EventConsumerImplTest method testHandlerCallsCloseHook.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void testHandlerCallsCloseHook(final TestContext ctx, final BiConsumer<ProtonReceiver, ArgumentCaptor<Handler>> handlerCaptor) {
    // GIVEN an open event consumer
    final Async consumerCreation = ctx.async();
    final BiConsumer<ProtonDelivery, Message> eventConsumer = mock(BiConsumer.class);
    final RecordImpl attachments = new RecordImpl();
    final Source source = mock(Source.class);
    when(source.getAddress()).thenReturn("source/address");
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.isOpen()).thenReturn(Boolean.TRUE);
    when(receiver.getSource()).thenReturn(source);
    when(receiver.attachments()).thenReturn(attachments);
    when(receiver.open()).then(answer -> {
        attachments.set(EventConsumerImpl.KEY_LINK_ESTABLISHED, Boolean.class, Boolean.TRUE);
        consumerCreation.complete();
        return receiver;
    });
    final ProtonConnection con = mock(ProtonConnection.class);
    when(con.createReceiver(anyString())).thenReturn(receiver);
    final Handler<String> closeHook = mock(Handler.class);
    final ArgumentCaptor<Handler> captor = ArgumentCaptor.forClass(Handler.class);
    EventConsumerImpl.create(vertx.getOrCreateContext(), new ClientConfigProperties(), con, "source/address", eventConsumer, ok -> {
    }, closeHook);
    consumerCreation.await();
    handlerCaptor.accept(receiver, captor);
    // WHEN the receiver link is closed
    captor.getValue().handle(Future.succeededFuture(receiver));
    // THEN the close hook is called
    verify(closeHook).handle(any());
    // and the receiver link is closed
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonDelivery(io.vertx.proton.ProtonDelivery) Message(org.apache.qpid.proton.message.Message) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Handler(io.vertx.core.Handler) RecordImpl(org.apache.qpid.proton.engine.impl.RecordImpl) Source(org.apache.qpid.proton.amqp.transport.Source) ProtonConnection(io.vertx.proton.ProtonConnection) Async(io.vertx.ext.unit.Async) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties)

Aggregations

ClientConfigProperties (org.eclipse.hono.config.ClientConfigProperties)15 Before (org.junit.Before)7 Vertx (io.vertx.core.Vertx)6 Handler (io.vertx.core.Handler)5 TestContext (io.vertx.ext.unit.TestContext)5 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)5 HonoClientImpl (org.eclipse.hono.client.impl.HonoClientImpl)5 Test (org.junit.Test)5 Future (io.vertx.core.Future)4 Message (org.apache.qpid.proton.message.Message)4 Async (io.vertx.ext.unit.Async)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 ProtonConnection (io.vertx.proton.ProtonConnection)3 MessageSender (org.eclipse.hono.client.MessageSender)3 RunWith (org.junit.runner.RunWith)3 ProtonClient (io.vertx.proton.ProtonClient)2 ProtonDelivery (io.vertx.proton.ProtonDelivery)2 ProtonHelper (io.vertx.proton.ProtonHelper)2 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)2 ProtonReceiver (io.vertx.proton.ProtonReceiver)2