Search in sources :

Example 11 with ClientConfigProperties

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

the class StandaloneTelemetryApiTest method prepareHonoServer.

/**
 * Sets up the fixture common to all test cases.
 *
 * @param ctx The vert.x test context.
 */
@BeforeClass
public static void prepareHonoServer(final TestContext ctx) {
    vertx = Vertx.vertx();
    downstreamAdapter = new MessageDiscardingDownstreamAdapter(vertx);
    final HonoMessagingConfigProperties configProperties = new HonoMessagingConfigProperties();
    configProperties.setInsecurePort(0);
    final TelemetryEndpoint telemetryEndpoint = new TelemetryEndpoint(vertx);
    telemetryEndpoint.setMetrics(mock(MessagingMetrics.class));
    telemetryEndpoint.setTelemetryAdapter(downstreamAdapter);
    telemetryEndpoint.setRegistrationAssertionValidator(assertionHelper);
    telemetryEndpoint.setConfiguration(configProperties);
    server = new HonoMessaging();
    server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(TestSupport.createAuthenticationService(createUser())));
    server.setConfig(configProperties);
    server.addEndpoint(telemetryEndpoint);
    final Future<String> serverTracker = Future.future();
    vertx.deployVerticle(server, serverTracker.completer());
    serverTracker.compose(s -> {
        final ClientConfigProperties clientProps = new ClientConfigProperties();
        clientProps.setName("test");
        clientProps.setHost(server.getInsecurePortBindAddress());
        clientProps.setPort(server.getInsecurePort());
        clientProps.setUsername(USER);
        clientProps.setPassword(PWD);
        client = new HonoClientImpl(vertx, clientProps);
        return client.connect(new ProtonClientOptions());
    }).setHandler(ctx.asyncAssertSuccess());
}
Also used : HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) TestContext(io.vertx.ext.unit.TestContext) AuthoritiesImpl(org.eclipse.hono.auth.AuthoritiesImpl) HonoUserAdapter(org.eclipse.hono.auth.HonoUserAdapter) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Activity(org.eclipse.hono.auth.Activity) HonoUser(org.eclipse.hono.auth.HonoUser) HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) Future(io.vertx.core.Future) TelemetryEndpoint(org.eclipse.hono.telemetry.impl.TelemetryEndpoint) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) TestSupport(org.eclipse.hono.TestSupport) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) MessageSender(org.eclipse.hono.client.MessageSender) Authorities(org.eclipse.hono.auth.Authorities) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) Mockito.mock(org.mockito.Mockito.mock) HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) TelemetryEndpoint(org.eclipse.hono.telemetry.impl.TelemetryEndpoint) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) BeforeClass(org.junit.BeforeClass)

Example 12 with ClientConfigProperties

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

the class IntegrationTestSupport method init.

/**
 * Connects to the AMQP 1.0 Messaging Network.
 *
 * @param ctx The vert.x test context.
 */
public void init(final TestContext ctx) {
    registry = new DeviceRegistryHttpClient(vertx, IntegrationTestSupport.HONO_DEVICEREGISTRY_HOST, IntegrationTestSupport.HONO_DEVICEREGISTRY_HTTP_PORT);
    final ClientConfigProperties downstreamProps = new ClientConfigProperties();
    downstreamProps.setHost(IntegrationTestSupport.DOWNSTREAM_HOST);
    downstreamProps.setPort(IntegrationTestSupport.DOWNSTREAM_PORT);
    downstreamProps.setUsername(IntegrationTestSupport.DOWNSTREAM_USER);
    downstreamProps.setPassword(IntegrationTestSupport.DOWNSTREAM_PWD);
    downstreamClient = new HonoClientImpl(vertx, downstreamProps);
    downstreamClient.connect().setHandler(ctx.asyncAssertSuccess());
}
Also used : HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties)

Example 13 with ClientConfigProperties

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

the class DeviceRegistryAmqpTestSupport method prepareDeviceRegistryClient.

/**
 * Build a HonoClient to access the device registry service.
 *
 * @param vertx The Vert.x instance to execute the client on, if {@code null} a new Vert.x instance is used.
 * @return The client that is configured for accessing the device registry.
 */
protected static HonoClient prepareDeviceRegistryClient(final Vertx vertx) {
    final ClientConfigProperties clientProps = new ClientConfigProperties();
    clientProps.setName("test");
    clientProps.setHost(IntegrationTestSupport.HONO_DEVICEREGISTRY_HOST);
    clientProps.setPort(IntegrationTestSupport.HONO_DEVICEREGISTRY_AMQP_PORT);
    clientProps.setUsername(IntegrationTestSupport.HONO_USER);
    clientProps.setPassword(IntegrationTestSupport.HONO_PWD);
    return new HonoClientImpl(vertx, clientProps);
}
Also used : HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties)

Example 14 with ClientConfigProperties

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

the class ConnectionFactoryImplTest method testConnectEnablesSslIfTrustStoreIsConfigured.

/**
 * Verifies that the factory uses TLS when connecting to the peer if a trust store
 * is configured but TLS has not been enabled explicitly.
 */
@SuppressWarnings("unchecked")
@Test
public void testConnectEnablesSslIfTrustStoreIsConfigured() {
    // GIVEN a factory configured to use a specific trust store
    final ClientConfigProperties config = new ClientConfigProperties();
    config.setHost("remote.host");
    config.setTrustStorePath("/tmp/trusted-ca.p12");
    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 15 with ClientConfigProperties

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

the class AbstractAdapterConfig method messagingClientConfig.

/**
 * Exposes configuration properties for accessing a Hono Messaging service as a Spring bean.
 * <p>
 * The properties can be customized in subclasses by means of overriding the
 * {@link #customizeMessagingClientConfig(ClientConfigProperties)} method.
 *
 * @return The properties.
 */
@Qualifier(Constants.QUALIFIER_MESSAGING)
@ConfigurationProperties(prefix = "hono.messaging")
@Bean
public ClientConfigProperties messagingClientConfig() {
    final ClientConfigProperties config = new ClientConfigProperties();
    customizeMessagingClientConfig(config);
    return config;
}
Also used : ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) Bean(org.springframework.context.annotation.Bean)

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