Search in sources :

Example 1 with DeviceManagementService

use of org.eclipse.hono.service.management.device.DeviceManagementService in project hono by eclipse.

the class EdgeDeviceAutoProvisionerTest method verifySuccessfulAutoProvisioning.

@SuppressWarnings("unchecked")
private void verifySuccessfulAutoProvisioning() {
    final ArgumentCaptor<Device> registeredDeviceArgumentCaptor = ArgumentCaptor.forClass(Device.class);
    verify(deviceManagementService).createDevice(eq(Constants.DEFAULT_TENANT), eq(Optional.of(DEVICE_ID)), registeredDeviceArgumentCaptor.capture(), any());
    final Device registeredDevice = registeredDeviceArgumentCaptor.getValue();
    assertThat(registeredDevice).isEqualTo(NEW_EDGE_DEVICE);
    final ArgumentCaptor<Map<String, Object>> messageArgumentCaptor = ArgumentCaptor.forClass(Map.class);
    verify(sender).sendEvent(argThat(tenant -> tenant.getTenantId().equals(Constants.DEFAULT_TENANT)), argThat(assertion -> assertion.getDeviceId().equals(DEVICE_ID)), eq(EventConstants.CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION), any(), messageArgumentCaptor.capture(), any());
    verify(deviceManagementService).updateDevice(eq(Constants.DEFAULT_TENANT), eq(DEVICE_ID), argThat(device -> device.getStatus().isAutoProvisioningNotificationSent()), any(Optional.class), any(Span.class));
    final Map<String, Object> applicationProperties = messageArgumentCaptor.getValue();
    verifyApplicationProperties(GATEWAY_ID, DEVICE_ID, applicationProperties);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) HashSet(java.util.HashSet) DeviceManagementService(org.eclipse.hono.service.management.device.DeviceManagementService) Answer(org.mockito.stubbing.Answer) MessagingType(org.eclipse.hono.util.MessagingType) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) TracingMockSupport(org.eclipse.hono.test.TracingMockSupport) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Device(org.eclipse.hono.service.management.device.Device) EventSender(org.eclipse.hono.client.telemetry.EventSender) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) NoopTracerFactory(io.opentracing.noop.NoopTracerFactory) Vertx(io.vertx.core.Vertx) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) DeviceStatus(org.eclipse.hono.service.management.device.DeviceStatus) MessageHelper(org.eclipse.hono.util.MessageHelper) VertxExtension(io.vertx.junit5.VertxExtension) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) TenantObject(org.eclipse.hono.util.TenantObject) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) List(java.util.List) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) Collections(java.util.Collections) Id(org.eclipse.hono.service.management.Id) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Optional(java.util.Optional) Device(org.eclipse.hono.service.management.device.Device) TenantObject(org.eclipse.hono.util.TenantObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Span(io.opentracing.Span)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Span (io.opentracing.Span)1 NoopTracerFactory (io.opentracing.noop.NoopTracerFactory)1 Future (io.vertx.core.Future)1 Vertx (io.vertx.core.Vertx)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 HttpURLConnection (java.net.HttpURLConnection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 EventSender (org.eclipse.hono.client.telemetry.EventSender)1 MessagingClientProvider (org.eclipse.hono.client.util.MessagingClientProvider)1 Id (org.eclipse.hono.service.management.Id)1 OperationResult (org.eclipse.hono.service.management.OperationResult)1 Device (org.eclipse.hono.service.management.device.Device)1 DeviceManagementService (org.eclipse.hono.service.management.device.DeviceManagementService)1