RequestResponseApiConstants { public static final Message getAmqpReply(final String endpoint, final EventBusMessage response) { Objects.requireNonNull(endpoint); Objects.requireNonNull(response); final Object correlationId = response.getCorrelationId(); if (correlationId == null) { throw new IllegalArgumentException("response must contain correlation ID"); } final String tenantId = response.getTenant(); final String deviceId = response.getDeviceId(); final Integer status = response.getStatus(); final String cacheDirective = response.getCacheDirective(); final JsonObject payload = response.getJsonPayload(); final ResourceIdentifier address = ResourceIdentifier.from(endpoint, tenantId, deviceId); final Message message = ProtonHelper.message(); message.setMessageId(UUID.randomUUID().toString()); message.setCorrelationId(correlationId); message.setAddress(address.toString()); final Map<String, Object> map = new HashMap<>(); map.put(MessageHelper.APP_PROPERTY_STATUS, status); if (tenantId != null) { map.put(MessageHelper.APP_PROPERTY_TENANT_ID, tenantId); } if (deviceId != null) { map.put(MessageHelper.APP_PROPERTY_DEVICE_ID, deviceId); } if (cacheDirective != null) { map.put(MessageHelper.APP_PROPERTY_CACHE_CONTROL, cacheDirective); } message.setApplicationProperties(new ApplicationProperties(map)); MessageHelper.setJsonPayload(message, payload); return message; } protected  RequestResponseApiConstants(); static final Message getAmqpReply(final String endpoint, final EventBusMessage response); static final Message getAmqpReply(final String endpoint, final String tenantId, final Message request, final RequestResponseResult<JsonObject> result); static final Message getErrorMessage(
            final int status,
            final String errorDescription,
            final Message requestMessage); static final String CONTENT_TYPE_APPLICATION_JSON; static final String FIELD_PAYLOAD_DEFAULTS; static final String FIELD_PAYLOAD_DEVICE_ID; static final String FIELD_PAYLOAD_SUBJECT_DN; static final String FIELD_PAYLOAD_TENANT_ID; static final String FIELD_ENABLED; static final String FIELD_ERROR; static final String FIELD_PAYLOAD; static final String FIELD_OBJECT_ID; }
@Test public void testGetAmqpReplyAddsCacheDirective() { final CacheDirective directive = CacheDirective.noCacheDirective(); final String correlationId = "message-id"; final EventBusMessage response = EventBusMessage.forStatusCode(200) .setTenant("my-tenant") .setDeviceId("my-device") .setCacheDirective(directive) .setCorrelationId(correlationId); final Message reply = RequestResponseApiConstants.getAmqpReply("endpoint", response); assertThat(MessageHelper.getCacheDirective(reply)).isEqualTo(directive.toString()); }