Search in sources :

Example 6 with MqttPublishMessage

use of io.vertx.mqtt.messages.MqttPublishMessage in project hono by eclipse.

the class VertxBasedMqttProtocolAdapterTest method testOnPublishedMessageUsesDeviceIdentityForTopicWithoutTenant.

/**
 * Verifies that the adapter uses an authenticated device's identity when mapping a topic without tenant ID.
 *
 * @param ctx The helper to use for running tests on vert.x.
 */
@Test
public void testOnPublishedMessageUsesDeviceIdentityForTopicWithoutTenant(final TestContext ctx) {
    givenAnAdapter();
    // WHEN an authenticated device publishes a message to a topic that does not contain a tenant ID
    final MqttPublishMessage message = newMessage(MqttQoS.AT_MOST_ONCE, TelemetryConstants.TELEMETRY_ENDPOINT);
    final MqttContext context = newContext(message, new Device("my-tenant", "4711"));
    final Async addressCheck = ctx.async();
    final Future<ResourceIdentifier> checkedAddress = adapter.mapTopic(message).compose(address -> adapter.checkAddress(context, address)).map(address -> {
        addressCheck.complete();
        return address;
    });
    // THEN the mapped address contains the authenticated device's tenant and device ID
    addressCheck.await();
    final ResourceIdentifier downstreamAddress = checkedAddress.result();
    assertThat(downstreamAddress.getEndpoint(), is(TelemetryConstants.TELEMETRY_ENDPOINT));
    assertThat(downstreamAddress.getTenantId(), is("my-tenant"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) RunWith(org.junit.runner.RunWith) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) EndpointType(org.eclipse.hono.util.EndpointType) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Assert.assertThat(org.junit.Assert.assertThat) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) Timeout(org.junit.rules.Timeout) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Device(org.eclipse.hono.service.auth.device.Device) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) Device(org.eclipse.hono.service.auth.device.Device) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 7 with MqttPublishMessage

use of io.vertx.mqtt.messages.MqttPublishMessage in project hono by eclipse.

the class VertxBasedMqttProtocolAdapterTest method testMapTopicFailsForQoS2EventMessage.

/**
 * Verifies that the adapter rejects QoS 2 messages published to the <em>event</em> endpoint.
 *
 * @param ctx The helper to use for running tests on vert.x.
 */
@Test
public void testMapTopicFailsForQoS2EventMessage(final TestContext ctx) {
    givenAnAdapter();
    // WHEN a device publishes a message with QoS 2 to an "event" topic
    final MqttPublishMessage message = newMessage(MqttQoS.EXACTLY_ONCE, EventConstants.EVENT_ENDPOINT);
    adapter.mapTopic(message).setHandler(ctx.asyncAssertFailure(t -> {
    // THEN no downstream sender can be created for the message
    }));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) RunWith(org.junit.runner.RunWith) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) EndpointType(org.eclipse.hono.util.EndpointType) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Assert.assertThat(org.junit.Assert.assertThat) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) Timeout(org.junit.rules.Timeout) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Device(org.eclipse.hono.service.auth.device.Device) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) Test(org.junit.Test)

Example 8 with MqttPublishMessage

use of io.vertx.mqtt.messages.MqttPublishMessage in project hono by eclipse.

the class VertxBasedMqttProtocolAdapterTest method testMapTopicFailsForQoS2TelemetryMessage.

/**
 * Verifies that the adapter rejects QoS 2 messages published to the <em>telemetry</em> endpoint.
 *
 * @param ctx The helper to use for running tests on vert.x.
 */
@Test
public void testMapTopicFailsForQoS2TelemetryMessage(final TestContext ctx) {
    givenAnAdapter();
    // WHEN a device publishes a message with QoS 2 to a "telemetry" topic
    final MqttPublishMessage message = newMessage(MqttQoS.EXACTLY_ONCE, TelemetryConstants.TELEMETRY_ENDPOINT);
    adapter.mapTopic(message).setHandler(ctx.asyncAssertFailure(t -> {
    // THEN no downstream sender can be created for the message
    }));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) RunWith(org.junit.runner.RunWith) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) EndpointType(org.eclipse.hono.util.EndpointType) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Assert.assertThat(org.junit.Assert.assertThat) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) Timeout(org.junit.rules.Timeout) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Device(org.eclipse.hono.service.auth.device.Device) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) Test(org.junit.Test)

Example 9 with MqttPublishMessage

use of io.vertx.mqtt.messages.MqttPublishMessage in project hono by eclipse.

the class VertxBasedMqttProtocolAdapterTest method testMapTopicFailsForUnknownEndpoint.

/**
 * Verifies that the adapter rejects messages published to topics containing an endpoint
 * other than <em>telemetry</em> or <em>event</em>.
 *
 * @param ctx The helper to use for running tests on vert.x.
 */
@Test
public void testMapTopicFailsForUnknownEndpoint(final TestContext ctx) {
    givenAnAdapter();
    // WHEN a device publishes a message to a topic with an unknown endpoint
    final MqttPublishMessage message = newMessage(MqttQoS.AT_MOST_ONCE, "unknown");
    adapter.mapTopic(message).setHandler(ctx.asyncAssertFailure(t -> {
    // THEN no downstream sender can be created for the message
    }));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) RunWith(org.junit.runner.RunWith) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) EndpointType(org.eclipse.hono.util.EndpointType) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Assert.assertThat(org.junit.Assert.assertThat) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) Timeout(org.junit.rules.Timeout) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Device(org.eclipse.hono.service.auth.device.Device) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) Test(org.junit.Test)

Example 10 with MqttPublishMessage

use of io.vertx.mqtt.messages.MqttPublishMessage in project hono by eclipse.

the class VertxBasedMqttProtocolAdapterTest method testMapTopicFailsForQoS0EventMessage.

/**
 * Verifies that the adapter rejects QoS 0 messages published to the <em>event</em> endpoint.
 *
 * @param ctx The helper to use for running tests on vert.x.
 */
@Test
public void testMapTopicFailsForQoS0EventMessage(final TestContext ctx) {
    givenAnAdapter();
    // WHEN a device publishes a message with QoS 0 to an "event" topic
    final MqttPublishMessage message = newMessage(MqttQoS.AT_MOST_ONCE, EventConstants.EVENT_ENDPOINT);
    adapter.mapTopic(message).setHandler(ctx.asyncAssertFailure(t -> {
    // THEN no downstream sender can be created for the message
    }));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) RunWith(org.junit.runner.RunWith) MqttEndpoint(io.vertx.mqtt.MqttEndpoint) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) EndpointType(org.eclipse.hono.util.EndpointType) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Assert.assertThat(org.junit.Assert.assertThat) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) Timeout(org.junit.rules.Timeout) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Device(org.eclipse.hono.service.auth.device.Device) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MqttPublishMessage(io.vertx.mqtt.messages.MqttPublishMessage) Test(org.junit.Test)

Aggregations

MqttPublishMessage (io.vertx.mqtt.messages.MqttPublishMessage)11 Buffer (io.vertx.core.buffer.Buffer)8 MqttEndpoint (io.vertx.mqtt.MqttEndpoint)8 ProtocolAdapterProperties (org.eclipse.hono.config.ProtocolAdapterProperties)8 Test (org.junit.Test)8 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)6 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)5 Future (io.vertx.core.Future)5 Async (io.vertx.ext.unit.Async)5 TestContext (io.vertx.ext.unit.TestContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 MqttContext (org.eclipse.hono.adapter.mqtt.MqttContext)5 Device (org.eclipse.hono.service.auth.device.Device)5 EndpointType (org.eclipse.hono.util.EndpointType)5 EventConstants (org.eclipse.hono.util.EventConstants)5 TelemetryConstants (org.eclipse.hono.util.TelemetryConstants)5 CoreMatchers.is (org.hamcrest.CoreMatchers.is)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertThat (org.junit.Assert.assertThat)5 Rule (org.junit.Rule)5