Search in sources :

Example 16 with Device

use of org.eclipse.hono.service.auth.device.Device 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)

Example 17 with Device

use of org.eclipse.hono.service.auth.device.Device in project hono by eclipse.

the class VertxBasedMqttProtocolAdapterTest method testOnPublishedAuthenticatedMessageFailsForMissingDeviceId.

/**
 * Verifies that the adapter fails to map a topic without a device ID received from an authenticated device.
 *
 * @param ctx The helper to use for running tests on vert.x.
 */
@Test
public void testOnPublishedAuthenticatedMessageFailsForMissingDeviceId(final TestContext ctx) {
    givenAnAdapter();
    // WHEN an authenticated device publishes a message to a topic that does not contain a device ID
    final MqttContext context = newContext(MqttQoS.AT_MOST_ONCE, TelemetryConstants.TELEMETRY_ENDPOINT + "/my-tenant", new Device("my-tenant", "device"));
    adapter.onPublishedMessage(context).setHandler(ctx.asyncAssertFailure(t -> {
    // THEN the message cannot be mapped to an address
    }));
}
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) MqttContext(org.eclipse.hono.adapter.mqtt.MqttContext) Device(org.eclipse.hono.service.auth.device.Device) Test(org.junit.Test)

Aggregations

Device (org.eclipse.hono.service.auth.device.Device)17 ProtocolAdapterProperties (org.eclipse.hono.config.ProtocolAdapterProperties)14 Future (io.vertx.core.Future)13 MqttEndpoint (io.vertx.mqtt.MqttEndpoint)13 Test (org.junit.Test)13 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)12 Buffer (io.vertx.core.buffer.Buffer)12 EventConstants (org.eclipse.hono.util.EventConstants)12 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)12 TelemetryConstants (org.eclipse.hono.util.TelemetryConstants)12 Async (io.vertx.ext.unit.Async)11 TestContext (io.vertx.ext.unit.TestContext)11 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)11 CoreMatchers.is (org.hamcrest.CoreMatchers.is)11 Assert.assertThat (org.junit.Assert.assertThat)11 Rule (org.junit.Rule)11 Timeout (org.junit.rules.Timeout)11 RunWith (org.junit.runner.RunWith)11 MqttPublishMessage (io.vertx.mqtt.messages.MqttPublishMessage)10 EndpointType (org.eclipse.hono.util.EndpointType)10