use of org.eclipse.hono.notification.AbstractNotification in project hono by eclipse.
the class CredentialsChangeNotificationTest method testDeserialization.
/**
* Verifies that a serialized notification is deserialized correctly.
*/
@Test
public void testDeserialization() {
final AbstractNotification abstractNotification = Json.decodeValue(JsonObject.mapFrom(notification).toBuffer(), AbstractNotification.class);
assertThat(abstractNotification).isNotNull();
assertThat(abstractNotification).isInstanceOf(CredentialsChangeNotification.class);
final CredentialsChangeNotification newNotification = (CredentialsChangeNotification) abstractNotification;
assertThat(newNotification.getSource()).isEqualTo(NotificationConstants.SOURCE_DEVICE_REGISTRY);
assertThat(newNotification.getCreationTime()).isEqualTo(Instant.parse(CREATION_TIME));
assertThat(newNotification.getTenantId()).isEqualTo(TENANT_ID);
assertThat(newNotification.getDeviceId()).isEqualTo(DEVICE_ID);
}
use of org.eclipse.hono.notification.AbstractNotification in project hono by eclipse.
the class TenantChangeNotificationTest method testDeserialization.
/**
* Verifies that a serialized notification is deserialized correctly.
*/
@Test
public void testDeserialization() {
final AbstractNotification abstractNotification = Json.decodeValue(JsonObject.mapFrom(notification).toBuffer(), AbstractNotification.class);
assertThat(abstractNotification).isNotNull();
assertThat(abstractNotification).isInstanceOf(TenantChangeNotification.class);
final TenantChangeNotification newNotification = (TenantChangeNotification) abstractNotification;
assertThat(newNotification.getSource()).isEqualTo(NotificationConstants.SOURCE_DEVICE_REGISTRY);
assertThat(newNotification.getCreationTime()).isEqualTo(Instant.parse(CREATION_TIME));
assertThat(newNotification.getChange()).isEqualTo(CHANGE);
assertThat(newNotification.getTenantId()).isEqualTo(TENANT_ID);
assertThat(newNotification.isEnabled()).isEqualTo(ENABLED);
}
use of org.eclipse.hono.notification.AbstractNotification in project hono by eclipse.
the class ProtonBasedNotificationSenderTest method testPublishNotificationSucceeds.
/**
* Verifies that the sender sends a notification message with the expected format.
*
* @param ctx The vert.x test context.
*/
@Test
public void testPublishNotificationSucceeds(final VertxTestContext ctx) {
final String tenantId = "my-tenant";
final Instant creationTime = Instant.parse("2007-12-03T10:15:30Z");
final TenantChangeNotification notification = new TenantChangeNotification(LifecycleChange.CREATE, tenantId, creationTime, false);
final ArgumentCaptor<Handler<ProtonDelivery>> dispositionHandlerCaptor = VertxMockSupport.argumentCaptorHandler();
final ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
// WHEN publishing a notification
final Future<Void> publishNotificationFuture = notificationSender.publish(notification).onComplete(ctx.succeedingThenComplete());
// VERIFY that the message is being sent
verify(sender).send(messageCaptor.capture(), dispositionHandlerCaptor.capture());
// VERIFY that the future waits for the disposition to be updated by the peer
assertThat(publishNotificationFuture.isComplete()).isFalse();
// THEN the disposition is updated and the peer accepts the message
dispositionHandlerCaptor.getValue().handle(protonDelivery);
// VERIFY that the message is as expected
final Message message = messageCaptor.getValue();
assertThat(message.getAddress()).isEqualTo(NotificationAddressHelper.getAddress(notification.getType()));
assertThat(message.getContentType()).isEqualTo(NotificationConstants.CONTENT_TYPE);
final AbstractNotification decodedNotification = Json.decodeValue(MessageHelper.getPayload(message), AbstractNotification.class);
assertThat(decodedNotification.getClass()).isEqualTo(notification.getClass());
assertThat(publishNotificationFuture.isComplete()).isTrue();
}
use of org.eclipse.hono.notification.AbstractNotification in project hono by eclipse.
the class DeviceChangeNotificationTest method testDeserialization.
/**
* Verifies that a serialized notification is deserialized correctly.
*/
@Test
public void testDeserialization() {
final JsonObject json = new JsonObject().put(NotificationConstants.JSON_FIELD_TYPE, "device-change-v1").put(NotificationConstants.JSON_FIELD_SOURCE, NotificationConstants.SOURCE_DEVICE_REGISTRY).put(NotificationConstants.JSON_FIELD_CREATION_TIME, CREATION_TIME).put(NotificationConstants.JSON_FIELD_DATA_CHANGE, LifecycleChange.DELETE).put(NotificationConstants.JSON_FIELD_TENANT_ID, TENANT_ID).put(NotificationConstants.JSON_FIELD_DEVICE_ID, DEVICE_ID).put(NotificationConstants.JSON_FIELD_DATA_ENABLED, true);
final AbstractNotification abstractNotification = Json.decodeValue(json.toBuffer(), AbstractNotification.class);
assertThat(abstractNotification).isNotNull();
assertThat(abstractNotification).isInstanceOf(DeviceChangeNotification.class);
final DeviceChangeNotification newNotification = (DeviceChangeNotification) abstractNotification;
assertThat(newNotification.getSource()).isEqualTo(NotificationConstants.SOURCE_DEVICE_REGISTRY);
assertThat(newNotification.getCreationTime()).isEqualTo(Instant.parse(CREATION_TIME));
assertThat(newNotification.getChange()).isEqualTo(LifecycleChange.DELETE);
assertThat(newNotification.getTenantId()).isEqualTo(TENANT_ID);
assertThat(newNotification.getDeviceId()).isEqualTo(DEVICE_ID);
assertThat(newNotification.isEnabled()).isTrue();
}
use of org.eclipse.hono.notification.AbstractNotification in project hono by eclipse.
the class AllDevicesOfTenantDeletedNotificationTest method testDeserialization.
/**
* Verifies that a serialized notification is deserialized correctly.
*/
@Test
public void testDeserialization() {
final AbstractNotification abstractNotification = Json.decodeValue(JsonObject.mapFrom(notification).toBuffer(), AbstractNotification.class);
assertThat(abstractNotification).isNotNull();
assertThat(abstractNotification).isInstanceOf(AllDevicesOfTenantDeletedNotification.class);
final AllDevicesOfTenantDeletedNotification newNotification = (AllDevicesOfTenantDeletedNotification) abstractNotification;
assertThat(newNotification.getSource()).isEqualTo(NotificationConstants.SOURCE_DEVICE_REGISTRY);
assertThat(newNotification.getCreationTime()).isEqualTo(Instant.parse(CREATION_TIME));
assertThat(newNotification.getTenantId()).isEqualTo(TENANT_ID);
}
Aggregations