CacheBasedDeviceConnectionService extends AbstractVerticle implements DeviceConnectionService, HealthCheckProvider { @Override public Future<DeviceConnectionResult> setCommandHandlingAdapterInstance(final String tenantId, final String deviceId, final String adapterInstanceId, final Duration lifespan, final Span span) { return cache.setCommandHandlingAdapterInstance(tenantId, deviceId, adapterInstanceId, lifespan, span) .map(v -> DeviceConnectionResult.from(HttpURLConnection.HTTP_NO_CONTENT)) .otherwise(t -> DeviceConnectionResult.from(ServiceInvocationException.extractStatusCode(t))); } CacheBasedDeviceConnectionService(final DeviceConnectionInfo cache); @Override Future<DeviceConnectionResult> setLastKnownGatewayForDevice(
            final String tenantId,
            final String deviceId,
            final String gatewayId,
            final Span span); @Override Future<DeviceConnectionResult> getLastKnownGatewayForDevice(
            final String tenantId,
            final String deviceId,
            final Span span); @Override Future<DeviceConnectionResult> setCommandHandlingAdapterInstance(final String tenantId,
            final String deviceId, final String adapterInstanceId, final Duration lifespan,
            final Span span); @Override Future<DeviceConnectionResult> removeCommandHandlingAdapterInstance(final String tenantId, final String deviceId,
            final String adapterInstanceId, final Span span); @Override Future<DeviceConnectionResult> getCommandHandlingAdapterInstances(final String tenantId, final String deviceId,
            final List<String> viaGateways, final Span span); @Override void registerReadinessChecks(final HealthCheckHandler readinessHandler); @Override void registerLivenessChecks(final HealthCheckHandler livenessHandler);  }
@Test public void testSetCommandHandlingAdapterInstance(final VertxTestContext ctx) { final String deviceId = "testDevice"; final String adapterInstanceId = "adapterInstanceId"; when(cache.setCommandHandlingAdapterInstance(anyString(), anyString(), anyString(), any(), any(Span.class))) .thenReturn(Future.succeededFuture()); givenAStartedService() .compose(ok -> svc.setCommandHandlingAdapterInstance(Constants.DEFAULT_TENANT, deviceId, adapterInstanceId, null, span)) .onComplete(ctx.succeeding(result -> { ctx.verify(() -> { assertThat(result.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT); verify(cache).setCommandHandlingAdapterInstance(eq(Constants.DEFAULT_TENANT), eq(deviceId), eq(adapterInstanceId), any(), any(Span.class)); }); ctx.completeNow(); })); }