AbstractVertxBasedCoapAdapter extends AbstractProtocolAdapterBase<T> { @Autowired(required = false) public final void setResources(final Set<Resource> resources) { this.resourcesToAdd.addAll(Objects.requireNonNull(resources)); }  final void setHonoDeviceResolver(final ApplicationLevelInfoSupplier deviceIdentityResolver); final void setPskStore(final AdvancedPskStore pskStore); @Autowired final void setMetrics(final CoapAdapterMetrics metrics); @Autowired(required = false) final void setResources(final Set<Resource> resources); @Override final int getPortDefaultValue(); @Override final int getInsecurePortDefaultValue(); @Autowired(required = false) final void setCoapServer(final CoapServer server); @Override final void doStart(final Promise<Void> startPromise); @Override final void doStop(final Promise<Void> stopPromise); final Future<ResponseCode> uploadTelemetryMessage(
            final CoapContext context); final Future<ResponseCode> uploadEventMessage(
            final CoapContext context); final Future<ResponseCode> uploadCommandResponseMessage(final CoapContext context);  }
@Test public void testStartRegistersResources(final VertxTestContext ctx) { final CoapServer server = getCoapServer(false); final Resource resource = mock(Resource.class); final AbstractVertxBasedCoapAdapter<CoapAdapterProperties> adapter = getAdapter(server, true, s -> {}); adapter.setResources(Collections.singleton(resource)); final Promise<Void> startupTracker = Promise.promise(); startupTracker.future().onComplete(ctx.succeeding(s -> { final ArgumentCaptor<VertxCoapResource> resourceCaptor = ArgumentCaptor.forClass(VertxCoapResource.class); ctx.verify(() -> { verify(server).add(resourceCaptor.capture()); assertThat(resourceCaptor.getValue().getWrappedResource()).isEqualTo(resource); }); ctx.completeNow(); })); adapter.start(startupTracker); }
@Test public void testResourcesAreRunOnVertxContext(final VertxTestContext ctx) { final Context context = vertx.getOrCreateContext(); final CoapServer server = getCoapServer(false); final Promise<Void> resourceInvocation = Promise.promise(); final Resource resource = new CoapResource("test") { @Override public void handleGET(final CoapExchange exchange) { ctx.verify(() -> assertThat(Vertx.currentContext()).isEqualTo(context)); resourceInvocation.complete(); } }; final AbstractVertxBasedCoapAdapter<CoapAdapterProperties> adapter = getAdapter(server, true, s -> {}); adapter.setResources(Collections.singleton(resource)); final Promise<Void> startupTracker = Promise.promise(); adapter.init(vertx, context); adapter.start(startupTracker); startupTracker.future() .compose(ok -> { final Request request = new Request(Code.GET); final Exchange getExchange = new Exchange(request, Origin.REMOTE, mock(Executor.class)); final ArgumentCaptor<VertxCoapResource> resourceCaptor = ArgumentCaptor.forClass(VertxCoapResource.class); verify(server).add(resourceCaptor.capture()); resourceCaptor.getValue().handleRequest(getExchange); return resourceInvocation.future(); }) .onComplete(ctx.completing()); }