Search in sources :

Example 1 with Result

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();
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) DeviceChangeNotification(org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification) ArgumentCaptor(org.mockito.ArgumentCaptor) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AllDevicesOfTenantDeletedNotification(org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification) Device(org.eclipse.hono.service.management.device.Device) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Result(org.eclipse.hono.service.management.Result) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) NoopSpan(io.opentracing.noop.NoopSpan) Id(org.eclipse.hono.service.management.Id) Mockito.mock(org.mockito.Mockito.mock) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test)

Example 2 with Result

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();
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) DeviceChangeNotification(org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification) ArgumentCaptor(org.mockito.ArgumentCaptor) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AllDevicesOfTenantDeletedNotification(org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification) Device(org.eclipse.hono.service.management.device.Device) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Result(org.eclipse.hono.service.management.Result) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) NoopSpan(io.opentracing.noop.NoopSpan) Id(org.eclipse.hono.service.management.Id) Mockito.mock(org.mockito.Mockito.mock) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test)

Example 3 with Result

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();
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) DeviceChangeNotification(org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification) ArgumentCaptor(org.mockito.ArgumentCaptor) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AllDevicesOfTenantDeletedNotification(org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification) Device(org.eclipse.hono.service.management.device.Device) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Result(org.eclipse.hono.service.management.Result) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) NoopSpan(io.opentracing.noop.NoopSpan) Id(org.eclipse.hono.service.management.Id) Mockito.mock(org.mockito.Mockito.mock) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test)

Example 4 with Result

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();
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Tenant(org.eclipse.hono.service.management.tenant.Tenant) ArgumentCaptor(org.mockito.ArgumentCaptor) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TenantChangeNotification(org.eclipse.hono.notification.deviceregistry.TenantChangeNotification) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Result(org.eclipse.hono.service.management.Result) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) NoopSpan(io.opentracing.noop.NoopSpan) Id(org.eclipse.hono.service.management.Id) Mockito.mock(org.mockito.Mockito.mock) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Test(org.junit.jupiter.api.Test)

Example 5 with Result

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();
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Tenant(org.eclipse.hono.service.management.tenant.Tenant) ArgumentCaptor(org.mockito.ArgumentCaptor) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TenantChangeNotification(org.eclipse.hono.notification.deviceregistry.TenantChangeNotification) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Result(org.eclipse.hono.service.management.Result) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) NoopSpan(io.opentracing.noop.NoopSpan) Id(org.eclipse.hono.service.management.Id) Mockito.mock(org.mockito.Mockito.mock) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Test(org.junit.jupiter.api.Test)

Aggregations

Future (io.vertx.core.Future)18 HttpURLConnection (java.net.HttpURLConnection)18 Optional (java.util.Optional)18 OperationResult (org.eclipse.hono.service.management.OperationResult)18 Result (org.eclipse.hono.service.management.Result)18 Vertx (io.vertx.core.Vertx)17 Id (org.eclipse.hono.service.management.Id)17 Span (io.opentracing.Span)15 NotificationEventBusSupport (org.eclipse.hono.notification.NotificationEventBusSupport)14 LifecycleChange (org.eclipse.hono.notification.deviceregistry.LifecycleChange)14 Truth.assertThat (com.google.common.truth.Truth.assertThat)11 VertxExtension (io.vertx.junit5.VertxExtension)11 VertxTestContext (io.vertx.junit5.VertxTestContext)11 List (java.util.List)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Test (org.junit.jupiter.api.Test)11 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)11 ArgumentCaptor (org.mockito.ArgumentCaptor)11 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)11 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)11