/** * Adds message properties based on a device's registration information. * <p> * This methods simply invokes {@link #addProperties(Message, JsonObject, boolean)} with * with {@code true} as the value for the regAssertionRequired parameter. * * @param message The message to set the properties on. * @param registrationInfo The values to set. * @throws NullPointerException if any of the parameters is {@code null}. */ protected final void addProperties( final Message message, final JsonObject registrationInfo) { addProperties(message, registrationInfo, true); }
/** * Adds message properties based on a device's registration information. * <p> * This methods simply invokes {@link #addProperties(Message, JsonObject, boolean)} with * with {@code true} as the value for the regAssertionRequired parameter. * * @param message The message to set the properties on. * @param registrationInfo The values to set. * @throws NullPointerException if any of the parameters is {@code null}. */ protected final void addProperties( final Message message, final JsonObject registrationInfo) { addProperties(message, registrationInfo, true); }
/** * 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 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 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)); }
/** * Verifies that the adapter's name is set on a downstream message. */ @Test public void testAddPropertiesAddsAdapterName() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat( MessageHelper.getApplicationProperty( message.getApplicationProperties(), MessageHelper.APP_PROPERTY_ORIG_ADAPTER, String.class), is(ADAPTER_NAME)); }
addProperties(msg, registrationInfo, regAssertionRequired); return msg;
addProperties(msg, registrationInfo, regAssertionRequired); return msg;