/** * Gets the registration assertion conveyed in an AMQP 1.0 message. * <p> * The assertion is expected to be contained in the messages's <em>application-properties</em> under key * {@link #APP_PROPERTY_REGISTRATION_ASSERTION}. * * @param msg The message. * @return The assertion or {@code null} if the message does not contain an assertion (at the expected location). */ public static String getRegistrationAssertion(final Message msg) { return getRegistrationAssertion(msg, false); }
/** * Gets the registration assertion conveyed in an AMQP 1.0 message. * <p> * The assertion is expected to be contained in the messages's <em>application-properties</em> under key * {@link #APP_PROPERTY_REGISTRATION_ASSERTION}. * * @param msg The message. * @return The assertion or {@code null} if the message does not contain an assertion (at the expected location). */ public static String getRegistrationAssertion(final Message msg) { return getRegistrationAssertion(msg, false); }
/** * Gets and removes the registration assertion conveyed in an AMQP 1.0 message. * <p> * The assertion is expected to be contained in the messages's <em>application-properties</em> under key * {@link #APP_PROPERTY_REGISTRATION_ASSERTION}. * * @param msg The message. * @return The assertion or {@code null} if the message does not contain an assertion (at the expected location). */ public static String getAndRemoveRegistrationAssertion(final Message msg) { return getRegistrationAssertion(msg, true); }
/** * Gets and removes the registration assertion conveyed in an AMQP 1.0 message. * <p> * The assertion is expected to be contained in the messages's <em>application-properties</em> under key * {@link #APP_PROPERTY_REGISTRATION_ASSERTION}. * * @param msg The message. * @return The assertion or {@code null} if the message does not contain an assertion (at the expected location). */ public static String getAndRemoveRegistrationAssertion(final Message msg) { return getRegistrationAssertion(msg, true); }
/** * Verifies that the fall back content type is set on a downstream message * if no default has been configured for the device. */ @Test public void testAddPropertiesAddsFallbackContentType() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is(AbstractProtocolAdapterBase.CONTENT_TYPE_OCTET_STREAM)); }
/** * Verifies that the registration assertion is set on a downstream message. */ @Test public void testAddPropertiesAddsRegistrationAssertion() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); }
/** * Verifies that the registered default content type is set on a downstream message. */ @Test public void testAddPropertiesAddsDefaultContentType() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/hono")); }
/** * Verifies that the registered default content type is not set on a downstream message * that already contains a content type. */ @Test public void testAddPropertiesDoesNotAddDefaultContentType() { final Message message = ProtonHelper.message(); message.setContentType("application/existing"); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/existing")); }
/** * Verifies that the registration assertion is not set on a downstream message * if the downstream peer does not require it. */ @Test public void testAddPropertiesOmitsRegistrationAssertion() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token"), false); assertNull(MessageHelper.getRegistrationAssertion(message)); }