LoraProtocolAdapter extends AbstractVertxBasedHttpProtocolAdapter<LoraProtocolAdapterProperties> { @Override protected void customizeDownstreamMessage(final Message downstreamMessage, final HttpContext ctx) { MessageHelper.addProperty(downstreamMessage, LoraConstants.APP_PROPERTY_ORIG_LORA_PROVIDER, ctx.get(LoraConstants.APP_PROPERTY_ORIG_LORA_PROVIDER)); Optional.ofNullable(ctx.get(LoraConstants.APP_PROPERTY_META_DATA)) .map(LoraMetaData.class::cast) .ifPresent(metaData -> { Optional.ofNullable(metaData.getFunctionPort()) .ifPresent(port -> MessageHelper.addProperty(downstreamMessage, LoraConstants.APP_PROPERTY_FUNCTION_PORT, port)); final String json = Json.encode(metaData); MessageHelper.addProperty(downstreamMessage, LoraConstants.APP_PROPERTY_META_DATA, json); }); Optional.ofNullable(ctx.get(LoraConstants.APP_PROPERTY_ADDITIONAL_DATA)) .map(JsonObject.class::cast) .ifPresent(data -> MessageHelper.addProperty(downstreamMessage, LoraConstants.APP_PROPERTY_ADDITIONAL_DATA, data.encode())); }  @Autowired(required = false) void setLoraProviders(final List<LoraProvider> providers); void setUsernamePasswordAuthProvider(final DeviceCredentialsAuthProvider<UsernamePasswordCredentials> provider); void setClientCertAuthProvider(final DeviceCredentialsAuthProvider<SubjectDnCredentials> provider);  }
@Test public void customizeDownstreamMessageAddsProviderNameToMessage() { final HttpContext httpContext = newHttpContext(); final Message messageMock = mock(Message.class); adapter.customizeDownstreamMessage(messageMock, httpContext); verify(messageMock).setApplicationProperties(argThat(properties -> TEST_PROVIDER .equals(properties.getValue().get(LoraConstants.APP_PROPERTY_ORIG_LORA_PROVIDER)))); }