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);
}
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);
}
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);
}
Aggregations