Search in sources :

Example 6 with MqttTopicSubscriptionImpl

use of io.vertx.mqtt.impl.MqttTopicSubscriptionImpl in project hono by eclipse.

the class ErrorSubscriptionTest method testGetErrorPublishTopicForMessageWithUnknownEndpoint.

/**
 * Verifies that the topic for an error caused by a message sent to a topic with
 * an unknown/invalid endpoint is "unknown".
 */
@Test
public void testGetErrorPublishTopicForMessageWithUnknownEndpoint() {
    final MqttTopicSubscription mqttTopicSubscription = new MqttTopicSubscriptionImpl("error///#", MqttQoS.AT_MOST_ONCE);
    final ErrorSubscription subscription = ErrorSubscription.fromTopic(mqttTopicSubscription, device);
    assertThat(subscription).isNotNull();
    String errorPublishTopic = subscription.getErrorPublishTopic("something", null, null, 503);
    assertThat(errorPublishTopic.split("/")[3]).isEqualTo(ErrorSubscription.UNKNOWN_ENDPOINT);
    errorPublishTopic = subscription.getErrorPublishTopic("", null, null, 503);
    assertThat(errorPublishTopic.split("/")[3]).isEqualTo(ErrorSubscription.UNKNOWN_ENDPOINT);
    errorPublishTopic = subscription.getErrorPublishTopic(null, null, null, 503);
    assertThat(errorPublishTopic.split("/")[3]).isEqualTo(ErrorSubscription.UNKNOWN_ENDPOINT);
}
Also used : MqttTopicSubscriptionImpl(io.vertx.mqtt.impl.MqttTopicSubscriptionImpl) MqttTopicSubscription(io.vertx.mqtt.MqttTopicSubscription) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with MqttTopicSubscriptionImpl

use of io.vertx.mqtt.impl.MqttTopicSubscriptionImpl in project hono by eclipse.

the class ErrorSubscriptionTest method testGetErrorPublishTopicForCommandResponseMessage.

/**
 * Verifies that the topic for an error caused by a command response message is correct.
 */
@Test
public void testGetErrorPublishTopicForCommandResponseMessage() {
    final MqttTopicSubscription mqttTopicSubscription = new MqttTopicSubscriptionImpl("error///#", MqttQoS.AT_MOST_ONCE);
    final ErrorSubscription subscription = ErrorSubscription.fromTopic(mqttTopicSubscription, device);
    assertThat(subscription).isNotNull();
    String errorPublishTopic = subscription.getErrorPublishTopic(CommandConstants.COMMAND_ENDPOINT, null, null, 503);
    assertThat(errorPublishTopic.split("/")[3]).isEqualTo(ErrorSubscription.COMMAND_RESPONSE_ENDPOINT);
    errorPublishTopic = subscription.getErrorPublishTopic(CommandConstants.COMMAND_ENDPOINT_SHORT, null, null, 503);
    assertThat(errorPublishTopic.split("/")[3]).isEqualTo(ErrorSubscription.COMMAND_RESPONSE_ENDPOINT_SHORT);
}
Also used : MqttTopicSubscriptionImpl(io.vertx.mqtt.impl.MqttTopicSubscriptionImpl) MqttTopicSubscription(io.vertx.mqtt.MqttTopicSubscription) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with MqttTopicSubscriptionImpl

use of io.vertx.mqtt.impl.MqttTopicSubscriptionImpl in project hono by eclipse.

the class ErrorSubscriptionTest method testSubscriptionSucceedsForUnauthenticatedDevice.

/**
 * Verifies that an unauthenticated device can successfully subscribe for errors
 * using the default topic.
 *
 * @param endpointName The endpoint name used in the topic.
 * @param qos The requested QoS.
 */
@ParameterizedTest
@MethodSource("endpointNamesWithQoS")
public void testSubscriptionSucceedsForUnauthenticatedDevice(final String endpointName, final MqttQoS qos) {
    final MqttTopicSubscription mqttTopicSubscription = new MqttTopicSubscriptionImpl(String.format("%s/tenant1/deviceA/#", endpointName), qos);
    final ErrorSubscription subscription = ErrorSubscription.fromTopic(mqttTopicSubscription, null);
    assertThat(subscription).isNotNull();
    assertThat(subscription.getTenant()).isEqualTo("tenant1");
    assertThat(subscription.getDeviceId()).isEqualTo("deviceA");
    assertThat(subscription.getEndpoint()).isEqualTo(endpointName);
    assertThat(subscription.getQos()).isEqualTo(qos);
}
Also used : MqttTopicSubscriptionImpl(io.vertx.mqtt.impl.MqttTopicSubscriptionImpl) MqttTopicSubscription(io.vertx.mqtt.MqttTopicSubscription) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

MqttTopicSubscription (io.vertx.mqtt.MqttTopicSubscription)8 MqttTopicSubscriptionImpl (io.vertx.mqtt.impl.MqttTopicSubscriptionImpl)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 Span (io.opentracing.Span)2 MqttEndpoint (io.vertx.mqtt.MqttEndpoint)2 MqttPublishMessage (io.vertx.mqtt.messages.MqttPublishMessage)2 Command (org.eclipse.hono.client.command.Command)2 Test (org.junit.jupiter.api.Test)2