use of org.eclipse.hono.service.management.Result in project hono by eclipse.
the class AbstractDeviceManagementServiceTest method testNotificationOnCreateDevice.
/**
* Verifies that {@link AbstractDeviceManagementService#createDevice(String, Optional, Device, Span)} publishes the
* expected notification.
*
* @param context The vert.x test context.
*/
@Test
public void testNotificationOnCreateDevice(final VertxTestContext context) {
final var notificationArgumentCaptor = ArgumentCaptor.forClass(DeviceChangeNotification.class);
deviceManagementService.createDevice(DEFAULT_TENANT_ID, Optional.of(DEFAULT_DEVICE_ID), new Device().setEnabled(false), SPAN).onComplete(context.succeeding(result -> {
context.verify(() -> {
verify(eventBus).publish(eq(NotificationEventBusSupport.getEventBusAddress(DeviceChangeNotification.TYPE)), notificationArgumentCaptor.capture(), any());
assertThat(notificationArgumentCaptor.getAllValues().size()).isEqualTo(1);
final var notification = notificationArgumentCaptor.getValue();
assertThat(notification).isNotNull();
assertThat(notification.getChange()).isEqualTo(LifecycleChange.CREATE);
assertThat(notification.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
assertThat(notification.getDeviceId()).isEqualTo(DEFAULT_DEVICE_ID);
assertThat(notification.getCreationTime()).isNotNull();
assertThat(notification.isEnabled()).isFalse();
});
context.completeNow();
}));
}
use of org.eclipse.hono.service.management.Result in project hono by eclipse.
the class AbstractDeviceManagementServiceTest method testNotificationOnDeleteDevicesOfTenant.
/**
* Verifies that {@link AbstractDeviceManagementService#deleteDevicesOfTenant(String, Span)} publishes the expected
* notification.
*
* @param context The vert.x test context.
*/
@Test
public void testNotificationOnDeleteDevicesOfTenant(final VertxTestContext context) {
final var notificationArgumentCaptor = ArgumentCaptor.forClass(AllDevicesOfTenantDeletedNotification.class);
deviceManagementService.createDevice(DEFAULT_TENANT_ID, Optional.of(DEFAULT_DEVICE_ID), new Device(), SPAN).compose(result -> deviceManagementService.deleteDevicesOfTenant(DEFAULT_TENANT_ID, SPAN)).onComplete(context.succeeding(result -> {
context.verify(() -> {
verify(eventBus).publish(eq(NotificationEventBusSupport.getEventBusAddress(AllDevicesOfTenantDeletedNotification.TYPE)), notificationArgumentCaptor.capture(), any());
assertThat(notificationArgumentCaptor.getAllValues().size()).isEqualTo(1);
final var notification = notificationArgumentCaptor.getValue();
assertThat(notification).isNotNull();
assertThat(notification.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
assertThat(notification.getCreationTime()).isNotNull();
});
context.completeNow();
}));
}
use of org.eclipse.hono.service.management.Result in project hono by eclipse.
the class AbstractDeviceManagementServiceTest method testNotificationOnUpdateDevice.
/**
* Verifies that {@link AbstractDeviceManagementService#updateDevice(String, String, Device, Optional, Span)}
* publishes the expected notification.
*
* @param context The vert.x test context.
*/
@Test
public void testNotificationOnUpdateDevice(final VertxTestContext context) {
final var notificationArgumentCaptor = ArgumentCaptor.forClass(DeviceChangeNotification.class);
deviceManagementService.createDevice(DEFAULT_TENANT_ID, Optional.of(DEFAULT_DEVICE_ID), new Device(), SPAN).compose(result -> deviceManagementService.updateDevice(DEFAULT_TENANT_ID, DEFAULT_DEVICE_ID, new Device().setEnabled(false), Optional.empty(), SPAN)).onComplete(context.succeeding(result -> {
context.verify(() -> {
verify(eventBus, times(2)).publish(eq(NotificationEventBusSupport.getEventBusAddress(DeviceChangeNotification.TYPE)), notificationArgumentCaptor.capture(), any());
assertThat(notificationArgumentCaptor.getAllValues().size()).isEqualTo(2);
final var notification = notificationArgumentCaptor.getValue();
assertThat(notification).isNotNull();
assertThat(notification.getChange()).isEqualTo(LifecycleChange.UPDATE);
assertThat(notification.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
assertThat(notification.getDeviceId()).isEqualTo(DEFAULT_DEVICE_ID);
assertThat(notification.getCreationTime()).isNotNull();
assertThat(notification.isEnabled()).isFalse();
});
context.completeNow();
}));
}
use of org.eclipse.hono.service.management.Result in project hono by eclipse.
the class AbstractTenantManagementServiceTest method testNotificationOnUpdateTenant.
/**
* Verifies that {@link AbstractTenantManagementService#updateTenant(String, Tenant, Optional, Span)} publishes the
* expected notification.
*
* @param context The vert.x test context.
*/
@Test
public void testNotificationOnUpdateTenant(final VertxTestContext context) {
final var notificationArgumentCaptor = ArgumentCaptor.forClass(TenantChangeNotification.class);
tenantManagementService.createTenant(Optional.of(DEFAULT_TENANT_ID), new Tenant(), SPAN).compose(result -> tenantManagementService.updateTenant(DEFAULT_TENANT_ID, new Tenant().setEnabled(false), Optional.empty(), SPAN)).onComplete(context.succeeding(result -> {
context.verify(() -> {
verify(eventBus, times(2)).publish(eq(NotificationEventBusSupport.getEventBusAddress(TenantChangeNotification.TYPE)), notificationArgumentCaptor.capture(), any());
assertThat(notificationArgumentCaptor.getAllValues().size()).isEqualTo(2);
final var notification = notificationArgumentCaptor.getValue();
assertThat(notification).isNotNull();
assertThat(notification.getChange()).isEqualTo(LifecycleChange.UPDATE);
assertThat(notification.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
assertThat(notification.getCreationTime()).isNotNull();
assertThat(notification.isEnabled()).isFalse();
});
context.completeNow();
}));
}
use of org.eclipse.hono.service.management.Result in project hono by eclipse.
the class AbstractTenantManagementServiceTest method testNotificationOnDeleteTenant.
/**
* Verifies that {@link AbstractTenantManagementService#deleteTenant(String, Optional, Span)} publishes the expected
* notification.
*
* @param context The vert.x test context.
*/
@Test
public void testNotificationOnDeleteTenant(final VertxTestContext context) {
final var notificationArgumentCaptor = ArgumentCaptor.forClass(TenantChangeNotification.class);
tenantManagementService.createTenant(Optional.of(DEFAULT_TENANT_ID), new Tenant(), SPAN).compose(result -> tenantManagementService.deleteTenant(DEFAULT_TENANT_ID, Optional.empty(), SPAN)).onComplete(context.succeeding(result -> {
context.verify(() -> {
verify(eventBus, times(2)).publish(eq(NotificationEventBusSupport.getEventBusAddress(TenantChangeNotification.TYPE)), notificationArgumentCaptor.capture(), any());
assertThat(notificationArgumentCaptor.getAllValues().size()).isEqualTo(2);
final var notification = notificationArgumentCaptor.getValue();
assertThat(notification).isNotNull();
assertThat(notification.getChange()).isEqualTo(LifecycleChange.DELETE);
assertThat(notification.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
assertThat(notification.getCreationTime()).isNotNull();
assertThat(notification.isEnabled()).isFalse();
});
context.completeNow();
}));
}
Aggregations