Search in sources :

Example 11 with MqttEndpoint

use of io.vertx.mqtt.MqttEndpoint in project hono by eclipse.

the class AbstractVertxBasedMqttProtocolAdapterTest method testUploadMessageSupportsShortAndLongEndpointNames.

/**
 * Verifies that the adapter will accept uploading messages to valid endpoint names.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testUploadMessageSupportsShortAndLongEndpointNames(final TestContext ctx) {
    // GIVEN an adapter with a downstream event consumer
    final MqttServer server = getMqttServer(false);
    final AbstractVertxBasedMqttProtocolAdapter<ProtocolAdapterProperties> adapter = getAdapter(server);
    givenATelemetrySenderForOutcome(Future.succeededFuture(mock(ProtonDelivery.class)));
    givenAnEventSenderForOutcome(Future.succeededFuture(mock(ProtonDelivery.class)));
    // WHEN a device publishes an event
    final MqttEndpoint endpoint = mock(MqttEndpoint.class);
    when(endpoint.isConnected()).thenReturn(Boolean.TRUE);
    final Buffer payload = Buffer.buffer("some payload");
    final MqttPublishMessage messageFromDevice = mock(MqttPublishMessage.class);
    when(messageFromDevice.qosLevel()).thenReturn(MqttQoS.AT_LEAST_ONCE);
    when(messageFromDevice.messageId()).thenReturn(5555555);
    when(messageFromDevice.payload()).thenReturn(payload);
    final MqttContext context = new MqttContext(messageFromDevice, endpoint);
    ResourceIdentifier resourceId = ResourceIdentifier.from("telemetry", "my-tenant", "4712");
    adapter.uploadMessage(context, resourceId, payload).setHandler(ctx.asyncAssertSuccess());
    resourceId = ResourceIdentifier.from("event", "my-tenant", "4712");
    adapter.uploadMessage(context, resourceId, payload).setHandler(ctx.asyncAssertSuccess());
    resourceId = ResourceIdentifier.from("t", "my-tenant", "4712");
    adapter.uploadMessage(context, resourceId, payload).setHandler(ctx.asyncAssertSuccess());
    resourceId = ResourceIdentifier.from("e", "my-tenant", "4712");
    adapter.uploadMessage(context, resourceId, payload).setHandler(ctx.asyncAssertSuccess());
    resourceId = ResourceIdentifier.from("unknown", "my-tenant", "4712");
    adapter.uploadMessage(context, resourceId, payload).setHandler(ctx.asyncAssertFailure());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) MqttServer(io.vertx.mqtt.MqttServer) Test(org.junit.Test)

Example 12 with MqttEndpoint

use of io.vertx.mqtt.MqttEndpoint in project hono by eclipse.

the class AbstractVertxBasedMqttProtocolAdapterTest method testUnauthenticatedMqttAdapterCreatesMessageHandlersForAllDevices.

/**
 * Verifies that the adapter registers message handlers on client connections
 * when device authentication is disabled.
 */
@SuppressWarnings("unchecked")
@Test
public void testUnauthenticatedMqttAdapterCreatesMessageHandlersForAllDevices() {
    // GIVEN an adapter that does not require devices to authenticate
    config.setAuthenticationRequired(false);
    final MqttServer server = getMqttServer(false);
    final AbstractVertxBasedMqttProtocolAdapter<ProtocolAdapterProperties> adapter = getAdapter(server);
    forceClientMocksToConnected();
    // WHEN a device connects that does not provide any credentials
    final MqttEndpoint endpoint = mock(MqttEndpoint.class);
    adapter.handleEndpointConnection(endpoint);
    // THEN the connection is established and handlers are registered
    verify(credentialsAuthProvider, never()).authenticate(any(DeviceCredentials.class), any(Handler.class));
    verify(endpoint).publishHandler(any(Handler.class));
    verify(endpoint).closeHandler(any(Handler.class));
    verify(endpoint).accept(false);
}
Also used : ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttServer(io.vertx.mqtt.MqttServer) Handler(io.vertx.core.Handler) DeviceCredentials(org.eclipse.hono.service.auth.device.DeviceCredentials) Test(org.junit.Test)

Aggregations

MqttEndpoint (io.vertx.mqtt.MqttEndpoint)12 MqttServer (io.vertx.mqtt.MqttServer)11 ProtocolAdapterProperties (org.eclipse.hono.config.ProtocolAdapterProperties)11 Test (org.junit.Test)9 Buffer (io.vertx.core.buffer.Buffer)4 Handler (io.vertx.core.Handler)3 MqttAuth (io.vertx.mqtt.MqttAuth)3 MqttPublishMessage (io.vertx.mqtt.messages.MqttPublishMessage)3 DeviceCredentials (org.eclipse.hono.service.auth.device.DeviceCredentials)3 JsonObject (io.vertx.core.json.JsonObject)2 ProtonDelivery (io.vertx.proton.ProtonDelivery)2 ClientErrorException (org.eclipse.hono.client.ClientErrorException)2 Device (org.eclipse.hono.service.auth.device.Device)2 UsernamePasswordCredentials (org.eclipse.hono.service.auth.device.UsernamePasswordCredentials)2 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)2 TenantObject (org.eclipse.hono.util.TenantObject)2 MqttConnectReturnCode (io.netty.handler.codec.mqtt.MqttConnectReturnCode)1 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)1 AsyncResult (io.vertx.core.AsyncResult)1 CompositeFuture (io.vertx.core.CompositeFuture)1